OpenSprinkler Beagle First Prototype Done

Update: OpenSprinkler Beagle is officially released, and is available for purchase at Rayshobby Shop.

A lot of prototype PCBs arrived over the weekend. Among them is my long-waited OpenSprinkler Beagle — a sprinkler / irrigation extension board for the BeagleBone Black. Cool, time for some prototyping actions!

IMG_3411IMG_3404

The design of OpenSprinkler Beagle largely follows OpenSprinkler Pi (OSPi). As usual, the board contains a 24VAC to 5VDC switching regulator, shift register, triacs, terminal blocks, and zone expansion board connector. It provides 5V power to the BeagleBone Black, uses 4 GPIO pins (specifically P9_11, 12, 13, 14) to interface with the shift register, and SDA2/SCL2 to interface with the DS1307 RTC. Since the BeagleBone and RPi are similar in size, I can reuse the same enclosure as I’ve been using so far.

There are also several changes and improvements. First and probably the biggest design change is that the BeagleBone Black is now oriented face-down, and it plugs directly to the extra long male pin headers as you can see on the pictures above and below. In contrast, on OSPi, the Raspberry Pi is oriented face-up, and connection from RPi to the board is through a pair of 8-pin and 3-pin cables. The biggest advantage of the face-down design is that it saves the cables, and there is now some extra space in the upper-half of the enclosure, making it possible to add additional modules. To make it easy to reuse the available pins on the BeagleBone, I’ve also mapped out all the 46 pins on ports P8 and P9 to the pinout area.

I actually wanted to use the same design for OSPi, but it’s more tricky because RPi uses male pin headers, which means the extension board will have to provide female pin headers. I haven’t been successful at finding extra long female pin headers, but I will keep looking.

IMG_3412IMG_3405

Among the other changes: the 24VAC port is now using a new type of terminal block that has different pin spacing and color with the others. This will reduce the chance of accidentally plugging 24VAC into the COM or rain sensor port, which has happened before. Speaking of rain sensor port, yes, there is now a rain sensor terminal — it takes one extra GPIO pin, but there are plenty of GPIO pins on the BeagleBone, so who cares 🙂

Also, I’ve added a 2A fuse, and nine 48V bidirectional TVS (transient-voltage suppressor) — one for the power in, and one for each of the eight zones. This will provide some level of protection to the circuit during power surges and lightening. In the past I’ve used MOVs (metal-oxide varistors). Those are pretty cheap, but they are bulky and have to be hand-soldered since they are through-hole components. TVS is a bit more expensive but can be easily automated using pick-and-place machines.

IMG_3410IMG_3407

Also, the analog-digital converter (ADC) has been removed since the BeagleBone has built-in analog pins. As sort of an experiment, I also removed the on-board DS1307 RTC, but instead added pin headers to plug in an external RTC module, as you can see close to the top of the PCB. This was done as an experiment to empty out some space on the PCB to allow future expansion. But it turns out to be not very successful, because the module actually takes quite some space and makes it difficult to close the top cover.

Here are some additional pictures of the assembly:
IMG_3406IMG_3408IMG_3409

I quite like the overall design. There are a few minor changes I want to make before the official release. For example, the 100uF capacitor is currently too close to the BeagleBone’s USB port, and it needs to be moved further away. Also, I can make the PCB color black to match the color of the BeagleBone Black. By the way, I learned from the forum that some users want to use the sprinkler controller to control garage doors. I figured it’s it’s pretty easy to add a relay on the board for general-purpose applications. So I am gonna try to add that too.

Naming

What would be a good abbreviated name for OpenSprinkler Beagle? Since it’s designed for the BeagleBone Black, I could call it OSBBB, but I want to distinguish it from another product I am working on — the OpenSprinkler Bee (OSBee). OSBBB and OSBee are too close with each other to pronounce. One possibility is to call it OS-Bo, which would put it nicely in a series with OS-Pi and OS-Bee. If you have better suggestions, feel free to leave a comment below. Thanks!

Update: OpenSprinkler Beagle is officially released, and is available for purchase at Rayshobby Shop.

HID-class USB Serial Communication for AVRs using V-USB

A month with no new post? That’s unacceptable. Since my last trip to Shenzhen, I actually have quite a few new ideas and projects to post about. The thing is there are so many of them that I don’t know which one to start with! Anyways, I’ve decided to put a stop to this. In this blog post, I will describe some work I did a little while back about implementing HID-class serial communication for AVR microcontrollers using the V-USB library.

Introduction

First, let me explain what I am trying to do. As you probably know, V-USB is a very useful software-only implementation of low-speed USB device for AVR microcontrollers. It adds USB functionality for almost any AVR, particularly for those without hardware USB functionality. With this, it’s possible to make a very low-cost standalone Arduino with USB port and without having to use an FTDI chip. I know there is the Arduino Leonardo, which is based on ATmega32u4, and which has hardware-based USB functionality. But mega32u4 only exists in SMT package, and it’s more expensive than mega328 after all. Besides, I am fully embracing the ‘I do it because I can’ spirit, and this is actually a great motivation for me to learn about V-USB.

What do I need the USB for? Mostly for two reasons. One is to flash a program to the microcontroller, so it needs a USB-based bootloader. For this, there is a very nice open-source project called USnoobie, which can bootload mega328 as a USBasp programmer. This way you can flash a program through the USB port directly, without using a serial cable or an external AVRISP programmer. So this is all good.

