Dead-Simple Driver Installation for USBasp and USBtiny on Windows

Today I came across a surprisingly simple approach to installing USBasp and USBtiny drivers for all versions of Windows — XP, 7, 8, 8.1, whether 32-bit or 64-bit, all inclusive! As you may know, installing open-source drivers such as USBasp and USBtiny have been a great pain on some of the recent Windows OS, due to the enforcement of signed drivers. The typical solution involves rebooting Windows into a mode that disables driver signature enforcement. Even after you’ve done it once, if you boot into the normal mode next time, it may fail to recognize the driver again (reporting it’s not digitally signed). A huge source of frustration.

Anyways, while searching for ‘fully signed USBasp driver’, I came across this tool called Zadig, which can be used to install libusb drivers on all versions of Windows, and it’s digitally signed. Since USBasp and USBtiny are both based on libusb, could it be the right solution? To my great surprise it worked really well — I was able to install both drivers on Windows XP, 7 (32-bit and 64-bit), 8, and 8.1 instantly, without messing with driver signature enforcement at all. I was mostly surprised such a great solution wasn’t documented more widely online.

Instructions
  • Go to http://zadig.akeo.ie/ and download the software (note that Windows XP has a separate link).
  • Plug in your USBasp or USBtiny device. In case your microcontroller uses a USBasp or USBtiny bootloader, enter bootloading mode, and let Windows detect the device (it will report driver not found). If a window pops up asking to search for driver, just close it or click on Cancel.
  • At this point, run Zadig, it should detect the USBasp or USBtiny, or any libusb device that you have. Then in the selection box (see below), choose libusb-win32 (v1.2.6.0), and click on Install Driver, and wait for the installation to complete.

zadig_srceenshot
That’s it! Because the drivers are digitally signed, there is no hassle installing it in Windows 7 64-bit and Windows 8.1.

I will be updating the driver installation instructions for OpenSprinkler 2.1 and SquareWear right away, as they both use USBasp bootloader. Users have often complained that it’s frustrating to install USBasp driver for Windows 7 64-bit and Windows 8.1. Those days are now past!

Sneak Peak Preview of SquareWear 2.3

There is an upcoming MakerJam at Mount Holyoke College and I’ve been commissioned to create a new version of SquareWear, numbered 2.3. Following the suggestions I’ve received in the past, I made the first prototype of SquareWear 2.3:

IMG_0416IMG_0418

Below I list the main changes / improvements:

  • Added Hardware USB-serial Chip (CH340G) : this pretty much follows the same recent change on OpenSprinkler 2.2u. CH340G is a very inexpensive, easy-to-use USB-serial converter. It’s a low-cost replacement of the popular FTDI chip. With a hardware USB-serial chip, SquareWear can now use the same optiboot bootloader as standard Arduinos use. Also, cloud-based Arduino platform, like CodeBender would also work well with SquareWear. Even better, CH340G is supported out of box on Windows 7 and 8, so no more messing with installing USBasp driver, ever!
  • Added Breadboard Pins (dual-purpose): people asked about the possibility of adding breadboard pins, so in this version there are 13 pins on the right edge with standard 0.1″ spacing. These pins are also neatly laid out to serve a second purpose: they match some of the common I2C sensors (particularly MPU6050 6-axis accelerometer) and bluetooth transceiver. This way you can easily plug in sensors and bluetooth transceiver as optional add-ons! The picture on the right above shows how the board looks like with an MPU6050 and bluetooth transceiver plugged in. With this setup, you can easily make a project that involves motion sensor, and even transmit the signal wirelessly to a nearby computer!
  • Upgraded the 3.3V LDO to a bigger chip (SOT-89 packaging) that can provide higher current.
  • Added AT24C128 (16KB) EEPROM: this follows SquareWear Mini, where the added EEPROM can be useful for storing logging data and animation frames.
  • Removed Build-in Rechargeable Coin Cell: I was quite reluctant to make this change, because the built-in rechargeable coin has been one of the main selling points of the original SquareWear. But to make space for the added USB-serial chip, and also to add the breadboard pins, the built-in battery has to go. On the plus side, this makes the design focus on using external LiPo battery, which has higher capacity and the charging current is also suitable increased.

I will look forward to the MakerJam to receive some feedback / comments on the new design.

Announcing OpenSprinkler Firmware 2.1.0 (Major Upgrade)

