First USB Power Shield Prototype on the Way!

After toying with the relays and Arduino I found that the diodes weren’t necessary – especially since the relay is latching, and current will be flowing both ways, so putting a diode in each direction would just create a short.

As such, I made some modifications to the board and put it into Gerber files using Eagle, uploaded them to BatchPCB, and am now waiting for the first one to arrive so that I can populate and test it. In the meantime, I need to get around to packaging the WootOff software for distribution, and come up with some documentation of this project that’s more readable than this series of blog posts.

Here’s the board schematic of the Prototype board:

USB Power Shield v1.0 - Prototype

USB Power Shield v1.0 - Prototype

Un-Mac the Mac

So I “caved”. I bought a Mac. I’ve used Windows for years, from our first computer running 95, to the screaming gaming desktop I built by hand and continue to upgrade to the latest and greatest. Windows has always treated me well. As long as you’re semi-competent, it’s easy enough to deal with its occasional quirks (User Account Control, anyone?).

So why did I move to the Mac? Bottom line, they have great hardware. Find me a PC with a 2.26GHz, 2GB DDR3, 9400M graphics, and a 7 Hour battery (no joke) for $1099, not to mention the amazing build quality with the unibody Aluminum casing and glass screen/trackpad, and the awesome support Apple offers.

Of course, every Mac comes with OSX. After a couple weeks of using it, I’m split. As we’ll see, I’ve been able to find most of the software I need on Mac. On the other hand, OSX has some quirks that severely bother me.

As far as program compatibility, it’s half and half. Matlab has a Mac version which works great and there is a version of Spice available (called MacSpice), but it lacks a graphical schematic creator (such as Orcad Capture). Also, the Mac version of Excel lacks Basic and therefore the ability to run linear regressions (or just about any other function) on data. And of course, OSX lacks the ability to play any serious game, even though the hardware on the new MacBook is more than capable for most.

On the downside, I’m starting to get severely frustrated with some quirks in OSX. To start with, why in the world can’t I resize a window from any side – OSX only resizes from the bottom right corner, while Windows will do it on any side. It may not seem like a big deal, but on the other hand, it’s so easy to implement. It should only take a few minutes, and yet it’s been overlooked (copy/paste on the iPhone, anyone?).

Along the same lines, why can’t I fullscreen most programs? Firefox in windows can go fullscreen with the push of a button, but on the Mac I’m wasting an inch or two of screen real estate on the OSX menu bar and the Firefox toolbar. Once again, not a huge deal, but it shouldn’t be hard to do – how can you implement huge pieces of architecture (Time Machine?) and yet leave out these simple details? Apple is all about the details in their hardware; I wish this same level of obsession with usability would reach through to permeate their GUI user experience.

So how did I Un-Mac the Mac?

I boot-camped Windows 7 onto it. Installed an aftermarket 128GB solid-state drive and spun up the Release Candidate for Microsoft’s latest OS. Let’s just say I’m cursing at Windows 7 a lot less than I am at OSX.

Bottom line – excellent hardware, but the OSX user experience could be improved.

And where the hell is my dang middle-click gesture? I need to open links in new tabs with one click!

Now with 100% more relays!

The arduino USB Power Shield has moved over to a relay design, to eliminate the voltage drop the transistors would have caused. Ports has dropped to two because a) no one needs to control four 5V devices, and b) the relays are latching and need two pins each.

The board isn’t done – I’ve ordered some of the relays to see exactly how they work with the Arduino and the diodes need to be figured out, but this is a good representation of what the final board should be like.

USB Power Shield with relays

USB Power Shield with relays

Also, there’s now room for a scrathpad that will be filled out with a 5V and GND bus for prototyping fun.

USB Power Shield

I really wanted there to be a complete solution for the Woot-Off lights project that could be almost plug and play for the end user, so today I drew up a schematic and a board for a USB Power Shield for the Arduino. It pops onto the Arduino like any other shield, and by controlling pins 9-12, you can control power to four devices.

There are two USB ports for anything that takes USB power (5V) – of course, these ports are for power only (no data). You can use these to control the Woot-Off lights without cutting and soldering the cord, and something else (USB Fan? Light? Humping Dog?). There are also four pads toward the middle so you can solder in anything else that takes 5V power.

USB Power Shield board

USB Power Shield board

Schematic here.

Since the Arduino can only supply maybe 300mA while on USB power and 600mA from its small 5V regulator (using DC in), I’ve included the stuff necessary to add a 7805 regulator and related components to allow up to 1A (if you use a heatsink). You can always leave these pads empty if you don’t plan on using that much power. The Woot-Off Lights will need at least the 5V regulator on the Arduino. There are also LEDs to show if the regulator and board itself are powered – these can be omitted as well.

