Page 1 of 20
ATmega128RFA1 Dev Board Hookup Guide
CONTR IBUTORS:
J IM B 0
Overview
The ATmega128RFA1 is a really nifty system-on-chip, which combines an
ATmega128 microcontroller with a 2.4GHz, 802.15.4 RF transceiver. It’s
what you might get if you smashed a wireless module, like Zigbee or
Synapse, into an AVR microcontroller (like those on many Arduinos). We at
SparkFun thought the chip was neat enough to warrant its own
development board.
This tutorial is focused on documenting the schematic and hardware layout
of the development board. It’ll also explain how to program the board via
the pre-programmed serial bootloader, from the comfy confines of the
Arduino IDE. We’ll finish off the tutorial with some example code, detailing
the basics of the ATmega128RFA1’s RF communication capabilities.
ATmega128RFA1 Devlopment Board Features:
• Arduino R3 Form Factor (Arduino shield compatible)
• On-Board Chip Antenna
• 33 Digital I/O’s
◦ SPI, TWI (I2C), and UART hardware interfaces
• 8 Analog Inputs (10-bit resolution)
• 16 MHz operating frequency
• ATmegaBOOT bootloader pre-programmed (making it
programmable with an FTDI Basic and the Arduino IDE)
• On-board 3.3V regulator
• Other standard ATmega128RFA1 features:
◦ 6 Timers
◦ 128 KB Flash
Page 2 of 20
◦ 16 KB SRAM
◦ 4096 Bytes EEPROM
◦ 2.4 GHz RF Transciever
Required Materials
In this tutorial, we’ll cover the basics of getting the ATmega128RFA1
Development Board up-and-running. There will be a focus on programming
the board via the bootloader (in the Arduino IDE), using an FTDI Board. To
follow along, you’ll need these materials:
ATmega128RFA1 Development Board Hookup Guide
SparkFun Wish List
Break Away Male Headers - Right Angle
PRT-00553
A row of right angle male headers - break to fit. 40 pins that can be cu…
Break Away Headers - Straight
PRT-00116
A row of headers - break to fit. 40 pins that can be cut to any size. Us…
Female Headers
PRT-00115
Single row of 40-holes, female header. Can be cut to size with a pair…
SparkFun FTDI Basic Breakout - 3.3V
DEV-09873
This is the newest revision of our [FTDI Basic](http://www.sparkfun.co…
DC Barrel Power Jack/Connector
PRT-00119
DC power jack/connector. This is a common barrel-type power jack fo…
Male headers are useful for soldering into programming headers, while
female headers help to add shield compatibility. A pair of
ATmega128RFA1s – either the SparkFun board, or another development
platform – are required to test communication between the chips.
Required Tools
This assembly will require some simple soldering, so you’ll need a soldering
iron and a bit of solder. If you’ve never soldered before, check out our how
to solder guide.
Suggested Reading
Page 3 of 20
This tutorial assumes some previous electronics knowledge to get along. If
you’re not familiar with these concepts, consider checking out our tutorials
on the subject!
• What is an Arduino - While not directly using an Arduino platform,
this tutorial will make use of the IDE.
• Installing FTDI Drivers - If you’ve never used an FTDI cable or board
before, you’ll need to install drivers.
• Serial Communication - We’ll be using the ATmega128RFA1 boards
as wireless bridges between two serial devices.
• How to Use GitHub - All of the source code and design files are
hosted on Github.
About the ATmega128RFA1
The ATmega128RFA1 is a portmanteau of sorts – two separate
components combined to form one device. Half microcontroller, half RF
transceiver.
ATmega128
Half of the ATmega128RFA1 is an ATmega128, an old mainstay of Atmel
AVR microcontrollers. The 128 is an 8-bit microcontroller with 128kB of
programmable flash, an abundance of I/O pins, an analog-to-digital
converter, and much more.
Low-Power 2.4GHz Transceiver
The other half of the ATmega128RFA1 – the “RFA1” part – is what really
makes it unique. That’s because built into the chip is a 2.4GHz wireless
radio transceiver. So one ATmega128RFA1 could talk to another up to
about 75m away, at speeds of up to 2 Mbps.
Because it has built-in hardware support for IEEE 802.15.4, the chip can
also talk to RF modules, like ZigBee’s, Synapse modules, and
IPv6/6LoWPAN devices. 802.15.4 defines a personal area network (PAN)
of wireless devices. It’s very similar to the Bluetooth standard (802.15.1) in
that way. Unlike Bluetooth though, which can send data at around 3Mbps,
802.15.4 can’t achieve as high a data rate, maxing out at around 250kbps.
Still, 802.15.4 is an excellent, cost-sensitive choice when you don’t need to
quickly send huge chunks of wireless data.
In comparison to the other wireless standards and protocols out there, the
ATmega128RFA1’s transceiver is geared towards low-level, low-power,
low-speed, low-data rate, low-range communication between devices. This
isn’t like WiFi, where we need to stream video, while downloading pictures
of cats, and syncing our dropboxes. 802.15.4 is for sending data between
embedded devices. Maybe you want to periodically transmit data from a
Page 4 of 20
weather station to a display in your house, or turn your coffee machine on
from the bed. That’s the type of situation 802.15.4 works best in! That
sounds like a job for the ATmega128RFA1 Dev Board!
Schematic and Hardware
The development board surrounds the ATmega128RFA1 with all of the
supporting circuitry one might need to get up-and-running with the chip.
Click the image to get a bigger view of the schematic. Or you can download
a PDF of it.
Power Input
The power input section of the circuit includes a voltage regulator, which
feeds 3.3V to the rest of the circuit. The following footprints are provided for
power input:
•
•
•
•
DC Barrel Jack
JST connector (2-Pin, Right-Angle)
3.5mm 2-Pin Screw Terminal
Standard 0.1"-spaced header
The slide-switch on the side of the board controls the flow of the input
power sources above to the regulator.
The 3.3V and GND pins are also broken out along the side of the board.
These nets are unregulated, but can be used to supply a clean, regulated
3.3V voltage source to the board.
ATmega128RFA1 Circuitry
The ATmega128RFA1 is supported by a 16MHz crystal and an assortment
of decoupling caps. The RF section of the board has a crystal of its own, as
well as a chip antenna and circuitry to support the RF interface. Try to
avoid placing components near the antenna, as they may interfere with
signal strength.
Page 5 of 20
All digital I/O pins of the ATmega128RFA1 are broken out in some form or
another. Two on-board LEDs are connected to the MCU’s pins B6 and B7.
The remaining I/O’s are broken out to the outer headers of the board. The
eight analog inputs on port F are available in the same place you’d expect
to find an Arduino’s analog pins. Key digital pins, like the hardware SPI, I2C,
and UART pins, are broken out to the same locations found on Arduinos as
well.
Programming Headers
There are two programming headers on the board. One 6-pin (2x3) ICSP
header, which can be used to program the chip using a standard AVR incircuit programmer. A 6-pin serial header near the power inputs can also be
used to program the chip (assuming the bootloader’s still on there); this
header should match up to common FTDI headers and cables (just make
sure they’re the 3.3V variety).
Powering the Board
There are a variety of ways to power the development board. Input jacks
are broken out for barrel jack, JST, screw, and 0.1" connectors. Whichever
voltage supply you choose to power the board, it should be between 4.5
and 15V. Each of these power sources is fed into the voltage regulator,
which drops the voltage down to 3.3V.
If you’re using the barrel jack, a 5V or 9V wall-wart is a good choice for
power source.
Voltage can be fed directly to the chip, using the headers labeled “3.3V” –
just make sure the voltage doesn’t exceed 3.6V. The ATmega128RFA1 can
only operate at voltages between 1.8 and 3.6V.
One of the ATmega128RFA1’s key features is its low power consumption.
Sending or receiving RF data should only require 16 to 18mA of current.
Idling, the chip should only require about 1-4.5mA. Each of the output pins
can source/sink between 2-8mA.
Check out the datasheet for more electrical specs.
Page 6 of 20
How To Program
Below, we’ll explain the two interfaces available for programming the
ATmega128RFA1. There is a serial bootloader pre-programmed onto the
board, or you can use the standard AVR 6-pin ISP header. In either case,
you’ll probably need to solder headers onto the programming port pins to
connect a programmer.
ATmegaBOOT Serial Bootloader
Bootloaders are small programs loaded onto a chip, which make uploading
compiled code easier. Instead of requiring a specialized (often expensive)
piece of hardware – a programmer – a more generalized tool can be used
to upload to the board.
The ATmega128RFA1 Development Board ships with a pre-programmed
serial bootloader. Either an (archaic) serial port can be used to upload code
to the board, or a more common USB-to-Serial converter can be used. We
recommend the 3.3V FTDI Basic board, which interfaces directly to the
6-pin serial header of the dev board.
A 3.3V FTDI Basic Board connected to the development board’s serial
programming header. Right-angle headers were previously soldered to the
header. As a bonus, the FTDI basic can also power the dev board.
The bootloader on the ATmega128RFA1 Dev Board is a variation of the
ATmegaBOOT serial bootloader, which was used on older Arduinos like the
Duemilanove. This bootloader uses the UART0 of the ATmega128RFA1,
and expects uploaded code at a baud rate of 57600.
If you’re familiar with avrdude, a command like the one below should
upload a compiled piece of code.
avrdude p atmega128rfa1 c arduino P \\.\COM## b 57600 D V U flash:w:testsketch.hex:i
Page 7 of 20
Or, skip avrdude, and use the Arduino IDE with the bootloader, as we’ll
explain in the following pages.
ISP Programmer
If you’ve got an AVR programmer and would rather skip working with the
bootloader, the standard AVR 2x3 pin programming header is broken out
on the board. Pin 1 of the programming port is marked with a silk-screened
dash.
An AVR Pocket Programmer connected to the development board’s ISP
header. Straight headers were previously soldered to the header to allow
for the connection.
If you don’t have an AVR programmer but would still prefer using this
method for uploading code, we’d recommend the USB Pocket AVR
Programmer. Using that, an avrdude command like below can be used to
upload a program:
avrdude p atmega128rfa1 c usbtiny P usb D V U flash:w:testsketch.hex:i
If you have an Arduino, that can work as an alternative to the AVR
programmer – check out the the ArduinoISP sketch under the examples
menu.
Arduino Compatibility
Everyone loves Arduino! The simplified IDE and host of libraries and
supporting code make it an awesome place to start prototyping. The
ATmega128RFA1 shares a lot in common with the popular ATmega328
used on the Arduino Uno, so it seems reasonable that we should be able to
program the board using the Arduino software. There are just a few extra
steps which need to be taken to do so.
First, if you haven’t already, download and install Arduino. Then…
Update WinAVR (For Windows Users)
Page 8 of 20
WinAVR is a wonderful, free, and open-source package of AVR utilities
(including avr-gcc and avrdude) and definition files. It forms the backbone
of most AVR development, including any AVR-based Arduino.
Unfortunately, Arduino is (as of v1.0.5) packaged with an out-of-date
version of WinAVR, which does not support the ATmega128RFA1. But it’s
easy to upgrade!
Download the most recent version of WinAVR (WinAVR-20100110 as of
writing this) from the WinAVR project page. It should be installed over the
old version of WinAVR included with Arduino, which is located in the
Arduino\hardware\tools\avr directory. Follow these steps to update
WinAVR:
1. Run the WinAVR installer (WinAVR-20100110-install.exe).
2. Cick "Run", Select your install Language, Click "Next", Click "I
Agree" (unless you don't?), until you get to the install location screen.
3. On the install location screen, click Browse..., and navigate to
the ../hardware/tools/avr directory inside your Arduino install (with the
Arduino installer, it should go to the location seen in this image):
4. Click next. On the next screen, make sure Install files and Add
Directories to PATH are selected. Install Programmers Notepad is
optional.
Page 9 of 20
5. Click Install and wait for the install to finish.
Alternative to that method, you can install WinAVR to a standalone
directory, and copy/paste it into the Arduino directory.
Update AVRGCC, Etc. With CrossPack (For Mac
Users)
If you’re using the ATmega128RFA1 Dev Board with Mac, a similar set of
steps is required to update your AVRGCC and AVR include files.
CrossPack is an excellent source for up-to-date AVR development files.
Go to their download page, and grab the most recent version.
Once the disk image is downloaded, you can install the “CrossPackAVR.pkg” file. By default, the package will install
to /usr/local/CrossPackAVR20131216 (the date part of that name is
subject to change). Now you’ll need to copy everything from that directory
into your Arduino application.
To copy them into your Arduino app, right-click on the “Arduino” app and
select Show Package Contents. Then navigate to
the /Contents/Resources/Java/hardware/tools/avr folder within there.
Finally, copy everything from the CrossPack download into that Arduino
app directory.
Voila! Onto the next step, adding the board definition.
Add the Board Definitions File
We also need to add a board definition file to be able to use the
ATmega128RFA1 Dev Board within the Arduino environment. To begin,
download the ATmega128RFA1 arduino addon.
Page 10 of 20
The 128RFA1-DEV folder from that download should be added to a
hardware directory within your Arduino sketchbook. Normally the
sketchbook will install to your documents/Arduino folder. If a hardware
folder isn’t already there, make it.
This directory contains a boards.txt file which defines the ATmega128RFA1
Dev Board, and adds a selectable option under the Tools > Board menu.
When you open the Arduino IDE (close and reopen it if it’s already open),
this option should be added to the menu:
When OS X prompts you, to ask what to do with merge conflicts, tell it to
Keep Newer. This will keep any old, un-updated files, in place.
Pin Mapping
After you’ve added ATmega128RFA1-compatibility to your Arduino IDE,
you can take advantage of all of the wonderful libraries you may have
grown acustomed to, including Serial, SPI, and Wire. In addition to that
each pin is mapped to a unique pin number, which you can invoke all of
your digitalWrite , digitalRead , analogWrite , and analogRead needs
upon.
The addon defines all of the ATmega128RFA1’s pins as singular numbers.
Just as Arduino has pins 0-13, and A0-A6, this development board has pins
0-25, and A0-A7. Here’s how the pins are mapped out:
Page 11 of 20
There are a few pins with PWM functionality – 3, 4, 5, 8, 9, 19, 34, and 35
– which you can use for analogWrite . Note that pins 34 and 35 are not
broken out to pins. They’re only connected to on-board LEDs.
The SPI, UART, and I2C pins are where you’d expect them to be on an
equivalent R3-or-later Arduino Uno. There is a second UART – UART1 –
on pins D2 and D3.
Example Code
Example Sketch: RF Chat
You can download the RF chat example here (or grab it from github). This
is a simple example of how to make use of the RF functionality of the
ATmega128RFA1. The radio-specific functions are split off into a secondary
file – RadioFunctions.h.
You’ll need two ATmega128RFA1’s for this example (it’s hard to demo the
RF functionality without something to talk to!). They can be tied to the same
computer, or a few rooms away. The maximum distance should be around
75m, but that’s with complete line-of-sight, walls will diminish the range.
Upload the same sketch to each dev board. Then open up a serial monitor
on each. You can use either the Arduino Serial Monitor, or a stand-alone
terminal program (Tera Term is great for Windows users, Cool Term should
work for Mac). Open up each serial port to 9600 bps (8 data bits, no parity,
1 stop bit), and start typing away! What’s typed into one terminal should
pop up into another.
Page 12 of 20
Understanding the Sketch
There are a few key functions, and a few interrupt routines that are key to
the workings of the RF transceiver.
rfBegin()
First, the radio must be initialized by calling the rfBegin() function. This is
called in the setup() portion of the sketch. Check out the comments within
the code for a line-by-line explanation. This function initializes the
ATmega128RFA1’s radio. The lone parameter for this function sets the
radio’s 2.4GHz channel, which should be some value between 11 and 26.
Radios must be on the same channel to communicate with each other.
Page 13 of 20
// Initialize the RFA1's lowpower 2.4GHz transciever.
// Sets up the state machine, and gets the radio into
// the RX_ON state. Interrupts are enabled for RX
// begin and end, as well as TX end.
uint8_t rfBegin(uint8_t channel)
{
for (int i=0; i