After fumbling around for a couple of hours, I have finally managed to flash the traditional blink sketch on an ATtiny85 with the Sparkfun Tiny AVR Programmer using the Arduino IDE (version 1.8.10) in Ubuntu 18.04. Perhaps others will run into some of the difficulties I encountered so here is how I go about it. As usual, I am merely collating the work of others.
Table of Contents
Arduino Core
The Tiny AVR Programmer Hookup Guide on the Sparkfun site should be read even if it is Windows oriented. There you will find that an Arduino Core for ATtiny AVR micro controllers (models 25, 45, 85, 24, 44 and 84) was developed by David A. Mellis and that it is available on GitHub: github.com/damellis/attiny. The procedure is straightforward, at least for those that have already installed an additional board manager. Basically, it is a two-step operation to add support for these micro controllers to the Arduino IDE.
1. Add the ATtiny board manager
Go to Preferences
in the File
menu and
add the following URL
to the Additional Boards Manager URLs
list.
If this is the first additional URL, it can be pasted directly into the edit box. Otherwise, click on the button to the right of the edit box and paste the URL in a separate line in the list as shown above.
2. Install the ATtiny core
Go to the Boards Manager
using the
Tools
/Board: "currently selected board"
menu. The Boards Manager
is at the top of the list of boards
currently supported.
Enter attiny
in the search filter at the top of the
window and then select the attiny
package and click on the
install
button.
That is it, but if this is a bit too terse, look at the very detailed installation instructions from the High-Low Tech Group.
Permissions
The good news it that it is not necessary to install drivers in Linux (in Windows, follow the
instructions in the Automatically Install the Drivers with Zadig section of
the Hookup Guide.) Just connect the AVR programmer to a USB port directly or
with an extension cable. It should show up as Multiple Vendors
USBtiny
in the list of connected USB devices.
If the device does not show up, try with another USB cable (if one was used) and with another USB port avoiding going through a USB hub. If the programmer still does not show up, then reboot and try connecting the AVR programmer.
Note how the programmer is connected to bus 3 as device 10. Its owner and
group are root
and others (i.e. me) do not have write access to
the device.
That will make it hard to flash a sketch on the AVR but there are ways to
temporarily work around this problem. The Arduino IDE could be started as
root
.
Of course the correct directory containing the arduino
executable will need to be specified. Another possibility is to grant others
write privileges to the device.
These kludges do work and it would be possible to go on directly to the
next section to upload the blink sketch to the micro controller. However, it
is better to create a udev
rule that will automatically set the
needed permissions when the programmer is connected and recognized.
First the usual udev rules directory will be made the current working
directory and then it is probably best to check that no rule exists for
vendor 1781
.
If a rule exits for vendor 1781
, check that it is for a
product other than 0c9f
otherwise there will be a conflict.
Assuming there is no conflict or that it has been taken care of, then a
rule will be created. I used the following
which I created with the nano
editor as the super user.
To see the effect of this rule, disconnect the programmer and run the
following two commands that restart the udev
system.
Reconnect the AVR programmer and then find it again as it will probably be connected as a different device.
Now others cannot even read the programmer, but that's no problem as the
group is now adm
instead of root
and the user (me!)
is a member of that group:
The default user should be a member of the plugdev
group
also. In all likelihood the default user is a member of both
plugdev
and adm
. I considered using the
dialout
group instead of adm
, because many micro
controllers programmed with the Arduino IDE are reached with TTY-USB
converters that are assigned to that group. It really does not matter.
The Arduino IDE can be started in the usual way and it will be possible to download a sketch to an AVR as shown in the next section. Before, I'll mention that others suggest the following rules.
The first corresponds to the second temporary solution discussed initially, but with the advantage that it will work no matter which device number is assigned to the AVR programmer when it is hot plugged into the USB bus. The second version is for those that hold up their pants up with suspenders and a belt.
ATtiny85 Blink
Uploading the ubiquitous blink sketch to an ATtiny85 is not quite the same thing as uploading to a Arduino Uno or an ESP8266. For one thing, the AVR programmer does not show up as a serial device. Nevertheless, the procedure is just as simple.
- Disconnect the AVR programmer.
- Insert the micro controller into the DIP socket of the AVR programmer. Make sure that it is oriented correctly: the dot on the DIP package should be at the top left corner when the programmer USB port is to your left.
- Get the
Blink
sketch using the IDE menu:File/Examples/01.Basics/Blink
. - Insert the line
#define LED_BUILTIN 0
into the sketch just before thevoid setup()
line in the sketch.This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Blink */ #define LED_BUILTIN 0 // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } - Select the correct board and parameters in the
Tools
menu. The screen capture shows the settings for an ATTiny85.Note how the communication port is grayed out; instead the
Programmer
should be set toUSBtinyISP
. - Upload the sketch in the usual manner: with the two key combination
CtrlU or the menu
Sketch/Upload.
Hopefully, you will have success as I had and you will see the amber LED of the AVR programmer flash quickly as the sketch is transferred to the micro controller and then flash on and off steadily once the sketch starts executing.
References and a Final Thought
Here are comments by anonymous clients on vendor sites that were my initial sources:
- Help fixing device permissions for A000092 usb programmer board, in Ubuntu (2016-03-21).
- Great USB programmer for ATtiny85. Works on Linux! Compatible with Arduino IDE! (2016-12-16).
Even more helpful were the following postings, especially the one by Rihard Kubilis which I wished I had found at the outset.
- Gregor van Egdom (2016-12-05), Using USBtinyISP with Ubuntu.
- Rihards Kubilis [Console Breadcrumb] (2016-11-12), Getting started with Attiny microcontroller.
The Tiny AVR Programmer Hookup Guide by Sparkfun and Programming an ATtiny w/ Arduino 1.6 (or 1.0) by David A. Mellis have already been mentioned.
Finally, there are more than one Arduino core for ATtiny devices available. Take a look at the ATTinyCore by Spence Konde. It supports many more ATTiny controllers and it seems to contain more functionalities.