The second reason to have USB is for serial communication — the ability to transfer data (e.g. strings) in and out between the device and a host computer through the USB port. This is useful especially for debugging (i.e. printing values to a serial monitor), unfortunately this feature is missing in most V-USB projects. There are some related projects. For example, I came across the AVR-CDC project, which turns a mega328 into a CDC-class USB-serial converter. But there seem to be some limitations of using V-USB to implement CDC (i.e. violates USB standard), and also CDC-class devices require installing a driver on Windows. I would like to make a HID-class USB device which does not require driver installation. So overall I didn’t find any available resource that I can use directly.

Circuit Design and V-USB

Now I’ve explained the motivation, let’s see how to go about implementing it. The first step is to learn to use V-USB. I started with the EasyLogger project downloaded from the V-USB website. It is based on the tiny45 mcu. The program reads a sensor (e.g. temperature or light) and presents itself as a USB keyboard to print out the sensor values to a host computer. This is an excellent starting point for me because USB keyboard is a standard HID-class device, and the project is simple enough that I can easily learn and make modifications.

To adapt it to mega328, I first made a circuit based on USnoobie. Here is the schematic and my build of the circuit on a breadboard:

m328-vusbIMG_3287

It’s a pretty standard V-USB setup. I assigned digital pin PD2 (INT0) to USB D+, pin PD7 to USB D-, and PD4 to a pushbutton. The pushbutton is used to enter bootloading mode. Specifically, if the button is pressed when the circuit is powered up, the bootloader is activated and the mcu will appear as a USBasp programmer. Different from USnoobie, I’ve decoupled this button from the D- line, so that I can use the button for general-purpose input (otherwise pressing the button will trigger the D- line). This requires changing the USnoobie code slightly to use pin PD4 for bootloading condition. Finally, I’ve also added a MCP9700 temperature sensor (you can replace it by any analog sensor such as photosensor) to analog pin ADC0 for testing later.

The next step is to modify the source code. First, change usbconfig.h to match the D+ and D- pin settings, specifically the following three macro defines:

#define USB_CFG_IOPORTNAME      D
/* */
#define USB_CFG_DMINUS_BIT      7
/* */
#define USB_CFG_DPLUS_BIT       2
/* */

Next, modify main.c. This step is pretty technical and tedious. It mainly involves changing register names to match mega328 (since the code was originally written for tiny45). Also, the calibrateOscillator(); function can be removed as the mega328 will be running on an external 12MHz clock.

I also modified the Makefile in order to compile and flash the code for mega328. After a few tweaks here and there, the EasyLogger started working on my mega328! It can successfully output numerical values to a text editor through the USB port. This is very encouraging. If these steps don’t make much sense, you can take a look at the code below, and give it a try yourself.

Learning HID

HID stands for Human Interface Device. It’s a USB class designed primarily for keyboard, mice, joystick, and similar human interface devices. The nice thing about HID is that it’s supported on all operating systems. For example, on Windows, the system uses built-in HID driver to handle USB requests, so no driver installation is required. This is why when you plug in a keyboard or mice, you never have to install a driver (imagine how annoying it would be if you had to!).

To implement HID, you first will need to construct a HID descriptor, which describes the number of reports, and the size, meaning, and (optionally) value range of each report. For example, these reports can be the ASCII code of the pressed key, the x and y offsets, and button presses of the mouse. There are also more general-purpose reports like a buffer of bytes. This is what I will be using to transfer bytes in and out between the device and host. To be honest, the whole USB descriptor thing was very obscure to me in the beginning. I didn’t know if there is one correct way to define it, or it can be flexible. As it turns out, Linux is pretty forgiving about it, but Windows is not. After many trials and errors, I finally settled with this HID descriptor:

PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {    /* USB report descriptor */
    0x06, 0x00, 0xff,              // USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    // USAGE (Vendor Usage 1)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x09, 0x00,                    //   USAGE (Undefined)
    0x82, 0x02, 0x01,              //   INPUT (Data,Var,Abs,Buf)
    0x95, HIDSERIAL_INBUFFER_SIZE, //   REPORT_COUNT (32)
    0x09, 0x00,                    //   USAGE (Undefined)
    0xb2, 0x02, 0x01,              //   FEATURE (Data,Var,Abs,Buf)
    0xc0                           // END_COLLECTION
};

It contains an outgoing buffer of 8 bytes (to transfer data to the host) and an incoming buffer of 32 bytes (to receive data from the host). As I said above, Linux is pretty flexible about the descriptor — you can change it in many ways and it still works. Windows, however, is very strict — if you are not careful, it will simply refuse to recognize the device.

The next step is to write functions to handle the USB requests. For transferring data out, I used the usbSetInterrupt function, which allows sending data spontaneously to the host (i.e. whenever the device has something to report). (I should mention here that I wrote the code as an Arduino library called HIDSerial. So everything gets compiled in the Arduino software. You can certainly use avr-gcc to compile the code as well). I made HIDSerial an inherited class from Arduino’s Print class, so I can make use of the many available print functions (e.g. print a string, an integer, a floating point) in the class for serial printing need, without writing extra code. For transferring data in, I implemented the usbFunctionWrite function, as described in the V-USB Document Wiki.

Now, before I can test and debug the code, I need to have some minimal host software to communicate with the device. That’s what I will be describing next.

Write Host Software using Processing

