Hardware Reference
In-Depth Information
ory, but are also defined if you hover the mouse above them. Additional commands are found
within the five menus 23 : File, Edit, Sketch, Tools, and Help. Sketch also enables you to import
libraries, which inserts one or more #include statements at the top of the sketch and compiles
the library with your sketch. This is handy but can cause problems if you begin to push the
limits of your Arduino's capabilities. Because libraries are uploaded to the board with your
sketch, they increase the amount of storage space that is used. If this becomes issues for you
and a sketch no longer needs a library, simply delete its #include statements from the top of
your code. Tools also enable you to select the Arduino board you are using.
The Arduino IDE uses the concept of a sketchbook , which is a standard place to store your
sketches. Open your sketches in your sketchbook from the File > Sketchbook menu or from the
Open buton on the toolbar. The irst time you run the Arduino software, it will automatically
create a directory for your sketchbook. You can view or change the location of the sketchbook
location with the Preferences dialog. The software allows you to manage sketches with more
than one file with each file showing up handily in its own tab. These files can be of several
types including your standard Arduino code files (no extension), C files (.c extension), C++
files (.cpp), or header files (.h).
After you have writen your sketch from scratch (or downloaded/altered/customized it) and
you want to test it in the real world, you need to upload it to the Arduino board. To do this,
you need to ensure that you are using the correct board and serial port. You can check this by
going to the Tools > Board and Tools > Serial Port menus, respectively. The correct board is the
one you are using (e.g. an Arduino Uno). The board selection has two effects: it sets the para-
meters (e.g. CPU speed and baud rate) used when compiling and uploading sketches; and sets
and the ile and fuse setings used by the burn bootloader command. For serial ports, it will
depend on your operating system:
On Linux , it should be /dev/tyUSB0, /dev/tyUSB1 or similar (e.g. Or /dev/tyACM for
non-FTDI-USB-to-serial converters).
On Windows , it is probably COM1 or COM2 (for a serial board) or COM4, COM5, COM7,
or higher COM10,20 (for a USB board)—to find out, you look for USB serial device in the
ports section of the Windows Device Manager.
On the Mac , the serial port is probably something like /dev/ty.usbmodem241 (for an Uno
or Mega2560 or Leonardo) or /dev/ty.usbserial-1B1 (for a Duemilanove or earlier USB
board), or /dev/ty.USA19QW1b1P1.1 (for a serial board connected with a Keyspan USB-
to-Serial adapter).
After selecting the correct serial port 24 and board, press the upload buton in the toolbar or
you can select File > Upload in the menu. Current Arduino boards will reset automatically and
begin the upload. With older boards (pre-Diecimila) that lack autoreset, you need to press the
reset buton on the board just before starting the upload. On most boards, the RX and TX LEDs
blink (as seen around the middle of the board to the left of the Arduino logo in Figure 4.1(a) )
as the sketch is uploaded. The Arduino environment will display a message when the upload
is complete.
When you upload a sketch, you are using the Arduino bootloader, a small program that has
been loaded on to the microcontroller on your board. It allows you to upload code without
using any additional hardware. The bootloader is active for a few seconds when the board re-
sets; then it starts whichever sketch was most recently uploaded to the microcontroller. The
bootloader will blink the on-board (pin 13) LED (above the RX and TX LEDs in Figure 4.1(a) )
when it starts (i.e. when the board resets). You can also use the IDE to put a bootloader on a
raw microcontroller.
 
 
Search WWH ::




Custom Search