I am excited to announce that OpenSprinkler Firmware 2.1.0 is officially release. This is a major upgrade that includes a number of new features, including:

  • Automatic Weather-based Water Time Adjustment using real-time weather data obtained from Wunderground (thanks to Rich Zimmerman who introduced the method, the adjustment method is named after him).
  • Improved Program Settings including per-station water time, flexible start times, custom name, per-program weather adjustment control, and up to 14 different programs.
  • Automatic Timezone and DST Detection based on your location. No need to select time zone and mess with DST any more — once you set your location, the firmware can automatically determine your time zone and DST.
  • Improved Station Attributes and Scheduler including station ‘disable’ attribute, ‘activate relay’ attribute, test station feature (replacing the previous manual mode), automatic serialization of overlapping schedules, and the ability to manually start a program on the controller using buttons.
  • Numerous UI Improvements (thanks to Samer’s hard work) including unified mobile interface, export / import configurations, improved visualization of logging data, and the number of supported languages has expanded to 17 (thanks to all who contributed)!

This is a pretty major milestone as it not only addresses the previous limitations but also introduced critical new features including weather-based control. Furthermore, consider all these are implemented on a small microcontroller with only 64KB flash memory and 4KB RAM 🙂 These significant changes are worth making a new video for. So here is the video tutorial for firmware 2.1.0 (it’s a bit long, but gives you a comprehensive overview of the main features);
http://youtu.be/iUrnf4nIuY4?list=UUl5dnj8oj_9dg6KIbudYmOw


Documentation

With this firmware I’ve also written a more detailed user manual, and API documentation. These are available on the Support page of our new website www.opensprinkler.com. In addition, there are a total of 4 tutorial videos that walk you through the hardware installation, WiFi connection, firmware features, and upgrading firmware. Be sure to check them out first.


Upgrade to Firmware 2.1.0

All OpenSprinkler 2.x devices (including 2.0, 2.1, and 2.2) are eligible to upgrade to firmware 2.1.0. Please check the ‘Firmware Update’ instructions on the support page to download and run the firmware updater. OpenSprinkler 2.0 and 2.2 are the easiest as drivers are pretty straightforward to install, and there is no bootloading procedure; OpenSprinkler 2.1 is tricky because the driver installation is more involved, and there is a bootloading procedure you need to follow. In any case, the firmware upgrade tutorial video gives you a quick walk-through of all the steps.

To use the weather feature, you need to apply for a Wunderground API key. Again, instructions can be found on the support page.

Firmware 2.1.0 has gone through internal alpha testing and external beta testing, so it should be pretty stable. For issues and suggestions, please use the forum, or the support page to submit support tickets.


Implementation

When I say ‘all these are implemented on a small microcontroller with only 64KB flash memory and 4KB RAM’, it’s not entirely true — the weather feature and timezone / DST detection are actually implemented using Python scripts hosted at www.opensprinkler.com. Why? Because these require fairly heavy processing power that’s simply beyond the capability of a small microcontroller. So they are implemented by using Python scripts that serve as the ‘middle man’ — retrieving data from weather websites, perform the necessary parsing and computation, and produce the final results to send back to OpenSprinkler. This way the heavy computation is done in the cloud, and OpenSprinkler only needs to poll the server once in a while to update the results. If you are interested in customizing the scripts, you can download the Python scripts from OpenSprinkler Github repository, modify them and host them on your own server. But for most people the default provided script should work pretty well.


Upcoming Features

As this firmware has been rolled out, we are getting excited to decide on the new features for the next round. Some planned features include:

  • Additional station attributes including soil type, slope type, serial group.
  • Support to store programs and station settings onto the microSD card (effectively allowing unlimited programs).
  • Adding firmware support to interface with remote power sockets, so you can use OpenSprinkler to control power line devices like heaters, fan, Christmas lights etc.
  • Support to use sunset and sunrise times for program start times (the sunset and sunrise times are already being detected using the timezone / DST script).
  • Support for flow sensor to monitor water consumption.
  • Cloud support: no more messing with port forwarding.

Suggestions and comments are welcome. Please post them below, or on the forum. Thanks!

os21s


Sneakpeak Preview of OpenSprinkler DIY kit v2.2u

We are getting ready to release the next minor revision of OpenSprinkler DIY kit, numbered 2.2u. This revision is largely the same with the current 2.1u, with three main differences:

  1. MCU clock speed is increased to 16MHz (from 12MHz previous), by using a 16MHz crystal.
  2. Built-in USB-Serial chip is added, by using CH340G, which is a common chip in low-cost USB-serial converters.
  3. With the hardware serial chip, the bootloader is also changed to use Arduino Optiboot, at 115200 bps baud rate and a bootloader size of only 512 bytes.

IMG_0249IMG_0248