Going the HID route means the device will not appear as a standard serial COM port, so you can’t use the standard serial monitor to send and receive values. Instead, I will have to write host software myself. I can certainly do this in C or Java. But since I want to make the host software cross-platform, I have chosen to implement it in Processing, which allows me to easily export the program as standalone applications on all platforms. Long story short, to do this, I used HIDAPI library. It has all the goodies to handle communications with HID devices, such as finding a device, opening the device, reading from the device, and sending feature report to the device. Also, using the G4P library, you can easily build a GUI with buttons and text fields, and make the interface just like a standard serial monitor. Once the software is finalized, I can simply click on ‘Export Application’, and select all three platforms, and voilà, the host software is all set! Below are two screenshots of the HID serial monitor:

hidserialmonitor1hidserialmonitor2

Source Code

The source code of this project is available for download on my GitHub repository:

You can either do a git clone, or directly download the project as a zip file (see the Download .zip button on the right-hand side of the page). The folder contains circuit schematic, part list, Arduino library (HIDSerial), host software (HID serial monitor), and bootloader (optional, but recommended as it allows you to re-flash the microcontroller through USB, without any external programmer). The Arduino library consists of several starting examples, which are also demonstrated in the video above. I am sure there are bugs and issues with the code, but please feel free to leave comments and feedback below, in order for me to improve the code.

Limitations and Issues

The biggest limitation of this implementation is the data transfer speed — it’s much slower compared to a standard USB-serial converter. This will be an issue if you need to pump out data as fast as possible. But I figured that for the purpose of debugging, the transfer speed is usually not that critical. The software works pretty reliably in Linux, but I’ve found that on Windows, the host software starts to lose data after running for a while, so not all data get transferred correctly. Resetting the microcontroller and restarting the host software seem to get it back to work. I am still investigating the cause of this issue. It may still have to do with Windows being very strict with USB communication protocols. Perhaps the USB experts can take a look at the code and point me in the right direction.

Adapting the Code to Other AVRs

It’s relatively easy to adapt the code to other AVRs. For example, ATtiny45/85 is a popular V-USB platform, since it’s small, cheap, and has internal oscillator that can run at 16.5MHz, which meets the USB standard (so it saves a crystal and frees up two pins). By changing a couple of pin assignments in the source code, I was able to get the HID serial functions to work on tiny45. I really should do it on tiny85, since tiny45 has only 4KB flash space (even a simple demo would take more than 3.5K flash space). Here is a picture of the tiny45 breadboard build. You can even program tiny45 in the Arduino software by following the descriptions here.

IMG_3322

Thanks for reading the post. Feedback, comments, and questions are welcome.

Visit to Shenzhen, Day 5 — ChaiHuo Maker Space

On the last day (Sep 8) of my trip to Shenzhen, I came across a scheduled event at ChaiHuo Maker Space. ChaiHuo is sponsored by SeeedStudio, and the name means ‘wood fire’. As a Chinese saying says: everybody adds firewood, the flame shoots higher. Chaihuo Maker Space is a place to inspire people to come and add ‘innovative ideas and projects’ to the maker culture. SeeedStudio made a very nice Makers’ Map for Shenzhen visitors, where you can easily locate all the maker-related resources and facilities.

IMG_3254IMG_3252

The topic of the event was about innovative ideas for electronic toys. There were 25 to 30 or so attendees, some traveled as far as from Beijing to come for this event. After a brief introduction, the presenter, who is a designer and has extensive expertise in the electronic toy industry started telling us about the lucrative market for electronic toys, the background, challenges, and four recent successful products. Ample time was given for brainstorming and discussing successful tips. This was overall a relaxed and fun event, and a great social opportunity. Many of the attendees were industrial designers and product developers. It’s a palce to make friends and connections.

Speaking of making friends, if you haven’t heard about this, you really have to check out this software app called WeChat (in Chinese it’s called WeiXin 微信). I only got to know this shortly before I took off for the trip. Basically WeChat is a free mobile text, voice, and multimedia messaging service. You might think it’s not that different from other mobile texting services, but the power of it is in the user interface and experience, and the fact that it’s very easy to share words and images with your friends. It kind of combines multimedia texting and social network, but it’s very lightweight and much easier to use than Facebook. At the ChaiHuo event, I noticed that everyone was adding friends on their phone using WeChat. It’s amazing to learn that WeChat has already achieved more than 300 million Chinese users and 100 million International (i.e. out of China) users. Next time, don’t bother distributing business cards any more — just use your WeChat app to scan others’ WeChat QR code 🙂

IMG_3253IMG_3250

IMG_3249IMG_3251

So this concludes my Shenzhen trip. Following ShenZhen, I stayed at Shanghai for one day and visited the electronics market there. It’s prosperous but nowhere near the size and variety of Hua Qiang Bei at Shenzhen. All right, time to pack and go back to the US. Felt like I’ve refreshed myself and gained new energy and inspiration to keep working and innovating :).

IMG_3270IMG_3269

Visit to Shenzhen, Day 4 — HAXLR8R

Day 4, I paid a special visit to HAXLR8R. HAXLR8R provides seeding fund to entrepreneurs who are passionate about building hardware devices. It offers $25K funding, office space, access to equipment and tools to a team of startups, in order to help them convert great ideas to functioning and marketable final products. They are very conveniently located right next to Hua Qiang Bei electronics market. Since I’ve met the co-founders Cyril and Zach at the Maker Faire previously, I contacted them through email and they were generous enough to spare some time to meet me.

Here are two pictures I took at the lobby:
IMG_3212-1IMG_3210-1

