Arduino on the ProtoAVR

The ProtoAVR now supports the Arduino Programming language. Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. It's perfect for robotics hobbyists, since it gives you all the speed of C while being easy to learn and quick to code. The fact that it's also free and Open Source have made it the fastest growing language in the world of physical computing.

This article explains how to install the Arduino IDE, configure it to work with the ProtoAVR, and upload your programs to your ProtoAVR. We'll go through the embedded version of a "Hello World" (blinking an LED), including building the circuit and examining the code.

Finally, there's a bit of reference info to help you cross reference the standard Atmel pin names that the ProtoAVR is labeled with to the names that are used by the Arduino environment.

Installation

NOTE: At present, the Arduino software only supports the ATMega644p, so it will not work on ProtoAVRs with the 324p or 164p. We hope to get it ported to the other processors, and will update these docs when the other versions are available.

Installing Arduino is about as easy as can be. In fact, on Windows, no installation is necessary. Just download the program, extract it into the directory of your choice, and run it by double-clicking on the "run.bat" icon.

In order to use Arduino with the ProtoAVR, you'll need to add some files to the standard Arduino distribution. Download the latest version of the Sanguino software, and extract it to a temporary location.

* copy sanguino-software-1.0/cores/sanguino to arduino-0011/hardware/cores/sanguino
* copy sanguino-software-1.0/bootloaders/atmega644p to arduino-0011/hardware/bootloader/atmega644p

Next, open the file arduino-0011/hardware/boards.txt in your text editor (such as Notepad) and add the following text at the bottom of the file.

##############################################################

protoavr.name=ProtoAVR
protoavr.upload.protocol=stk500
protoavr.upload.maximum_size=63488
protoavr.upload.speed=38400
protoavr.bootloader.low_fuses=0xFF
protoavr.bootloader.high_fuses=0xDC
protoavr.bootloader.extended_fuses=0xFD
protoavr.bootloader.path=atmega644p
protoavr.bootloader.file=ATmegaBOOT_644.hex
protoavr.bootloader.unlock_bits=0x3F
protoavr.bootloader.lock_bits=0x0F
protoavr.build.mcu=atmega644p
protoavr.build.f_cpu=18432000L
protoavr.build.core=sanguino
protoavr.verbose=false

At this point, start (or restart) your Arduino IDE and confirm that you are seeing the ProtoAVR entry under the Tools > Boards submenu. While you're in the Arduino IDE, we need to find out where your preferences file is stored. Open the Preferences dialog under the File menu, and make a note of the location of the preferences.txt file noted at the bottom of the dialog.

Once you've done that, close your IDE and open that file in your text editor. Locate the line that starts with upload.using= and change it to match the ISP programmer you're using. Here are a few of the more common programmers and the identifier to use in your preferences file:

AVRISP: avrisp
AVRISP mkII: avrispmkii
USBtinyISP: usbtinyisp
Parallel: parallel

There are others that we'll be adding as we come across them. If your programmer isn't noted here, please let us know & we'll help find the appropriate identifier and add it to the list. Note, the identifier is case sensitive and needs to be in all lower case.

Your First Circuit

Hopefully, everything is now properly configured. We'll test it in a moment, but first, let's build a quick circuit in a breadboard. Here's the schematic to build:
ledblink.gif

Connect a jumper wire from pin PD5 (Pin 13 in Arduino speak) to a 220 Ohm resistor to the short leg of an LED, and connect the long leg of the LED to ground. Note, the pins in that schematic are numbered one to eight, not zero to seven as is the standard in the microcontroller world. It's a little confusing at first, but you'll get used to it. In this case, connect to the pin labeled on the board as "OC1A".

Programs in Arduino speak are called "Sketches". For this one, we'll be using one of the sample sketches that are included in the Arduino distribution. Launch the Arduino IDE and select File > Sketchbook > Examples > Digital > Blink. The code is well commented, so it should be pretty clear. If you need more info, visit the link in the sketch. One thing to note, unlike the standard Arduino, the ProtoAVR doesn't include the inline resistor on pin 13 so you'll need to add one as shown in the schematic.

Uploading your Sketch

Now's the moment of truth where we find out whether the configuration is correct. First, click the "Verify" button (looks like a "Play" button, a triangle pointing to the right). This will compile the code to make sure it doesn't have any errors. Since this code was written by the Arduino developers, it should compile without any problems. Assuming that goes as planned, the next step is to upload your sketch. Click the "Upload" button (an arrow pointing to the right towards two rows of dots). If all goes well, you should see the message "Done uploading" at the in the message pane at the bottom of the window and your LED should start to blink.

It didn't work!

Uh oh… First, we need to state that while we will do our best to help you resolve any problems, we can only provide very limited troubleshooting assistance with your code and configuration. We're happy to try, but we can't help with every situation. Fortunately, the Arduino community is one of the best, most supportive groups around. If you have questions, try searching the Arduino forum and Google. If you still can't find the answer, let us know or try posting to the Arduino forum.

What's next?

There are literally hundreds of great sites on using the Arduino. Here are a few great sites to start out with:

Arduino Tutorials
The tutorials at the official Arduino site.
Arduino Foundations
If you're brand new to microcontrollers, start here. This explains the details about how a microcontroller works.
Getting Started with Arduino
A short PDF guide to using the Arduino

Reference

The ProtoAVR uses the Sanguino extension to to the normal Arduino software to support the ATMega644p. For documentation on using the extended features that the 644p provides, see the Sanguino website.

Since the pins on the ProtoAVR are labeled for use in standard ATMega programming, they don't use the same numbering system that the Arduino uses. Here's a cross reference between the numbering systems:

  • Digital 0 - PB0
  • Digital 1 - PB1
  • Digital 2 - PB2 - Interrupt 2
  • Digital 3 - PB3 - PWM
  • Digital 4 - PB4 - PWM
  • Digital 5 - PB5 - MOSI (used for SPI)
  • Digital 6 - PB6 - MISO (used for SPI)
  • Digital 7 - PB7 - SCK (used for SPI)
  • Digital 8 - PD0 - Rx0 (shared with the Serial port adapter)
  • Digital 9 - PD1 - Tx0 (shared with the Serial port adapter)
  • Digital 10 - PD2 - Rx1 / Interrupt 0 (shared with the extra serial connection)
  • Digital 11 - PD3 - Tx1 / Interrupt 1 (shared with the extra serial connection)
  • Digital 12 - PD4 - PWM
  • Digital 13 - PD5 - PWM
  • Digital 14 - PD6 - PWM
  • Digital 15 - PD7 - PWM
  • Digital 16 - PC0 - SCL (used for I2C)
  • Digital 17 - PC1 - SDA (used for I2C)
  • Digital 18 - PC2
  • Digital 19 - PC3
  • Digital 20 - PC4
  • Digital 21 - PC5
  • Digital 22 - PC6
  • Digital 23 - PC7
  • Digital 24 - PA7 - Analog 7
  • Digital 25 - PA6 - Analog 6
  • Digital 26 - PA5 - Analog 5
  • Digital 27 - PA4 - Analog 4
  • Digital 28 - PA3 - Analog 3
  • Digital 29 - PA2 - Analog 2
  • Digital 30 - PA1 - Analog 1
  • Digital 31 - PA0 - Analog 0

Note that digital pins 24-31 are in reverse order.

These extra features are optional, and the pins function as digital I/O pins by default.

Page tags: arduino protoavr
page_revision: 9, last_edited: 1219221361|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License