Page 300 - Hacking Roomba
P. 300
Chapter 13 — Giving Roomba a New Brain and Senses 281
still letting the developer write standard C. (Most versions of C for microcontrollers for pro-
grammers tend to use very non-standard syntax.)
Every C compiler needs a library of basic functions. AVR-Libc is a mini-version of the
standard C library that every C program is familiar with. This library contains functions like
printf(), toascii(), and malloc(), as well as functions for manipulating AVR-specific
registers.
For more complex I/O, Arduino also includes the Procyon AVRLib written by Pascal Stang.
This library contains some helper functions to deal with the AVR chip, but also has functions
to control LCDs, servos, compact flash disks, and even Wi-Fi cards. Using these functions
isn’t as easy as using the basic Arduino functions, but as Arduino grows it may find ways of
encapsulating more of AVRLib.
Getting Started with Arduino
Getting an Arduino board up and running is almost as easy as getting Processing running.
The most up-to-date information is available from the Arduino website, but when you have an
Arduino board and have downloaded the Arduino software, the most common thing to do is:
1. Install the USB-to-serial driver the Arduino readme says is needed.
2. Connect an LED to the digital pin 13 socket and Gnd socket on the Arduino board.
3. Plug in the Arduino board to a USB port. Its green LED power light should go on.
4. Run the Arduino IDE. Select the serial port of the Arduino board. (It will be the serial
port created by the USB-to-serial driver.)
5. Load up or write an LED blink program as shown in Figure 13-16 and compile it by
clicking the Verify/Compile button. It should say Success.
6. Press the reset button on the Arduino board and click the Upload to I/O board button.
While it’s uploading, you can watch the TX/RX LEDs on the Arduino blink. The IDE
will report Done when finished.
In a few seconds the Arduino board will reset to run your program, and your LED will start
blinking. Figure 13-17 shows the result of the preceding steps. (The bright white dot at the
bottom of the board is the power LED. The blinking LED is on the right toward the top,
inserted into the header socket.) You don’t need a resistor like you normally would for the
LED, because the pin 13 socket already has a resistor on the board, just for this kind of test.
The bootloader on the Arduino board is only active for the first three seconds after the board is
reset, so right before uploading your code to the board, press the reset button.
The Arduino board contains a USB-to-serial adapter and so requires a driver to be installed on
your OS before you can use it. You may already have this driver, but if you don’t, the Arduino
folder contains the correct driver for your OS.