At the moment they are in the middle of a session with 10 teams. This session will conclude in November. Everyone seems to be very busy, working in deadline mode. I had a great conversation with Cyril about the background of HAXLR8R and his own stories living in China. Being located right next to Hua Qiang Bei makes it super convenient to rapidly prototype ideas — the components and parts you need are within walking distances. Not only electronic parts, but plastic parts, mechanical parts, enclosures, common or uncommon, can be easily made here. It’s THE central place where physical goods are made.

Since everyone seems to be fully engaged in making their products, I didn’t want to take too much of Cyril’s time. After showing him my OpenSprinkler and SquareWear, I took off and headed to the next destination, which is to have lunch with Zach (a.k.a Hoeken). Zach is a fun guy and has been living in Shenzhen for more than two years. He is fascinated by the life in China, and his Mandarin is very good 🙂 At the moment he is in the process of moving to a new place. When I met him, he was visibly tired from late night working. We had a wonderful chat about his life in China, his passions, projects he worked on, the MakerBot (he was one of the original co-founders of MakerBot), the open-source culture, technical stuff, and so on. I felt very excited that we were brought together by this ‘Make’ connection — it’s a great way to meet people.

IMG_3208-1

Feel like I am having a hard time keeping my eyes open now. Will go to sleep soon. Tomorrow is Saturday. I will take a day off to go to the beach with my friend. Will blog again on Sunday 🙂

Visit to Shenzhen, Day 3 — back to SeeedStudio

Time flies. Yesterday was day 3 of my visit to Shenzhen. I went back to SeeedStudio and worked with the engineers on improving the design we talked about during day 1. Here I will give you a sneak peak preview of what’s happening.

First, we are going to design a paper box for OpenSprinkler. The design is largely based on SeeedStudio’s classic paper box, with art work and color adapted to OpenSprinkler. The first prototype is shown below. It’s pretty simple but it looks pleasant. I should mention that we are designing the paper box mainly because we would like to make this more towards a commercial product, for example, a product that you may find on Amazon.com. So we need proper packaging to give it the professional look and feel. But don’t worry, it will remain an open-source product — no matter how commercial it may be, the open-source nature won’t be lost.

ospaperbox_protoos21circuit

Next, we are also designing an injection molded enclosure for the OpenSprinkler Zone Expansion Board. As the circuit design of the zone expansion board has more or less finalized, I think it’s time to make a custom enclosure for it as well. I don’t have a copy of the prototype design yet, but one of the main changes is that the new expansion board will fit 16 stations per board, and yet the size is approximately the same as the current expansion board (which fits only 8 stations per board).

If you are wondering what about OpenSprinkler Pi — we won’t be designing an injection molded enclosure for OSPi yet, mainly because I heard from grape vine that there will be another round of revision for Raspberry Pi, and I have been advised not to finalize the design yet. On the flip side, I am working on a BeagleBone Black version of OpenSprinkler (for now, let me refer to it as OpenSprinkler BeagleBone). It occurs to me that BeagleBone Black is probably a more suitable platform for sprinkler applications, particularly because it has built-in ADC and RTC. This would make the extension board design really simple. The circuit should be very straightforward, but I do have to spend some time re-working the enclosure design. Will keep you updated about the progress.

With respect to hardware revision of OpenSprinkler v2.0, there will be a couple of minor changes to address some of the engineering issues. One is a circuit-side protection to prevent the users from damaging the mcu even if they plug in 24VAC into the rain sensor port. This is a rare situation, but because the rain sensor port uses the same type of terminal block as 24VAC, a careless mistake will clearly fry the mcu. The simplest solution we came up with is to add a zener diode and a resistor to the rain sensor port, such that even if you apply 24VAC to the port it won’t damage the mcu’s pin. See the circuit diagram on the right above.

This is fairly standard, so I won’t dwell much on it. But I do want to mention that the resistor RZ should be selected carefully. On the one hand, it should limit the current through zener diode D4 when 24VAC is applied to the terminal. Assuming the zener diode can sustain 10mA, and the maximum instantaneous voltage is 40V DC, RZ should be no smaller than (40-3.3)/0.01 = 3.7Kohm. On the other hand, the rain sensor port has to preserve its normal function, which is to sense the connection / disconnection of the rain sensor. Because we make use of AVR’s internal pullup resistor, which is approximately 20Kohm, in order for the mcu to detect that pin 2 on the terminal is shorted to ground (pin 1), the resistor RZ should be chosen such that 3.3 * RZ / (20K + RZ) < 0.6 where 0.6 is the maximum voltage that appears as a logic LOW to the mcu. So RZ should be smaller than 5.2Kohm. Combining the two factors together, I've chosen RZ to be 4.7Kohm, which falls in the range in between. Another minor change in the plan is to add a few components for AC current sensing, in order to detect the AC current supplied to the solenoids. This is useful for two purposes: one for detecting defective solenoids (i.e. current draw exceeds the typical current draw of a typical solenoid; the other purpose is for monitoring the number of valves that are currently open, which can be done by simply checking the total current draw. In any case, this will be a fairly simple thing to add to the revised circuit. At the end of the day, a friend of mine and I went to a traditional Beijing style hot pot restaurant. Instead of using an electric burner, the traditional style hot pot uses a pot that runs on burning charcoal. It gives the food a nice 'smoked' taste, which is what you won't find in standard hot pot. The food was delicious, and I highly recommend trying it, at least once in your life 🙂 So much for the report today. More to follow tomorrow! IMG_3207-1

Visit to Shenzhen, Day 2 — Hua Qiang Bei

