(UPDATE: 2 new features, with videos, at the end of the post)
– An Arduino Pro Mini
– A pair of 2mW Xbees with chip antenna
– A FTDI breakout
– … and some other glue accesories.
I had several objetives in mind. The first one was to improve the design so I wouln’t have to depend on the Wiimote (and its external cabling). Second, I didn’t want to depend on Bluetooth, due to its (supposed) limited range. Third, since I’m very new in the microcontroller business, I wanted to learn how to wirelessly connect Arduinos. I also wanted to do something that in the end could be very open and very easy to use with any platform. Finally, I wanted to have fun! Then I considered this idea:
This way you could interface with a wide variety of hardware computers and sofware. Of course, you could link to the computer via a serial link, but I considered the OSC option much more interesting.
1. The Transmitter circuit(s). I had to put together 3 blocks: Arduino Pro Mini+Xbee+Xbee explorer, the nunchuck guts and a power stage. This last block was necessary because the Nunchuck needs to be powered by 3.3 volts, but the Pro Mini I bought supplies 5 volts (it can be fed with 5 to 12 volts). There’s a version of the Pro Mini which works at 3.3 volts, but at the half of the speed (8MHz, in contrast to 16MHz of the 5V version). It might have been a good idea to have used the 3.3V version but I wanted the maximum speed possible. However I have to admit that I’m not sure if that extra power is really necessary for this application… anyway, I used a 3.3V regulator with the corresponding decoupling capacitors, a 10nF on the input and 10uF on output, as suggested in the datasheet:
And this is how it looks:
I cut the Nunchuck cable releasing the 5 smaller cables inside. The green cable is the SDA (data) line, and the yellow one is the SCL (clock). These must be connected to inputs 4 and 5 of the Arduino Pro Mini, because the I2C protocol uses these specific ports (see the Wire library documentation). This is how the Nunchuck should be wired. You can safely ignore and cut the black cable:
The Arduino pro mini can be fed directly from the batery into its RAW port. For easier debugging, I soldered some male headers to the Arduino, and female headers to the Xbee explorer.
This way I could easily connect the Arduino to the FTDI breakout for programming (as shown in previous picture) and to the Xbee explorer for testing the circuit. The pinouts of all the components fit perfectly with this setup.
2. Installing the Transmitter. I had some troubles with the orientation of the Nunchuck I previously used, and I also wanted to increase the visual impact of the design, so I re-created the back cover of my guitar:
I cut it from a transparend DVD box. Then I measured very carefully (ok, not so much) every block I had to put inside, and drilled the necessary holes for the plastic bolts which would hold the circuit boards:
I was worried that the microcontroller could touch a potentiometer inside the guitar and cause a short, so I made a small cover for it out of a plastic folder:
I just connected a 9V battery to the regulator and finally closed the thing. This is how it looks:
Pretty neat, huh? For the curious, it’s a Vampire Red Schecter 006 Deluxe. It’s an expensive, but very good quality guitar, and the only electric I own, so I’ve been very careful with it.
3. The receiver. The receiver is basically a Duemilanova with a Xbee shield on top of an Ethernet shield:
The problem with it is that the Xbee shield uses the ICSP connector for power (and maybe something else), so when I sandwich the Ethernet shield in-between, the Xbee loses those pins. That’s the explanation of those ugly green cables:
At this point, the USB cable is just for powering the Duemilanova, because all data is sent to the computer through the Ethernet port, in OSC form. Now the software part.
4. Program the Xbees. This was the most painful step, not because it’s hard, but because there’s no “definite guide” to do it. There are some things that depend upon the application, and there are some others which I think each person has to learn in the way. The steps for doing this are beyond the scope of this post, however, there are a few good tutorials in the Net. I personally used information from the Ladyada tutorial, (though it’s better if you have the Xbee adapter kit from Adafruit Industries) and specially this “How-to: Setting up XBee ZNet 2.5 (Series 2) modules“, by email@example.com. Also, this document is useful to understand the AT commands that can be used with the Xbee. In any case, it’s a good idea to install the X-CTU utility, and also the latest Xbee firmware. The problem with the X-CTU program is that it only runs on Windows, so take that into account (it can also be run in a virtual Windows installation, using VirtualBox, or other virtualization programs). Some Xbee parameters can be programmed using a terminal program, but some others not. In my case, I programmed the Receiver as a “ZNET 2.5 COORDINATOR AT”, and the Transmitter as a “ZNET 2.5 ROUTER/END DEVICE AT”. I used a baud rate of 57600, used a different Pan ID than the default and labeled the nodes with some string.
5. Code for the Transmitter. Well, I started with the nunchuck guts from my previous design, so I didn’t need to buy a new accelerometer. Also, I wanted to give a try to the I2C protocol which is used in the Wiimote-to-Nunchuck connection and is supported by the Arduino. For that, I checked the nunchuck_funcs.h library written by Tod E. Kurt. I also used his WiiChuck adapter, which can also be found in Sparkfun. That way I could debug the Transmitter code in the Duemilanova before uploading it to the Pro Mini with the Nunchuck soldered to it. Download the code from here. It transmits data from accelerometer, two continuous controllers and two push buttons (which I am not currently using), when it detects a change in the input, polling at intervals of 1 millisecond, and sends the data through the serial link formatted like this:
acc xxx xxx xxx
Where acc is the accelerometer data, cca and ccb the continuous controllers and bta and btb the push buttond.
6. Code for the Receiver. The receiver uses the Ethernet library, the excellent Recotana ArdOSC library and the Messenger library, by Thomas Ouellet Fredericks (for parsing serial input). Download the code from here. You’ll notice that both, the receiver and the transmitter code are pretty simple. The receiver parses the serial input and generates OSC messages according to this address space:
/guit/acc , fff
/guit/cca , f
/guit/ccb , f
/guit/bta , f
/guit/btb , f
I think the addresing could be improved, specially the data types.
That’s all. I’ll post some video soon (I hope) Done! Here you can see how the guitar controlling Pure Data:
I added a ribbon controller to increase the interaction possibilities. It’s a SoftPot connected to the unused potentiometer input of the Nunchuck:
I had unstable readings from the SoftPot, but I’m not sure if it’s due to the SofPot or to the Nunchuck. For now, I’m correcting that behavior within PureData.
I also implemented a very simple auto power-off mechanism. It’s very similar to those found in guitars and basses with active pickups. I simply replaced the original mono jack in the guitar with a stereo one, and wired it like this:
This way, when I connect a standard mono guitar cable, the battery gets connected powering up the internal circuit. Just in case you don’t believe me, you can see it working here:
I hope you enjoyed it.
Thanks for reading!