The first change above is to increase the processing speed and hopefully make the controller faster at handling complex algorithms and transferring data with the Ethernet controller. The second change above is mainly to solve the issue that it has been increasingly painful to install USBasp driver on Windows 8+. To understand the background, all of these have to do with firmware upgrade — how to reflash the microcontroller with new firmwares. Back in OpenSprinkler 2.0, I used to have a separate ATtiny45 chip on board to function as a USBtinyISP programmer, which can reflash the main MCU (ATmega644). This is not an ideal design because it involves an extra chip that we have to program; also USBtinyISP is not particularly fast. So when I designed OpenSprinkler 2.1, I made the conscious decision to get rid of ATtiny45. Instead, I decided to implement a USBasp bootloader for ATmega644, which can present the MCU itself as a USBasp programmer when a button is pressed on start-up. This is quite appealing because no extra chip is required, and the programming speed is considerably faster. The only caveat is that to use USBasp in Windows, you need to install the open-source USBasp driver. This was not the most pleasant thing to do, but wasn’t a big deal as the driver was fairly easy to install.

That is until when Windows 8 came out, with this feature called driver signature enforcement. It basically means the driver needs to be digitally signed with Microsoft, otherwise it won’t allow you to install the driver. Let’s be honest, for open-source developers, who wants to pay the big bucks to get the driver signed? So suddenly this has created an even bigger barrier for average users. The only way around the issue is to boot Windows 8 into a mode that disables driver signature enforcement. This step turns out to be unnecessarily complicated. I’ve often received comments about how it’s painful to install USBasp driver for Windows 8. I recently made a video to demonstrate how to update OpenSprinkler firmware — in this 11-minute video, 6 minutes were spent purely on explaining how to install USBasp driver for Windows 8. That’s an evidence of how unnecessarily complicated it is!

Anyways, I set out to find a better solution, and was glad that I discovered the CH340 chip. It’s basically a USB-serial chip that is often found in low-cost USB-serial cables / converters. It’s really inexpensive (less than 30 cents) and requires very few peripheral elements (just a crystal and filter caps). With this chip, you can now use the standard serial monitor to debug your program, and the bootloader can also now use the standard Arduino bootloader.

ch340g_closeup

What I like the most about this chip though, is that it does not require driver for Windows 7, 8 and above. What? Is that even possible? Yup, I’ve verified it — Windows 7, 8 and 8.1 all recognized it right away. The fact that it doesn’t require driver just makes it a whole lot easier to upgrade firmware. Windows XP and Mac OS still require driver for it, though, but that’s light years better than installing driver for Windows 8.

You may be wondering: wait a minute, what about the FT232 chip, which has been available on the standard Arduino since the beginning? Isn’t what I am trying to do here already done? Sure, CH340 is basically a replacement for FT232 — both are USB-serial converters. But there is an economic reason to go for it: even at volume quantity like 1000, FT232 costs about $3 to $4 per chip. That compared to 30 cents for CH340? You tell me. Another nice thing about CH340 is that it comes with SOIC-16 packaging, which is very easy to solder even by hand. This makes it more appealing than other low-cost alternatives like PL2303 and CP2102.

OK, I’ve done enough advertisement. I am not in any ways associated with the company that makes this chip, I am just excited, and regret that I didn’t know about it earlier 🙂

First Impression on the ESP8266 Serial-to-WiFi Module


Check my new blog post on the ESP8266 Toy


Continuing from my previous blog post about Hi-Link HLK-RM04 module, I have finally received the ESP8266 Serial-to-WiFi module that I’ve been waiting for. As I said previously, with the popularity of IoT devices, there is an increasing demand for low-cost and easy-to-use WiFi modules. ESP8266 is a new player in this field: it’s tiny (25mm x 15mm), with simple pin connections (standard 2×4 pin headers), and best of all, it’s extremely cheap, less than US$3 from Taobao.com!

IMG_3188IMG_3189IMG_3190

What is Serial-to-WiFi? Simply put, it means using serial TX/RX to send and receive Ethernet buffers, and similarly, using serial commands to query and change configurations of the WiFi module. This is quite convenient as it only requires two wires (TX/RX) to communicate between a microcontroller and WiFi, but more importantly, it offloads WiFi-related tasks to the module, allowing the microcontroller code to be very light-weighted.

There are already a lot of excitements and resources you can find online about ESP8266. I’ve included a few links below:

These are great resources to reference if you need help working with ESP8266. Below I document my own experience. I’ve also bought a few extra and put them available on the Rayshobby Shop for anyone who is interested in buying the module and don’t want to wait for the long shipping time from China 🙂


Check my new blog post on the ESP8266 Toy


Pin Connections. ESP8266 is sold in several different versions. The one I received is the version with 2×4 male pin headers, and PCB antenna. In terms of the form factor, it looks a lot like the nRF24L01 2.4G RF transceiver. Here is a diagram of the pins:
ESP8266_pinout
Connect the top two pins (UTXD, GND) and bottom two pins (VCC, URXD) to the RXD, GND, VCC, TXD pins of a microcontroller. Note that VCC must be no more than 3.6V. The middle four pins are should be pulled up to VCC for normal operation. However, if you need to upgrade the firmware of the module, you need to pull the GPIO0 pin to ground — that way upon booting ESP8266 will wait for a new firmware to be uploaded through serial. This is how you can upgrade the firmware in the future.