Continuing my last post about this week’s trip to ShenZhen, today’s agenda is to visit Hua Qiang Bei (HQB) — the largest electronics market in the world. HQB is located close to the center of the city. The name literally means the north of the Hua Qiang street. The area spans several big buildings, each of which is full of counters and booths selling all sorts of electronics components and gadgets.

After coming out of the metro HQB station, the first building that came into my eyes is this one:

IMG_3193IMG_3194

The banner says Hua Qiang Electronics World. Sounds like a place I should be, so I headed right in. Turns out this section of the building is mostly selling laptops, mobile phones, and commercial electronics gadgets. A bit disappointing. However, I discovered that the top two floors are dedicated to LEDs, which is one of the things I am looking for. As soon as I went up, I was faced with a sea of LEDs. There are just too many of them: some are for home lighting, illumination, some are for decoration. Many of them are color LEDs, displaying fancy moving patterns. It’s really awesome. Most sellers here are only interested in customers buying in large quantity. So if you tell them you are buying less than a hundred, they tend to lose interest right away and give you the ‘go away’ look. Some sellers do have the patience of talking to you and listening to what you do. I would rather patron these sellers 🙂

IMG_3195IMG_3196

One of the LEDs I was looking for is of type WS2812, which is used by Adafruit on their Neo Pixels. This type of LED has a built-in IC which allows you to set the brightness of each color separately, and most amazingly it takes only one data pin. You can also cascade multiple LEDs. The data is sent in like shift register, and it gets latched on each LED. This is really a very smart design: with only one data pin, you get to control mutiple independent LEDs, and it requires minimum mcu cycle to operate. Many sellers that carry this product sell them in the form of fully assembled tapes of LEDs; a few do sell just the LEDs, at a price of about $110 for a bag of 1000. Sounds like a competitive price. Short of a reference price, I decided to look around and come back to buy when I feel ready.

The next stop is the ‘Q’ section of the building, which is dedicated to all electronics components. When I walked into this section, it feels absolutely like a heaven for electronics lovers. There are endless counters that sell all sorts of components that you can think of.

IMG_3197IMG_3200

When I say ‘endless’, there is no exaggeration: standing at any point of the floor, you simply cannot see the end. It’s very easy to get disoriented. Also, there are multiple floors, each of which has a slightly different focus. The picture above on the right shows a counter that sells switches. Thinking of those times you spent on trying to find a Digikey part that fits your need? Here you can take out a real sample right at the counter and check it out in your hand.

I am curious how to choose which seller to buy from — since there are so many of them, the choice almost feels random. One thing I learned is that you shouldn’t feel rushed to buy: go around and compare different sellers before you make up your mind. Even at this low profit margin, there are still noticeable differences in price. Of course quality is also very important — often you can get a good idea by talking to the seller, and see if they are knowledgeable and professional. I tend to patron sellers who are willing to engage in a conversation and interested in knowing what I do.

It’s very easy to get lost and spend hours and hours here in the market. Moving to a different section in the building, I came across a floor which sells all sorts of cables, connectors, power adapters, terminal blocks etc. If you intend to buy a large enough quantity, you can also ask the seller to customize the product. Most things can be tailored to order. For example, I asked about 24VAC power transformers, and one seller told me depending on my need, they can customize the winding of the transformer and change the plug to any type of my choice. Wow, this is simply awesome 🙂 I was about to head to my next stop, which is the Sai Ge Electronics Market, and I ran out of time. So I will have to come back and visit again.

IMG_3203IMG_3202

At the end of the day, I didn’t buy a whole lot: my goal was to do some initial sight-seeing in order to get an idea of where to focus my attention when I come back a couple of days later. Below is what I bought though: two bags of 1K self-flashing RGB leds, one bag of 1K SMD slide switches, two bags of 200 testing probes, and a few mini relays. With a total spending of less than $100, it’s a real bargain. Can’t complain at all 🙂

IMG_3204W091743357BDA7FCC

After I was done with HQB, my friend brought me to the swimming pool at the ShenZhen Bay Sports Center. This is undoubtedly the largest pool I’ve ever swimmed in, and a good way to end today. So long for today’s report. Will keep blogging tomorrow!

Visit to Shenzhen, Day 1 — SeeedStudio

This week I am on a business trip to Shenzhen — the city with the largest electronics markets in the world. My plan is to visit several studios / factories and the of course the electronic markets here, and also some of my old friends. I will try to document my trip as much as I can.

shenzhen_mapIMG_3176

Shenzhen is located at the very south of China — it’s right above Hong Kong. The weather at this season is usually very hot and humid. Fortunately it has been raining for the past couple of days so it’s not as toasting as it normally is. The image above on the right is the look of the city from my hotel window. There is an electronics market right across the street on the other side 🙂

One of the challenges of traveling in China is that a lot of external websites are blocked by the Chinese government. For example, Facebook, Twitter, Gmail, NYTimes. I was able to use a private VPN to get around with it, but the data transfer speed is really slow. On the plus side, you have access to a wide variety of inexpensive food, which is hugely attractive to a gourmet traveler like me 🙂

On the first day, I visited SeeedStudio, the company that is currently in charge of manufacturing the fully assembled OpenSprinkler 2.0. SeeedStudio is well known in the open-source hardware community, and they have been growing at amazing speed in the past couple of years. I have been looking forward to this visit for a while.

The building where SeeedStudio is located at looks very, short of finding the right word, non-technical, which made me feel that I’ve walked into the wrong place. But as soon as I found their main lobby, I was reassured. On close look, the back wall is made of hundreds of circuit boards painted in white. Very interesting.

IMG_3180IMG_3178