The board uses four 2N3906 to control power of up to 200mA at 5V to four devices. By writing the corresponding pin LOW on the Arduino, you turn on the transistor and allow current to flow from 5V to the device (and then, hopefully, out to GND). Very Simple.

If anyone is interested in a group buy of these boards once I finish revisions and testing, let me know in the comments or email me.

Woot-Off Lights – in Python

The Woot-Off Lights project continues to slowly progress. Over the weekend we moved over to Python for the coding, since that’s the language Alex is most familiar with right now (especially in networking).

Serial control of the lights in Python took longer than expected – we could have saved over an hour of troubleshooting had we simply waited two seconds between opening the serial connection and transmitting the first byte (allowing the connection protocols time to complete), but instead we tried half a dozen Python libraries, thinking the problem was somewhere in the code library. Lesson learned – the exact specifics of interaction between software and hardware is not to be ignored.

We then were able to force the Woot Tracker to update it’s cache, pull down the XML file generated by the tracker, parse it for the value we are looking for (wootoff, true or false), and take action based upon it.

Now we’re simply trying to figure out how to package the program into an .exe that can be hidden in the tray, and also figure out how the timing should work – I would prefer that my server didn’t get a ton of update requests at the same time, especially during a Woot-Off. Right now it looks like we’ll run a custom version of the software on our machine to update the tracker, and the software we distribute publicly will simply pull down the XML (without first updating the cache, because our software has already done so).

On the hardware side of things, I’ve consolidated the driver circuitry onto a small piece of protoboard that pops into the Arduino like a shield. I’ve also cut up an Altoids tin and housed the assembly inside of it. Don’t forget the isolate the top/bottom of the board with electrical tape or similar so the metal case doesn’t short anything.

Here’s a few pictures of the assembly, with the lights being controlled via the Python application.

Driving Speakers with Arduino

In my quest to try out everything the Arduino can possibly do, I decided to hook up a buzzer and try messing around with generating some tones. Since my little 8ohm buzzer seemed to have gone missing, I substituted one of Sparkfun’s audio jack breakout boards and a cheap pair of earbuds I had lying around. DO NOT use a quality set of earbuds or headphones, or any set that you wouldn’t want damaged – we’ll see why in a minute. Just connect ground to ground and either the left or right channel (or both) to one of the digital pins – I used 13 so the LED would light up with the rhythm of the music. I eventually found a couple more buzzers and hooked them in.

Arduinos with Buzzers

Arduinos with Buzzers


My new Boarduino USB from Adafruit is on the left in a breadboard and the Duemilanove is on the right.

The most basic way to create audio using the Arduino is essentially bit-banging one of the digital pins – write high and low at the frequency you wish to generate. The downside is that this creates a nearly square wave, which sound very harsh and unnatural. Also, the “high” is 5V, which is a very high amplitude to be supplying to headphones. Constant use at this amplitude (volume) will probably damage the drivers in earbuds – use the cheap earbuds that came with your MP3 player. Using a standard 8ohm buzzer is of course the preferred method if you have one lying around. I found a buzz function online to control this – pass it the pin to buzz on, the frequency, and the length, and it does the work for you.

void buzz(int targetPin, long frequency, long length) {
long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i=0; i < numCycles; i++){ // for the calculated length of time...
digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait againf or the calculated delay value
}
}

The downside is that this uses the delay function. That means your controller can't do anything else while waiting for the end of the delay. You would also have to use a delay function between the notes to create spaces. This is sufficient for a small buzzer project, but if you're looking to do more complex things (especially signals other than square wave), try consulting the Arduino Playground.

I was able to find a script for the Mario Bros theme online, and covert it into a series of buzz and delay calls. Not all the notes are correct and some of the spacing is off, but it's good enough to get the idea. The entire Arduino script is available here.

Woot-Off Lights Schematic and Hardware

Here’s some details about the hardware setup for the woot-off lights. It’s exactly as I described in the first post – this just includes the schematic and goes a little more in depth.

Quick and Dirty Schematic for Woot-Off Light Control

Quick and Dirty Schematic for Woot-Off Light Control

Let’s take it from left to right. USB input to the Arduino to send serial data. The current from the USB port is not sufficient to start the motors (they require a bit of boost when turned on and consume less current during normal operation), therefore we use the DC input on the Arduino board to supplement the USB. Feed it somewhere between 7-10V (up to 12V should be fine). The Arduino contains a regulator to lower the Vin down to 5V.