A few quick notes for connection:

  • The typical operating voltage is 3.3V (acceptable range is 1.7V to 3.6V). As the module can draw up to 200 to 300mA peak power, make sure the power supply can deliver at least 300mA. For example, the 3.3V line from a USB-serial cable would be barely sufficient, in that case it’s better to use a LDO to derive 3.3V from the 5V line.
  • When using the module with a 5V microcontroller, such as a standard Arduino, make sure to use a level shifter on the URXD pin — a simple resistor-zener level shifter is sufficient. Again, this is to prevent over-voltage.

A schematic will make it clear. See below. In my case, I soldered the components and a matching female 2×4 pin header to a perf-board. This way I can easily plug in and unplug ESP8266. Again, if you are using a 3.3V microcontroller, you can do away with the LDO and zener diode.

esp8266_connIMG_3194

Experiments using a USB-Serial Cable. Before connecting to a microcontroller, it’s a good idea to use a USB-Serial cable (such as the inexpensive PL2303 USB-serial converter) to check out the basic functions of the module. Connect the PL2303 cable with ESP8266 according to the schematic above. Then open a serial monitor (such as gtkterms in Linux and putty in Windows) with 11520 baud rate (my ESP8266 seems to be set to 115200 bard rate; earlier versions use 57600). Then you can use a list of AT commands to talk to ESP8266. The AT commands are pretty well documented on this page. Below are some example input (shown in bold font) and output that show how to reset the module, list available WiFi networks, check the WiFi network it’s connected to, list IP address, and firmware version etc.


AT
OK
AT+RST
OK
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset
... ...
chksum 0x46
csum 0x46
ready
AT+CWLAP
+CWLAP:(0,"",0)
+CWLAP:(3,"freefly",-49)
OK
AT+CWJAP?
+CWJAP:"freefly"
OK
AT+CIFSR
192.168.1.130
AT+GMR
00150900
OK

A Simple Demo using Arduino.
Next, I connected ESP8266 to an Arduino. Because Arduino is already using the TX/RX pins for bootloader, make sure to unplug ESP8266 while flashing the Arduino, otherwise you may not be able to upload a sketch successfully. Also, you can’t use TX/RX for printing debugging information, since ESP8266 will be using them to communicate with Arduino. Instead, you can use another pair of pins (e.g. D7 and D8) as software serial pins, and use a PL2303 serial cable to monitor the output. This will help print debugging information.

I’ve also experimented with using software serial to communicate with ESP8266, but that has failed — ESP8266 requires 115200 baud rate, and that’s a little beyond the capability of software serial. So you have to stick with the hardware TX/RX pins.

(Update: the code has been revised on Dec 14, 2014 to improve robustness, particularly for some of the latest ESP8266 firmwares. Right now there is still an issue that if the browser is closed before the transfer is completed, it may leave ESP8266 in the notorious ‘busy s’ mode, the only solution to which is to do a hard reset. If using the module in real products, make sure you have a way to use a microcontroller pin to reset the power of the module, thus providing a way to hard reset the module. It looks like future firmwares may be able to address this in software.)

The demo program first configures ESP8266 to log on to your WiFi network (SSID and password are given as macro defines at the beginning), then it sets ESP8266 as HTTP server with port number 8080, and it listens to incoming request. If you open a browser and type in http://x.x.x.x:8080 where x.x.x.x is the module’s IP address (printed to soft serial pins), you will see the output which is a list of analog pin values, and the page refreshes every 5 seconds. So this is a basic Hello World example that shows how ESP8266 can be configured as an IoT server, responding to incoming requests.

IMG_3193

Challenges. While my initial experiments with ESP8266 have been quite successful, I’ve also encountered minor issues that took me a while to figure out. For example, while the AT commands are well documented, they don’t seem extremely consistent — some commands allow question marks at the end, some don’t. I also see variations of the returned values from running the AT commands: sometimes there is an extra end of line character, sometimes there is none. These basically require a robust software library to handle all possible cases.

Overall I would say ESP8266 is a very promising WiFi module for IoT, particularly open-source IoT gadgets, because of its low cost, compact size, and the community development. It seems the manufacturer has also open source the firmware code, and thus the minor issues can probably be easily fixed through a firmware upgrade.

We have a small number of ESP8266 modules available in stock, and will continue to offer them if there are sufficient interests. Thanks!


Check my new blog post on the ESP8266 Toy