Arduino Tips, Tricks, and Techniques
Created by Ladyada
2
4
4
5
12
13
15
15
15
15
16
17
18
19
19
19
20
21
23
23
23
24
25
25
25
28
30
30
30
32
Guide Contents
Guide Contents
Arduino UNO FAQ
Arduino Timeline
New USB Chip
More 3.3v power!
UNO R2 and R3
Arduino Libraries
Need Help Installing a Library?
What is a library?
Using Libraries
What's in a library?
It's important to remember!
How to install libraries
Bootloader
Bootloader for the Atmega328
"No-Wait" Bootloader
No-Hang Bootloader
Upload Sketches with AVRDUDE
Upgrade
Introduction
Replace the Chip
Download an Arduino IDE with ATmega328 compatibility
3.3V Conversion
Introduction
Replace the Regulator
Replacing the Fuse
Arduino Hacks
Bumpers
Free up some RAM
ArduinoISP
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 2 of 37
32
32
32
35
36
37
Introduction
Parts
Assemble
Load the Code
Bonus! Using with AVRdude
Support Forums
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 3 of 37
Arduino UNO FAQ
There's so many Arduino's out there, it may get a little confusing. We wanted to clarify for
people some of the changes in the latest version.
NB this is just our opinion and interpretation of some of the decisions made by Arduino. We
aren't associated with Arduino, and don't speak for them! If you have to get an Official
Response to your Arduino question please contact them directly. Thx!
NB2 Still in progress, we're collecting common questions to answer. If you have more
questions, please post them in our forums (http://adafru.it/forums).
Arduino Timeline
But first…some history! First there was the serial Arduino (what's the name of it?) with RS232
which was not used outside of the Arduino team & friends.
The first popularly manufactured Arduino was called the NG (New Generation, like Star Trek,
yknow?) The NG used the Atmega8 chip running at 16 MHz and an FT232 chip for the USB
interface. The bootloader takes up 2KB of space and runs at 19200 baud.
The next version was the Diecimila. The Diecimila updated the chip from the Atmega8 to the
Atmega168. The great thing here is double the space and memory (16K instead of 8K). It still
ran at 16MHz. The Diecimila also added two extra header pins for 3.3V (from the FTDI chip) and
the reset pin which can be handy when a shield is covering up the Reset button. The bootloader
takes up 2KB of space and runs at 19200 baud. Auto-resetting was also added which makes
life awesomer for everyone.
In 2009, the Duemilanove was released. This one also upgraded the chip again, to the
Atmega328. Yet another doubling of space and memory! Another upgrade is now the power is
automagically switched between USB and DC-jack which removed the previous jumper. This
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 4 of 37
automagically switched between USB and DC-jack which removed the previous jumper. This
makes it easier and faster to move from programming to standalone and got rid of some
confusion. The bootloader takes up 2KB of space and runs at 57600 baud.
In 2010, we have the Uno! The Uno still uses the 328P chip and the power switcher. It has a
smaller bootloader called OptiBoot (more space for users' projects) that runs at 115K. So even
though the chip is the same, you get another 1.5K of extra flash space that was previously used
by the bootloader. The FTDI chip has also been replaced with a atmega8u2 which allows for
different kinds of USB interfaces. Finally, there's an extra 3.3V regulator (LP2985) for a better
3.3V supply. whew!
New USB Chip
So! All of the older Arduinos (NG, Diecimila and Duemilanove) have used an FTDI chip (the
FT232RL) to convert the TTL serial from the Arduino chip (Atmel ATmega). This allows for
printable debugging, connecting to software like PureData/Max, Processing, Python, etc. etc. It
also allows updating the firmware via the serial bootloader.
The good news about the FT232RL has royalty-free drivers and pretty much just works. The
bad news is that it can -only- act as a USB/Serial port. It can't act like a keyboard, mouse, disk
drive, MIDI device, etc.
The Uno has changed that by exchanging the FT232RL chip with an atmega8u2 chip. There are a
few things that are possible with this new chip but before we discuss that lets make it clear that
by default, this chip acts identically to the FTDI chip that it replaces. It's just a USB-serial port!
One improvement in updating the chip is that, previously, Mac users needed to install FTDI
drivers. The 8u2 imitates a 'generic' CDC serial device. So now, Mac users do not have to install
a driver. Windows users still need to install the .INF file but luckily there are no drivers. This
means there will be fewer problems with new versions of windows. There is no way to have a
serial USB device that doesn't require an INF file in windows, sadly :(
The big thing that is nice about the 8u2 is that advanced users can turn it into a different kind
of USB device. For example it can act like a keyboard or mouse. Or a disk driver. Or a MIDI
interface, etc. Right now there are no examples of how to do this, but we hope to post some
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 5 of 37
shortly.
And, finally, going with the 8u2 reduced the price of the board which made up for some of the
other extras.
Why not just go with a atmega32u4?
The Arduino team has indicated they thought about this but preferred that hackability of a DIP
chip.
Right now there are a few Arduino's with a 32u4 chip such as the Leonardo, Micro and Esplora
The Arduino team has indicated they thought about this but preferred that hackability of a
DIP chip.
Right now there are a few Arduino's with a 32u4 chip such as the
Leonardo, Micro and Esplora
How can I change the USB firmware?
The 8u2 can be programmed by soldering a 6-pin ISP header (the R3 has the 6-pin header
pre-soldered in) and using a standard AVR programmer. You can also use the bootloader (DFU)
in the 8u2 by soldering the jumper right underneath the board. Again, we don't have any
examples or tutorials but hope to shortly.
The 8u2 can be programmed by soldering a 6-pin ISP header (the R3 has the 6-pin header
pre-soldered in) and using a standard AVR programmer. You can also use the bootloader
(DFU) in the 8u2 by soldering the jumper right underneath the board. Again, we don't have
any examples or tutorials but hope to shortly.
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 6 of 37
The code for the 8u2 is based on LUFA, Dean Cameran's totally awesome USB-AVR library that
has great examples and documentation. Its also completely open source.
Can I get to the other pins on the 8u2?
The FT232RL had an internal oscillator whereas the 8u2 does not. That means there is a
16mhz crystal next to the 8u2 to allow it to keep up with precise USB timing.
On the other hand, the Atmega328p chip that is the core processor in the Arduino now has a
16mhz ceramic resonator. Ceramic resonators are slightly less precise than crystals but we
have been assured that this one was specified and works quite well.
The FT232RL had an internal oscillator whereas the 8u2 does not. That means there
is a 16mhz crystal next to the 8u2 to allow it to keep up with precise USB
timing.
On the other hand, the Atmega328p chip that is the core
processor in the Arduino now has a 16mhz ceramic resonator. Ceramic resonators are
slightly less precise than crystals but we have been assured that this one was specified and
works quite well.
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 7 of 37
So the Arduino is not as precise, timing-wise?
The short answer is: yes. The long answer is that most things that people are doing with
Arduino do not rely on 20ppm precision timing where 100ppm would fail. For people who want
long term precise timekeeping we suggest going with a TCXO (temperature compensation
crystal oscillator) - but you would know if you needed that.
The short answer is: yes. The long answer is that most things that people are doing
with Arduino do not rely on 20ppm precision timing where 100ppm would fail. For people
who want long term precise timekeeping we suggest going with a TCXO (temperature
compensation crystal oscillator) - but you would know if you needed that.
Why not have one 16Mhz crystal shared between both?
Good question, technically you can. However, in practice the board did not make it through
FCC certification with one crystal (long traces with fast squarewaves = lots of noise).
Good question, technically you can. However, in practice the board did not make it
through FCC certification with one crystal (long traces with fast squarewaves = lots of
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 8 of 37
noise).
OK well lets say I don't care about that...
You can absolutely connect the CLKO out the crystal from the '8u2 to the '328p but you're on
your own as we don't think there will be any tutorials about that.
You can absolutely connect the CLKO out the crystal from the '8u2 to the '328p but
you're on your own as we don't think there will be any tutorials about that.
Whats with the FCC logo on the back?
Arduino is now FCC certified! That means that the board by itself passes FCC certification for
electromagnetic emissions. It does not mean that your project is FCC certified. The moment
you change the Arduino, it's no longer FCC certified (although we'd like some back-up
documentation on this).
Arduino is now FCC certified! That means that the board by itself passes FCC certification for
electromagnetic emissions. It does
not mean that your project is FCC
certified. The moment you change the Arduino, it's no longer FCC certified (although we'd
like some back-up documentation on this).
It is also, still, CE certified for Europeans.
A new Bootloader?
There's a new bootloader. It works just like the old one - being an STK500-protocol
compatible but its a quarter of the size! Down from 2K, the new bootloader is a tiny 512b. This
gives you more space for your project code! Yay! It's also faster - 115K instead of 57.6k so
you'll be uploading code in 3 seconds.
The Bad News is that you must make sure to select Uno in the Boards menu!!! If you
don't things will be confusing because the bootloader speed is wrong, and you won't get that
extra 1.5K!
Overall, its a good direction, and the chips can be used in older Arduinos just fine (so you can
upgrade your Diecimila or Duemilanove to the Uno by simply replacing the chip).
For more detailed information about the bootloader, such as source code, please visit the
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 9 of 37
Optiboot (http://adafru.it/aUM) project page.
There's a new bootloader. It works just like the old one - being an STK500-protocol
compatible but its a
quarter of the size! Down from 2K, the new
bootloader is a tiny 512b. This gives you more space for your project code! Yay! It's also
faster - 115K instead of 57.6k so you'll be uploading code in 3
seconds.
The Bad News is that you
must make sure to select
Uno in the Boards menu!!! If you don't things will be confusing because
the bootloader speed is wrong, and you won't get that extra
1.5K!
Overall, its a good direction, and the chips can be used in
older Arduinos just fine (so you can upgrade your Diecimila or Duemilanove to the Uno by
simply replacing the chip).
For more detailed information about the
bootloader, such as source code, please visit the
Optiboot (http://adafru.it/aUM) project page.
Why not just use the '8u2 as a programmer?
While it is possible that the 8u2 could act as a full ISP programmer there are a few reasons
why its good that it isn't.
1. Giving beginners access to a full ISP programmer will result in bricked chips. There's no risk
of messing up the Arduino chip beyond recognition if it's just being bootloaded
2. Having the chip act only as a USB/serial passthrough simplifies the firmware so that the chip
has only one function instead of having to have it do double duty as programmer -and-
serial interface (think about it, its not easy)
3. Backwards compatibility - the Arduino chips can still be programmed with FTDI breakout
boards or cables, making it easy for people to breadboard or make clones.
While it is possible that the 8u2 could act as a full ISP programmer there are a few reasons
why its good that it isn't.
- Giving beginners access to a full ISP programmer will result
in bricked chips. There's no risk of messing up the Arduino chip beyond recognition if it's just
being bootloaded
- Having the chip act only as a USB/serial passthrough simplifies
the firmware so that the chip has only one function instead of having to have it do double
duty as programmer -and- serial interface (think about it, its not easy)
- Backwards
compatibility - the Arduino chips can still be programmed with FTDI breakout boards or
cables, making it easy for people to breadboard or make clones.
How does the new '8u2 affect Arduino-derivatives?
Every USB device needs to have a unique product id and vendor id. Vendor IDs (VID) are sold
to companies and Product IDs (PID) are chosen by that company. So for example FTDI owns VID
#0403 and they give their chips ID's between #0000 and #FFFF (65,536 different PIDs) Older
Ardiuno's used FTDI's VID/PID as that is part of the deal when you purchase their chips. Because
the Uno does not use an FTDI chip anymore, the Arduino team had to purchase a USB Vendor
ID (VID). Every Arduino product will now have their own PID starting with the Uno (#0001).
If you want to make your own Arduino-compatible board, you have a few choices:
1. Don't use an 8u2, go with an FTDI chip instead that comes with a VID
2. If you're planning to make more than one board for your personal use, you will have to
purchase a VID from USB IF (http://adafru.it/aUN) for a one time $2000 fee
3. If you're making a single board for your own experimentation, you can pick a VID/PID that
doesn't interfere with any devices on your computer and substitute those in
4. You can purchase licenses for single VID/PID pairs from companies that develop USB
devices (we dont have any specific links at the moment)
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 10 of 37
However, you can't use the Arduino VID when distributing your own Arduino-compatibles! If the
cost of a VID is too much for you, simply go with an FTDI chip, K?
Every USB device needs to have a unique product id and vendor id. Vendor IDs (VID)
are sold to companies and Product IDs (PID) are chosen by that company. So for example
FTDI owns VID #0403 and they give their chips ID's between #0000 and #FFFF (65,536
different PIDs) Older Ardiuno's used FTDI's VID/PID as that is part of the deal when you
purchase their chips. Because the Uno does not use an FTDI chip anymore, the Arduino team
had to purchase a USB Vendor ID (VID). Every Arduino product will now have their own PID
starting with the Uno (#0001).
If you want to make your own Arduino-
compatible board, you have a few choices:
- Don't use an 8u2, go with an FTDI chip
instead that comes with a VID
- If you're planning to make more than one
board for your personal use, you will have to purchase a VID from USB IF (http://adafru.it/aUN) for a one time $2000
fee
- If you're making a single board for your own experimentation, you can
pick a VID/PID that doesn't interfere with any devices on your computer and substitute those
in
- You can purchase licenses for single VID/PID pairs from companies that develop
USB devices (we dont have any specific links at the moment)
However, you can't
use the Arduino VID when distributing your own Arduino-compatibles! If the cost of a VID is
too much for you, simply go with an FTDI chip, K?
I tried to find a place to buy some '8u2s and couldnt locate any!
Yep, there is a worldwide shortage of Atmel parts right now. Even the chip used in the
Arduino core (Atmega328P) is really hard to get. This happens after recesssions. We hope that
these and other Atmel chips will show up again in places like digikey soon. Till then, keep
searching on findchips.com!
Yep, there is a worldwide shortage of Atmel parts right now. Even the chip used in
the Arduino core (Atmega328P) is really hard to get. This happens after recesssions. We
hope that these and other Atmel chips will show up again in places like digikey soon. Till
then, keep searching on findchips.com!
So does this mean there may be an Arduino shortage?
Probably not. The Arduino team buys chips in the 10's of thousands, directly from Atmel.
They probably get priority over distributors because of this. We're assuming the team bought
enough to last for a while.
Probably not. The Arduino team buys chips in the 10's of thousands, directly from
Atmel. They probably get priority over distributors because of this. We're assuming the
team bought enough to last for a while.
Did the Arduino team move from the FTDI chip to the '8u2 to screw over derivative-makers?
While the appearance of a hard-to-get chip coupled with the VID/PID mishegas may seem to
be a little annoying, we don't think that means that the Arduino team is being malicious or
attempting to make life difficult for people who make derivatives. The move to an '8u2 makes
the Arduino more powerful, and easy to use as there are fewer drivers to install. While there is
a shortage now, there will eventually be plenty of chips on the market.
Some people in the Arduino forum have thought of forming a group that would purchase a VID
for Arduinites to use in personal projects. This is a pretty good idea and its probably the best
way to avoid VID/PID conflicts. Between 65,536 projects, that comes to under a nickel per PID.
And of course, because they didn't get rid of the bootloader system, you can always just use
an FTDI chip.
While the appearance of a hard-to-get chip coupled with the VID/PID mishegas may
© Adafruit Industries http://learn.adafruit.com/arduino-tips-tricks-and-techniques Page 11 of 37
seem to be a little annoying, we don't think that means that the Arduino team is being
malicious or attempting to make life difficult for people who make derivatives. The move to
an '8u2 makes the Arduino more powerful, and easy to use as there are fewer drivers to
install. While there is a shortage now, there will eventually be plenty of chips on the
market.
Some people in the Arduino forum have thought of
forming a group that would purchase a VID for Arduinites to use in personal projects. This is
a pretty good idea and its probably the best way to avoid VID/PID conflicts. Between 65,536
projects, that comes to under a nickel per PID.
And of course, because
they didn't get rid of the bootloader system, you can
always just use an
FTDI chip.
Are Shields still going to work?
All previous shields should still work perfectly fine as the header spacing is the same, the
core chip is the same and the location of parts is the same. In fact, some should work better
because the 3V supply has been upgraded (see next point).
All previous shields should still work perfectly