At our workshop this week, we did some hands-on testing of our control theory knowledge with an aerodynamically-driven balance beam–basically just an electrically controlled fan that blows to lift up a weighted board. The idea was to capture the difficulties of UAV control in a simpler and slightly less dangerous system. Little did we know what we were signing up for! (Arduino code and data after the break.)
We’ve been using Arduinos for all our projects, and it was time I got around to benchmarking the serial communication performance. It’s actually not very fast; even at the maximum baud rate of 115200 bits per second, delivered performance is only a little over 10KB/second each way, and it only hits this bandwidth when sending over 100 bytes at a time.
The problem for small messages seems to be a 4 millisecond minimum roundtrip latency. Messages over about 40 bytes seem to take several such latencies, so there’s a stair step pattern to the latency. Paul Stoffregen says this is due to the Uno firmware’s 4.1 millisecond transmit timeout.
Evidently, the Teensy (with direct USB to the chip, not a USB-to-serial onboard) gets about 1ms serial latency. The same page reported the Duemillanove at 16ms minimum (62Hz!).
Overall, this means you’re only going to get a 250Hz control rate if you’re shipping sensor data from an Arduino Uno up to a PC, and then sending actuator signals back down to the Arduino. But 250Hz is enough for most hardware projects we’ve been thinking about.
The other annoying problem? After opening the serial port, the Arduino Uno takes 1.7 seconds to boot before it responds to serial commands. Anything you send from the PC before that time seems to be lost, not buffered. The fix is probably to have the Uno send the PC one byte at startup, so the PC knows the Uno is ready.
Just uploaded some new video of my color-tracking “smart wheels” robot:
I’ve been playing with microcontrollers for over a decade now, and have hands-on experience with PIC, ARM, 68HC11, and MSP430 devices. Usually, it’s a long slow road where you (1) pick a processor to buy, (2) pick a device programmer, (3) pick a compiler, (4) read the processor documentation, (5) find/fix example code until it compiles, (6) program the chip, (7) figure out why the lights aren’t blinking. It’s usually very painful, takes a few days at the very least, and every new task or chip is just more work.
But this is easy!
- Buy an Arduino Uno R3 for about $30. Lots of places have the hardware, including Amazon (and cable) or SparkFun (and cable). The cable is an ordinary USB A to B cable, with the thick square end like on most USB printers.
- Download and unzip the Arduino 1.0 IDE. (On Linux, you’ll also need to “sudo apt-get install gcc-avr avr-libc” to get the compiler.)
- Open the IDE’s “Drivers” folder. Right click “Arduino UNO R3.inf” and hit “Install”. Plug in the Arduino, and it should show up as a serial port (something like COM3 or /dev/ttyUSB0.)
- The very similar Arduino Duemilanove 2009 board doesn’t need drivers; it shows up as an ordinary FTDI USB to serial device.
- Start up the IDE by double clicking Arduino.exe, and:
- Choose File -> Examples -> Firmata -> StandardFirmata.
- Hit File -> Upload. The TX and RX LEDs will flicker as the device is programmed.
- The Arduino now responds to the serial Firmata command protocol.
- Download the Firmata Test Program, run it, and choose the “Port” from the menu (like COM3 or ttyUSB0.)
- Click pin 13 on and off, and watch the LED blink! You can set any pin to input (reading low or high voltage) or output (producing low or high voltage), and many pins have other functions available like analog input, PWM(pulse width modulation), or servo control. Just click and drag to interact with all the pins!
The beautiful thing about this is you don’t have to figure out how to enable analog inputs, initiate ADC conversions, correctly set the PWM control registers, or set interrupt modes–it’s pure plug and play!