The 5V is then connected to the V+ of the lights (red wire). The GND of the lights is connected to Pin 18 of the ULN2803 IC. The ULN2803 also has it’s own 5V/GND connections (the 5V connection is necessary in this application because of the inductance of the motors). When the ULN2803 receives a HIGH input on Pin 1 (coming from Pin 9 on Arduino), it connects Pin 18 to GND (note that this is the same for all pins on the IC except 9/10 – i.e., Pin 2 controls Pin 17, etc). Thus, the lights are now fully connected to both 5V and GND, the circuit is complete, and we have spinny lights.

Work continues on reading a Woot-Off Tracker from a C++ application – if anyone has tips or ideas, they’d be appreciated.

Serial Control of Woot-Off Lights Working

After a few hours of clumsy and inept coding, I managed to scrape together a basic windows console application to send data over serial. Right now it just asks you which COM port the Arduino is on (usually COM3), and then you hit enter to turn the lights on/off. All that’s actually happening is the program sending the character ‘1′ or ‘0′ down the serial pipe.

On the other end of the pipe, the Arduino is listening to the serial communication. The sketch I have set up simply sets pin 9 to HIGH when it receives a 1, and LOW when it receives a 0. That’s it. Then the hardware is controlled as discussed in the previous post.

Prototype console application for Arduino Serial communication

Prototype console application for Arduino Serial communication

So at this point we have:
a) Hardware control of lights
b) Windows console application for serial communication on/off

Which leaves:
c) Having the application read the tracker for wootoff status
d) Packaging it together in a nice, pretty package

So for those following along with an Arduino, I’m posting the Arduino sketch and the console application below. If you want to use a pin other than pin 9 on the arduino, just modify that part at the top of the sketch. Obviously, you should upload the sketch to the Arduino first, exit the Arduino software (since only one application can access the port at a time), identify which port your Arduino is on, and then run the console application. I AM NOT RESPONSIBLE FOR ANY HORRIBLE THINGS THAT RESULT FROM THE USE OF THIS SOFTWARE, largely because I started college as a CS major and switched to EE a year later because I hate coding. That said, it works fine on my and my roommate’s machines.

Arduino Sketch
Windows Console Application

Make your own (dim) LED

Want to make an LED yourself? All you need is some Silicon Carbide, a sharp piece of metal, and a 12V power supply (and maybe a couple resistors to limit current). You can see the faint glow at the tip of the needle touching the SiC.

Silicon Carbide, a needle, and 12V makes an LED

Silicon Carbide, a needle, and 12V makes an LED

Via HackADay

Intelligent Control of Woot-Off Lights

Occasionally, Woot has extravaganzas where they post item after item in what is known as a woot-off. Little .gif lights spin round and round to alert visitors to this spectacle. Playing on this, Woot occasionally sells physical woot-off lights. They run off of USB power, with a switch in each light/motor piece. Since it’s a standard 5V connection, this opens the doors for all sorts of hackery.

The ultimate goal of this project is to have these lights come on whenever there is a woot-off.

If you aren’t already familiar with the Arduino, become familiar now. I’ll wait.

Ok, so the Arduino is a microcontroller system with a USB-serial input communication, a microprocessor with a bootloader to run “sketches”, and the ability to control over a dozen digital logic pins (including a few with PWM or Analog-In).

The setup will use a PC application for monitoring a “Woot Tracker” (many of these are available online to reduce load on Woot’s own servers). The application will check for the presence of the woot-off lights logo, indicating a woot-off – in the future, the lights will be activated by each changing of an item. The application will then send a byte over serial to indicate the woot-off status to the Arduino. Based on the input from the computer, the Arduino will turn the lights on or off.

Great – so in order to turn on the lights all we have to do is turn on one of the Arduino’s pins (they are 5V at digital high). Unfortunately each pin is only capable of supplying at most 50mA, and these lights run on over 100mA. Luckily, the 5V power regulator on the Arduino is capable of supplying much more current – up to 500mA or so if a good DC power supply is used. So if we hook up the positive lead of these unit to the 5V, we now need to control the ground connection to control the circuit – connect the ground and the lights go on because the circuit completes.

The ULN2803 chip provides this exact function. The chip is connected to 5V and ground. The ground from the device to be controlled is connected to a pin (remember that the positive of the device is already connected to 5V), and the control signal from the Arduino is connected to the corresponding control pin. When the control pin sees 5V (from the Arduino control signal), the ground lead from the device is connected to the ground of the chip, completing the circuit and sending current to the device. In this case, the lights spin up.

Early Woot-Off Light Software/Arduino Control

Early Woot-Off Light Software/Arduino Control

So far I have the hardware running, and have used the Arduino PC software to send input down the serial connection, turning the lights on and off. The next step will be to write an application to send serial information, and then to expand that application to search the textfile of the woot tracker for the lights.gif. The final stage will be to integrate all the hardware into a small package so the device can be used permanently.