Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Last active September 9, 2019 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stonehippo/445db2b41ddcd3c57284978f4babb5aa to your computer and use it in GitHub Desktop.
Save stonehippo/445db2b41ddcd3c57284978f4babb5aa to your computer and use it in GitHub Desktop.

Notes on AVRDUDE, Arduino, and Raspberry Pi

I ran into some issues getting AVRDUDE and Arduino IDE working with my Raspberry Pis running Raspbian.

General Reference

Don't forget to add youself to the dialout group

The dialout group has access to many USB and TTY devices in Raspbian, so adding yourself to that is pretty important working with Arduino IDE. This is mentioned in the Arduino IDE Linux setup docs, but it's important enough that I'll put it here, too

sudo usermod -a -G dialout <username>

Updating udev rules

When USB devices get connected, the UDEV rules may prevent access expect by root or via sudo. I had this happen and lost a couple of hours trying to figure out what was going on.

One way to solve this is install the PlatformIO CLI on your Raspberry Pi. As part of the install, it installs a pretty comprehensive set of UDEV rules that cover a lot of platforms and devices. If you do this, other tools, including AVRDUDE and the Arduino IDE will also benefit, and you'll find that many devices "just work".

On the system where I ran into issues with a USBtinyISP, I discoverd that I was getting permissions issues trying to upload via the programmer or burn the bootloader. I tried the avrdude installed with the Arduino IDE from the command line and ran into the same problem. After hunting around a bit, I realized I'd missed tips on fixing this by adding udev rules to allow access (the Linux install of Arduino IDE includes a script, android-linux-setup.sh, that can install some udev rules, but not the ones I needed for USBtinyISP).

This fix is noted elsewhere, including the Adafruit overview of AVRDUDE and the USBtinyISP (look at the bottom of the page).

For myself, I fixed this with the following:

$ sudo nano /etc/udev/rules.d/99-USBtiny.rules

I added this to the 99-USBtiny.rules file:

SUBSYSTEM=="usb", ATTR{idVendor}=="1781", ATTR{idProduct}=="0c9f", MODE="0660", GROUP="dialout"

Then restarted UDEV:

$ sudo service udev restart
$ sudo udevadm control --reload-rules
$ sudo service udev status // check to be sure there's no errors

AVR Fuse Values

I've been working with bare ATtiny85 MCUs. There are a few things that I've found helpful in using them with AVRDUDE, Arduino IDE, and PlatformIO and dealing with the fuse bits.

AVR fuse settings

One handy resource, for both determining what you want fuse values on a AVR MCU to be, and what the current settings mean, is the EngBedded AVR Fuse Calculator.

Getting the current fuse settings can be done with AVRDUDE. Here's the command with a USBtinyISP when working with at ATtiny85:

avrdude -c usbtiny -p t85

This will report the current fuse values as part of the output. You can also connect via terminal mode and dump the fuse values.

AVRDUDE can also set fuse values. For example, here's the command to set the ATtiny85 fuse bits to default values:

sh avrdude -c usbtiny -p t85 -U lfuse:w:0x62:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m

The following will set the clock speed to 8mHz and preserve EEPROM data during a chip erase (the difference being the low and high bits, respectively, between the commands below and above):

sh avrdude -c usbtiny -p t85 -U lfuse:w:0xe2:m -U hfuse:w:0xd7:m -U efuse:w:0xff:m

A couple of other ways to set the fuse values:

  • If you're using the attiny board package in the Arduino IDE, you can select the MCU speed, then use the Burn Bootloader menu item to set the fuses
  • Same thing with attinycore with Arduino, you can select MCU speed, and other fuse settings as well, such as the brown-out level, and set them with Burn Bootloader
  • PlatformIO has a special run target for AVR, fuses, builtin for setting fuse values. Read the docs for info.

Understanding the fuse settings

The datasheets for the ATtiny MCUs are invaluable, but if you're looking for a good, clear explanation of what some of the options set via the fuse settings mean, take a look at the attinycore docs. For example, here's the detailed doc on the ATtinyx5 series.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment