Fake Keyboard used in Andy Gelme’s “wearable computing” talk

Last night Andy Gelme did a cool talk at Linux Users Victoria where he demonstrated a gesture recognition system that uses a Lilypad Arduino sewn onto a shirt and connected to an accelerometer mounted on a sleeve using conductive thread. Our cunning plan had been to use the output from his system to drive inputs on my Fake Keyboard shield to send keypress events to a host when he moved his arms around so he could control Frozen Bubble physically, but there was a misunderstanding about laptops: I didn’t take mine along, and Andy assumed that I’d have mine there with Frozen Bubble installed so we didn’t quite pull it off. It was cool though bringing the two bits of hardware together in the 5 minutes before the talk, plugging them in, and it worked first time! To make things easier for the talk I added some buttons to the Fake Keyboard shield:

arduino-usb-hid-buttons

Pressing any of the buttons causes it to send a keypress event to the host. I also had female headers soldered on so his Arduino could send events to it, but I took them off before that photo. It’s not as cool as using Andy’s gesture recognition system but just for the fun of it I fired up Frozen Bubble and had a game totally controlled from the Arduino:

arduino-usb-hid-fb

It’s on Amazon and we haven’t finished writing it yet

I was just checking out the new Author Blogs feature on Amazon.com when their system came up with a list of suggested books to associate with my profile – including Practical Arduino! Turns out it’s already been issued an ISBN and a book page has been created for it. Wow, scary.

www.amazon.com/dp/1430224770

Despite the fact that it doesn’t exist yet it’s even been assigned a sales ranking and there are several items listed under “customers who bought this item also bought” and says that 23% of people who view the book page ultimately buy it. Umm, huh? Are people pre-ordering it already? Not that I mind, of course! In fact – please go and pre-order a copy right now! No, order 10!

Organising Arduino bits n pieces

Trying to keep track of the parts for 40+ Arduino projects at once has been a bit of an exercise in controlled chaos so a couple of weekends ago I went down to the Reject Shop and bought a stack more cheap kitchen containers with snap-on lids. Now things are much neater. This is one shelf:

project-boxes

Yellow labels for projects for Practical Arduino, white and blue labels for general supplies. I started doing blue labels using a Dymo labeler but it turned out that hand-written labels on electrical tape are easier to read from a distance so I gave up on the high-tech approach.

There are actually about twice that many containers now: that photo is a couple of weeks old and since then I’ve been back to buy even more.

Arduino telemetry payload in a class C rocket

A few weeks ago I headed over to a local trotting track with Thomas to meet up with Marc Alexander, Rohan Fernando, and their kids to do a couple of launches with Marco Ostini’s class-C rocket fitted with an Arduino telemetry payload. Rohan brought a video camera and Marc brought a still camera, and it was a beautiful day so we got some really good coverage.

This was a triple-purpose trip: Arduino development for Practical Arduino, rocketry education for Lunar Numbat, and an excuse to have some fun.

Because class-C rockets are so small and light they can’t lift much of a payload and I had to keep the mass of the electronics as small as possible. You can get a sense of scale from this photo which shows a small white bundle in the bottom of the nosecone. Inside that bundle is an Arduino Pro Mini 5V/16Mhz, a 433Mhz transmitter module, and a Lilypad 3-axis accelerometer:

arduino-payload

The Arduino runs some code that reads the accelerometer values, pokes them out the transmitter using Mike McCauley’s VirtualWire library and waits for the message to go out, then loops back to the start. The result is a stream of values that is pretty much rate-limited by the 2Kbps transmission rate. On the ground I had my laptop connected to an Arduino Duemilanove with a 433MHz receiver module:

rocket-receiver

Running on the laptop was a little piece of code that read values coming from the USB port and displayed them on screen while also writing them to a logfile. This shot shows the values scrolling on the screen while I’m holding the rocket and giving it a bit of a shake:

rocket-telemetry

The launches worked really well, but in the end I don’t think the accelerometer data is going to mean anything much at all. I learned a very important lesson: always, always, always put an absolute timestamp in with the data, even if there’s a relative one in there! The values came out looking like this:

562047|326|328|395
562204|322|330|393
562361|327|327|397
562516|317|335|604
562673|325|331|590
562830|328|330|514
562985|328|331|506
563142|328|331|500
563298|328|329|501

where the columns are:

  1. Time in milliseconds since the Arduino booted
  2. X force
  3. Y force
  4. Z force

That data segment is from around the time of the second launch with the Z value stable at around 394 while the rocket was stationary then jumping to 604 and falling to 500 over the next 800ms. Which brings me to the second lesson learned: comms failed right at that point, less than 1 second after launch. So the el cheapo 433MHz modules from Jaycar just didn’t manage to do the job. I have a pair of 60mW XBee modules from SparkFun that are a lot bigger than the 433MHz modules but should be good for 1Km+ range, so for next time the 433 modules are out and XBee is in. One of the launches captured at just the right moment by Marc, with Thomas holding the launch controller and my arm around him:

rocket-launch

The extra mass in the nosecone didn’t seem to hinder the launches at all, but because I used C6-7 motors with a 2 second separation delay there was a heart-stopping moment when it reached apogee, turned over, and started coming straight down *really* fast before the charge fired and the chute deployed. On the second launch I thought the separation had failed because it descended a very long way before it fired, so the final lesson for the day was to use motors with a smaller separation delay when working with a larger payload mass.

Fun times!

(Photos in this post copyright 2009 Marc Alexander, all rights reserved, used with permission)

Tank level sensor hardware almost done

The project I’m writing up at the moment is a tank level sensor that uses a differential pressure transducer to measure the difference in pressure between the atmosphere and the water at the bottom of the tank, which in turn allows the Arduino to figure out how full the tank is since pressure increases with depth. I built a prototype using part of a circuit board that already had an op-amp comparator / amplifier on it and it worked nicely so I’ve just finished doing a version on a prototyping shield:

tank-level-protoshield-small

That picture show it complete except for two things: the 4-way connector for the lead to the pressure sensor, and a jumper that selects which analogue input the shield will use. Coming along nicely!

Progress on Arduino-as-USB-keyboard project

Thanks to the assistance of Philip Lindsay who created the UsbKeyboard library for Arduino I got a USB shield working tonight that allows an Arduino to pretend to be a HID (Human Interface Device) such as a keyboard or mouse:

arduino-usb-hid

This opens up a bunch of very intriguing possibilities, such as having an Arduino provide keyboard input to desktop applications including games. Andy Gelme is doing a talk at Linux Users Victoria next week about taking over the world with Arduino and wearable computing, and we’re hatching a plot to use our bodies as physical input devices to control a game through the USB shield above. Should be fun!

Arduino code highlighting in Vim

A big thankyou to Johannes Hoff for putting together a Vim syntax highlighting file for Arduino development. Most people start their Arduino journey using the IDE but many then move on to using other tools, and for me personally my editor of choice has been Vim for so long I can’t remember when I started with it. The Arduino language is really just C++ with some extra libraries thrown on top but because sketch files are stored with a .pde extension Vim doesn’t even apply regular C++ highlighting by default, let alone highlight Arduino-specific functions. So Johannes put together an “arduino.vim” syntax file that you can grab from www.vim.org/scripts/script.php?script_id=2654.

To get it running on my Ubuntu system these are the steps I followed:

  1. Create the directory to store syntax files if it doesn’t already exist: mkdir -p ~/.vim/syntax
  2. Put the file you just downloaded into it: mv arduino.vim ~/.vim/syntax/
  3. Bind that syntax definition to files with the .pde extension by adding the following line to your ~/.vimrc file: au BufNewFile,BufRead *.pde setf arduino
  4. Open a .pde file in Vim and type: :syntax on

Voila! Syntax highlighty goodness for .pde files:

arduino-vim-highlighting

If you want Vim to always have syntax highlighting automatically each time you open a file, just add this to your ~/.vimrc file:

syntax on

Enjoy!

Updated library for nuelectronics / Seeed Studio ethernet shield

seeed-ethernetThe Seeed Studios Ethernet shield is a beautifully made board: the gloss white overlay gives easily the best finish I’ve ever seen on a PCB, and they were smart enough to realise that when people put an Ethernet shield on a project they probably also want to add some custom hardware as well so the spare board area is a mini prototyping area. Sweet! The downside of the board is that it uses the nuelectronics etherShield library which has a tiny but fatal bug that prevents it working on operating systems with case-sensitive filesystems, such as Linux: the wrapper class has incorrect capitalisation on the filename for the library header. The syntax itself is also all over the place with semi-random indentation in the examples that makes them really hard to follow, and there’s close to zero documentation for it. So to save other people the pain I’ve created an updated version of the library and put it on github so it can be updated: github.com/jonoxer/etherShield/tree/master Enjoy!

Problem: Arduino won’t run with USB disconnected

I’ve seen a few people mention problems with getting their Arduino board to execute code when running stand-alone disconnected from USB, and it’s a problem that had me scratching my head when I first came across it too. The symptom is that you’ve written some code, uploaded it to the Arduino, tested it, and everything seems to work fine – until you disconnect the USB and try to run the Arduino off a battery, and it just won’t go. Plug it back in to USB and everything is fine. Grrrrr!

The basic problem is the Arduino seeing a floating input to the RX line on the serial port. While booting up the Arduino bootloader searches for an update from a host computer, and if it finds one it loads it up and runs it. But with the RX line floating it sees garbage data and sits there indefinitely waiting for an update that will never come.

The solution is easy when you know how. Just stick a 10k resistor across the RX and TX connections (ie: digital pins 0 and 1) or from RX to GND when you’re not using the USB connection and the Arduino will boot cleanly and execute your code as expected.