Here is a picture of the ‘innovation corner’ and also the marketing / PR section of the studio.

IMG_3181IMG_3177

The main agenda today was to discuss the design of a paper box and a printed user manual for OpenSprinkler, making a mold for the OpenSprinkler Zone Expansion board, and designing a laser cut enclosure for OpenSprinkler Pi. The meeting was quite productive: I talked with the product manager, an enclosure engineer, and an electronics engineer for several hours. Things got started moving right away. Among the electronics discussions, we covered several potential improvements to the current OpenSprinkler circuit, including preventing users from damaging the circuit by inserting the power to the wrong terminal port, automatic detection of defective solenoids, adding built-in WiFi etc. I felt very excited to start prototyping these ideas right away.

After the meeting, the product manager gave me a short tour of the studio. The top floor is where the offices and meeting rooms are located. The bottom floor is where the production pipeline is.

Here are pictures of the soldering / assembly area, and the SMT pick and place machine.
IMG_3183IMG_3184

Next, the laser cutter and a testing area where engineers were testing a brain wave (EGG) controlled drones. Hmm, very impressive!

IMG_3185IMG_3188

Finally, here are two bins of assembled and tested OpenSprinklers. It really pleases my mind to see these lovely OpenSprinklers 🙂

IMG_3182

So that’s all for my report of Day 1. My next stop is Hua Qiang Bei (华强北), where you can find almost any electronic component you can think of right at the counters. Looking forward to it!

New Rayshobby Shop Homepage Available

This is a quick heads-up that the new Rayshobby Shop Homepage is now available. The new page design is based on OpenCart, a popular free and open-source shopping cart software. It is fairly straightforward to set up, although I did spend quite some time creating nice looking graphics, including banners, product images, and product pages. The end result is satisfying. The shop page now looks much more professional with a load of new features. Take a look at these snapshots first:

rayshobby_newshoppage1

rayshobby_newshoppage

Before I started, I took a look at several options, including WooCommerce for WordPress, OpenCart, ZenCart etc. WooCommerce has the advantage that it integrates seamlessly with your WordPress blog. But it requires a theme that’s compatible with WooCommerce. Since I have an existing WordPress blog, I tried a few themes with WooCommerce support, and they don’t look that great: the images and formatting all become wacky. To fix them will require a lot of changes. So I’ve decided not to go that route. Regarding OpenCart and ZenCart, they both look great, I think OpenCart looks a bit simpler to set up and the design is more minimalist, so that became my pick in the end.

With OpenCart, it’s now a lot easier to add new products and keep them organized. Also, features like showing related products, applying coupons, comparing different products, managing user accounts, providing different payment options are automatically supported. Definitely a big step forward :). I have also added the distributor page to show current official distributors of OpenSprinkler products.

Of course, since this is a new system, I won’t be surprised if I’ve left some glitches. I will keep my fingers crossed and see how things go. If you see any problem or issue, feel free to let me know and I will get them fixed as quickly as I can. Thanks!

RI Mini Maker Faire Pictures

Yesterday we went to the RI Mini Maker Faire in Providence. I came back around midnight last night, feeling quite tired. It was a fun trip, and the first time that I went there as a maker. The faire was co-located with the Foo Fest, so even though its size is nowhere comparable to the Bay Area Maker Faire and New York Maker Faire, there were still a decent number of people. We had a single and fairly small table to showcase everything. As you can see from the pictures below, the table was very crowded, but we managed to lay out everything I wanted to show, and the promotional materials as well 🙂

As in previous Maker Faires, the most fun and rewarding part of the experience is that I get to talk to a lot of different people, explain to them how electronic gadgets work, get them excited about electronics, answer their questions, and hear their innovation ideas and solutions. I had two students, Kim and Cheni, who kindly offered their help, so I got to spend more time talking to people.

IMG_3025IMG_3021

IMG_3020IMG_3019

One tip I learned from the Bay Area Maker Faire earlier this year is that everyone is really excited about blinking LEDs. I know, it sounds trivial, but really, everyone loves it. Last time I just accidentally packed a hundred self-flashing and RGB color LEDs, together with coin batteries in my baggage. While setting up the table, an idea popped up in my mind that we can distribute them as free gifts at the faire. They are really cheap, so I don’t mind giving them away. What I didn’t foresee was how popular this was: the one hundred packets were gone almost in no time.

So this time, I am better prepared: I brought a bag of one thousand self-flashing and RGB color LEDs, together with one thousand batteries! We printed instructions so people can learn how to make an LED throwie on their own (basically sandwiching a coin battery in between the two legs of an LED). We distributed these as free gift to people, but told them it’s only free if they make one themselves (instead of taking away our demos 🙂 ) This was a huge success: I estimated that we gave away at least 250 of these. Many people passing by the table saw this and were eager to give it a try. Kids especially love these. Kim and Cheni were busy cutting tape and helping others learn to build their LED throwies. It’s really rewarding to see something so easy to learn can get people to excited, and it’s also fun to see how people were teaching each other at the table, and bringing their own friends to learn how to build these. Perhaps to some this will motivate them to explore the world of electronics. Then I will feel I have fulfilled my education mission a little bit 🙂

IMG_3034IMG_3035

Announcing AASaver 2.0 (with USB and LiPo charging)

Three months after its first prototype version, I am glad to announce that the long-awaited AASaver 2.0 has finally become available! In case you haven’t seen the first version of AASaver: it is basically a versatile boost converter that takes two AA (or AAA) batteries and bumps them to 5V so you can use it to power flashlight LEDs, or use it for breadboard experiments. The nice thing is that since it’s based on an efficient boost converter chip that has low start-up voltage, it can work with both new and used batteries. Even if the batteries can no longer work in other devices, like remote control, electronic toys, you can still use the AASaver to light up LEDs and run circuit board experiments for a long time. It’s a great way to harvest the remaining energy (or in layman’s term, suck the remaining juice) in your ‘dead’ AA batteries 🙂


The New Design

IMG_3016IMG_3011
IMG_3009IMG_3017
AASaver 2.0 is a completely redesigned circuit from its 1.x version. Here is a list of new changes:

  • Added USB port, which allows charging of USB devices such as mobile phones, MP3 players etc. To support up to 500mA charging current, the booster converter is changed to use NCP1450A, an upgrade from the previous MCP1640.
  • Added lithium battery charger (based on MCP73831), which allows charging of lithium polymer (LiPo) batteries from AA batteries. There is an on-board LiPo battery jack, and an SMT pot (trimmer) to provide adjustable charging current.
  • There is also an input LiPo jack, so the circuit can take source either from AA batteries or external LiPo battery. There is a good reason to provide this functionality, as explained below.
  • The original battery clips are changed to a plastic battery holder, which is mounted with screws on the back of the component side. This frees a lot of room on the component side, which in turn reduces the PCB size.
  • The breadboard pin headers are now changed to the battery holder side. The AASaver now takes much less space when plugged into breadboard. An additional pair of pinouts are also added to fit breadboards with extended width.
  • It’s also possible to use the circuit for solar charging, and charging LiPo battery from external USB port.

In sum, this version preserves the same basic functionality as before, which is to take two AA (or AAA) batteries and serve dual functions as an LED flashlight and breadboard power supply. But it also has a lot of new features and improved usability, most of which were adopted from user suggestions on the original version. Here is a quick summary of the spec:

  • Power Source: two AA/AAA batteries, or external 3.7V LiPo battery (selecctable by an on-board switch). Can also be modified to work with a single battery, or with a solar cell.
  • Power Output: any of the following: flashlight LEDs (seletable by a switch), breadboard pin headers, USB, or LiPo charger. The LiPo charging current is adjustable from 10mA to 200mA through an on-board trimmer.
  • Output Voltage: 5V up to 500mA.

Here is an annotated diagram for the various on-board components:aasaver2_diagram

Schematic and Board Design

Acknowledgement: the USB charging circuit, particularly the D+/D- line voltages, references the design of the MintyBoost by Lady Ada. Check the details about USB charging therein.

Technically AASaver 2.0 is different from the MintyBoost in that 1) it uses a different boost converter chip (NCP1450A vs. LT1302); 2) it has a built-in LiPo charger; 3) it uses SMT components and is mostly assembled. Also, AASaver is designed to be versatile and serve multiple functions, including LED flashlights, breadboard power supply, USB charging, and LiPo charging. Its primary goal is to make use of old batteries (hence the name AASaver 🙂 ).


The Kit

A limited number of the AASaver 2.0 kits are now available on Rayshobby Shop. More will become available in the upcoming weeks. Included in the kit are one assembled and tested AASaver 2.0 circuit board, battery holder, two pin headers, two bright flashlight LEDs, a power switch, two screws and nuts.

IMG_2982IMG_2981


Assembly and Usage Instructions

Although the circuit board is mostly assembled, it does require a few simply assembly and soldering steps to get it fully functional. If you’d rather not assemble and solder anything, you can order a completely assembled AASaver at additional cost. The instructions are posted below with high resolution images. These instructions will soon be posted on the AASaver homepage.

Step 1. Attach the Battery Holder

Use the two screws and nuts to fix the battery holder at the back of the PCB. Make sure that the battery holder wires are close to the side with the AA/LiPo Source Selector (i.e. the opposite side of the USB port).
IMG_2983IMG_2984

Next, cut the battery holder wires to about 1 to 2 inches long (don’t cut it too short, or otherwise you will have difficulty soldering it later). Then use a wire stripper to strip the lead, and then insert the wires to the PCB holes and solder them. Make sure that the red wire goes into the hole marked ‘+’, because this is the positive wire. Double check yours with the image on the right below.
IMG_2985IMG_2986

If you want, you can use a little bit of hot glue to fix the wires in place. This is not required, but is helpful as the wires are very thin and are prone to breaking if you wiggle them too much.

Step 2. (Optional) Solder the Breadboard Pin Headers and LEDs

Now you need to solder the breadboard pin headers and flashlight LEDs. NOTE: these steps are optional, and depends on what you want the AASaver for. If you don’t need it to run breadboard experiments, you don’t need to solder the pin headers (or you can always solder them later).

To solder the pin headers, first insert the two pin headers towards the end of a breadboard. This will help fixing them in place during soldering. Next, align the PCB holes on the AASaver with the pin headers. The height of the pin headers are designed to match the height of the battery holder, so if everything is correct, the battery holder should sit flat on the same surface with the breadboard. Note that this only works if the pin headers are inserted towards the end of a breadboard — if they are inserted in the middle of a breadboard, the battery holders will sit on top of the breadboard and this won’t work.

Also note that on the left side there is an additional pair of VCC-GND pin holes. These are designed for breadboards with extended width. So if your breadboard is wider than the one shown in the picture below, use the extended pair of pin holes.
IMG_2990IMG_2991

Next, to solder the flashlight LEDs, first insert the LEDs to the LED pin holes. These pin holes are located on the same side as the USB port. Make sure the longer lead of the LED goes into the hole marked ‘+’, as the picture below shows. Then gently bend the LED to 90 degrees, and solder the two leads. You can decide how long the LED should stick out of the circuit board, but in general, keep the LED close to the circuit board so that it doesn’t get accidentally bent. Once the LED is soldered in place, remember to cut the excessive leads. Follow the same process to solder the other LED.

IMG_2992IMG_2993

Now the AASaver is completely assembled! Below are the usage instructions.

Step 3. Power it On and Flashlight LEDs

Pop in two AA batteries. Make sure you insert them in the correct orientation. Then turn on the power switch. The red Power Indicator LED should light up. If not, check the Source Selector Switch, and make sure it’s turned to ‘AA’ (instead of LiPo In). The Source Selector allows you to select either AA or LiPo as the power source.

Next, turn Flash LED switch to ‘On’, and the two flashlight LEDs should light up. These are two bright flashlight LEDs, which work really well in the dark.

Note that the battery holder also sort of works for AAA batteries, although the contact is not very reliable. So if you want to pop in AAA batteries, try to use a small piece of aluminum foil to fill the gap between the AAA battery with the battery clips inside the holder. This should make it work perfectly.
IMG_2996IMG_3017

Step 4. Use it as BreadBoard Power Supply

AASaver is also designed to function as a breadboard power supply. It provides regulated 5V, which is great for many circuit board experiments. To use this function, simply plug the AASaver (with pin headers down) into a breadboard. Note that unlike the AASaver 1.x, the body of the AASaver 2.0 will stay out of the breadboard, so this gives you more room on the breadboard.
IMG_3009IMG_3011

Step 5. USB Charging

This is probably the most exciting new feature of the AASaver 2.0: you can now use it to charge USB devices. There is a built-in USB port that fits most standard USB cables. use it to charge your mobile phones, MP3 players, or anything that can charge through the USB port.

IMG_3001IMG_3016

Using a fresh pair of batteries, the circuit can provide up to 500mA charging current @ 5V output, which is sufficient for most USB devices. Also, empirical results show that with a fresh pair of batteries, you can charge the iPhone and the Samsung Galaxy S3 phone up to 20% to 25%. This is not a whole lot, but is good enough as an emergency charger, since AA batteries are really easy to get at convenience stores.

Now, there is a tricky question: since the hallmark of the AASaver is to save old AA batteries, can I use old or even almost ‘dead’ AA batteries for USB charging? The answer is mostly NO. Well, there is no magic: most USB devices require a certain amount of charging current in order to charge properly. Mobile phones are particularly power hungry. To provide 100mA @ 5V output, the AA batteries need to output at least (100mA x 5V) = 0.5 Watt power, and usually more to account for the non-perfect efficiency of the boost converter. Depending on the battery condition, you may or may not be able to draw that much power from a pair of AA batteries — for fresh batteries, no problem; for close to depleted batteries, almost certainly no. Technically, the problem with old batteries is that as soon as you start to draw higher current, the voltage of the battery will drop, and so the boost converter will start sucking more current from it, causing the voltage to drop further. At some point, the boost converter will not be able to maintain a regulated output voltage, hence it will stop charging.

What if you really want to dump the juice from old AA batteries to your phone? There is actually a solution, and you should keep reading below.

Step 6. LiPo Charging

In addition to USB charging, one of the new features of the AASaver 2.0 is LiPo charging. If you have a 3.7V LiPo battery (we carry an inexpensive 700mAH LiPo battery at Rayshobby Shop), you can plug it in to the LiPo Out jack. This allows you to charge the LiPo battery from AA batteries with an adjustable charging current (from 10mA to 200mA). Once the battery is charging, you should see the green Charge Indicator LED light up.

To change the charging current, use a small screw driver to gently rotate the trimmer (SMT POT). The trimmer is very fragile, so be careful when adjusting it. The flat side of the trimmer top is the tail, and the opposite side is the head. The charging current is indicated by where the head is pointing to.

How does the adjustable charging current help? As I described above, the issue with old batteries is that they cannot provide much output current. But they should still work if you ‘dump’ the power slowly. For example, they probably can’t provide 100mA output current at 5V, but they are probably good with 20mA current at 5V. So the trick is to dump the power slowly into a LiPo battery. This is analogous to having a water pipe with very limited capacity: you can’t draw water from it at a high speed, but you can let it drip slowly into a bucket (in this case the ‘bucket’ is the LiPo battery). Then later you can dump the water from the bucket at a much faster rate.

So all in all, if you have an old pair of AA batteries, you can’t charge USB devices directly. But you can still use them to charge a LiPo battery at a slow rate. To do so, adjust the trimmer so that the green indicator LED will remain on. If the LED goes off, it mean either the charge current is too high, or too low. So adjust the trimmer to keep it on. As you will see in the next step, with the LiPo battery, you can then charge USB devices with much ease.

IMG_2999IMG_3002

Step 7. Using LiPo Battery as Power Source

To use a LiPo battery as the power source, simply plug it in to the LiPo In battery jack, then make sure that you turn the Source Selector Switch up to point to LiPo In. This selects the LiPo battery as the power source, and everything else works the same way as before.
IMG_3000


All right, this is the end of the story. I know this post is very long, but most of it will be moved to the AASaver Homepage after I refine the text and hear back comments and suggestions from users. If you are interested, please place an order for the AASaver from the Rayshobby Shop. We have a limited amount right now and more stock will become available in the upcoming weeks.

Questions and comments? Post them below or on the Rayshobby Forum.