Search This Blog

Wednesday, 28 May 2014

Getting AVRDUDE working on Ubuntu with Pololu AVR ISP programmer and 3.3v ATtiny

I am an UBUNTU biggot... there, I said it!

I use Ubuntu 13.10 as my primary Operating System day in and day out.  If I *have* to use something else, I have access to MS Windows XP, Windows 7, and OSX Mountain Lion through the magic of VirtualBox.  <---- you Really want to try this!!


As part of my Dancing Brushbot project, I had to move out of my comfort zone in programming AVR chips.  I'm quite familiar with using the Arduino IDE to program *Arduino* boards, and have also used the IDE to program ATtiny8x chips by connecting them to an Arduino UNO ... 


For the current Brushbot project, I had made a small standalone ATtiny84 board with a builtin AVR ISP connector for programming without having to remove it from the robot.
I went to my local Robots Supply Store and purchased this Pololu AVR ISP programmer.
As I had previously programmed ATtiny chips with the UNO, I already had the proper Boards.txt configuration.

This should be simple right?


Wrong! 

  1. I plugged it in to my laptop USB port, 
  2. plugged the AVR ISP plug into the robot board
  3. From the Arduino IDE, selected  "Tools/Board/ATtiny84 (internal 8 mhz clock)"
  4. Also from the IDE  Selected Tools/Programmer AVR ISP
  5. Selected the correct USB serial port (/dev/ttyACM0)
  6. attempted to upload the compiled "Blink" sketch.

and it failed...   

AVRDUDE (the application that actually communicates with the Atmel processors) could not sync, told me to check my serial ports, etc... 

Now if you read my previous posting, you'll understand that I am RTFM challenged.


So I dug in, and did a little research, and quickly found http://openenergymonitor.org/emon/buildingblocks/avrisp

3. AVR ISP V2 - Pololu USB AVR Programmer (http://www.pololu.com/catalog/product/1300). This is quite a cheap programmer that works well on Linux Ubuntu, it can only programmed at 5v (needs 4V on MOSI pin to initialize) and requires the board to be externally powered. The following lines need to be added to programmers.txt in the Arduino Hardware folder:
avrispv2.name=AVR ISP v2
avrispv2.communication=serial

avrispv2.protocol=avrispv2
Using sudo,  I opened /usr/share/arduino/hardware/arduino/programmers.txt, and added the following 3 lines:
avrispv2.name=AVR ISP v2
avrispv2.communication=serial

avrispv2.protocol=avrispv2
I closed and reopened the Arduino IDE,  and the new programmer showed up.  I selected it from the Tools/Programmer menu, and again attempted to upload.

and it failed... 

Remember that RTFM issue? 

Looking at what I posted here from the Openenergy blog a paragraph up... 
This is quite a cheap programmer that works well on Linux Ubuntu, it can only programmed at 5v (needs 4V on MOSI pin to initialize) and requires the board to be externally powered.

This lead me to read the Pololu manual for the ARV ISP programmer (gasp!)

And  this comment on the pololu forum: 
Re: Pololu USB AVR ProgrammerPostby JeremyT » Fri Sep 13, 2013 3:34 pmYou can configure the Pololu USB AVR Programmer through Linux using PgmCmd from the Pololu USB Software Development Kit. PgmCmd is a command-line status and configuration utility. More information, such as how to compile the code, can be found in the README.txt in the SDK. By the way, I still recommend configuring it via Windows, as it would probably be easier. 
I have programmed an Atmega8U2 running at 3.3V with the Pololu USB AVR Programmer in Windows, and I do not expect there be a difference in programming with Linux, as long as the programmer is configured correctly. 
Using a level shifter, like the one you linked, would probably work. A resistor voltage divider would also suffice. However, I did not have any voltage divider when I programmed the Atmega8U2. 
- Jeremy

(Note:  as the AVR chips can run at up to 5.5v they do not need a level shifter)

I then downloaded the Pololu USB Software Development Kit for Linux. and read the Readme.txt file           (I know, eh?) 

To compile their C# applications, you need mono installed:
     sudo apt-get install libusb-1.0-0-dev mono-gmcs mono-devel libmono-winforms2.0-cil

     In the top level directory of the downloaded SDK, type "make".  


From there, I was able to cd to the pololu-usb-sdk/UsbAvrProgrammer/PgmCmd folder, and execute the AVR ISP programmer's command line utility   

./pgmcmd --list  

PgmCmd: Configuration and status utility for the Pololu USB AVR Programmer.
Version: 1.0.1.0
Options:
 -l, --list             list available devices
 -d, --device SERIALNUM (optional) select device with given serial number
 -s, --status           display complete device status
     --freq NUM         sets the ISP frequency (in units of kHz)
     --linea ID
       or --lineb ID    set serial control signal associated with line A or B.
                        Valid IDs are: none, cd, dsr, ri, dtr, rts.
                        Warning: dtr and rts are outputs: -f option is required
     --swminor HEXNUM   AVR ISP software version minor (in hex, e.g. A)
     --swmajor HEXNUM   AVR ISP software version major (in hex)
     --hw HEXNUM        AVR ISP software hardware version (in hex)
     --vddmin NUM       set minimum allowed target vdd (units of mV)
     --vddmaxrange NUM  set maximum allowed target vdd range (units of mV)
     --restoredefaults  restore factory settings
     --bootloader       put device in to bootloader (firmware upgrade) mode

then   ./pgmcmd --status  revealed... 

Serial number:                  00060244
Firmware version:               1.07
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   4384 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: None
  Measured Target VDD Minimum:  N/A
  Measured Target VDD Range:    N/A
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off


So... I ran ./pgmcmd --vddmin 3200  
to set a minimum VDD value of 3.2v.. resulting in...

Serial number:                  00060244
Firmware version:               1.07
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   3200 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: None
  Measured Target VDD Minimum:  N/A
  Measured Target VDD Range:    N/A
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off

I plugged the robots battery in (remember that requires the board to be externally powered comment?), plugged in the AVR ISP cable, opened the blink sketch in the Arduino IDE, and clicked the upload icon......

(drum roll please!)

The leds under the Sharp IR distance sensor came to life!!!  


Stay tuned for Funky Robotic Vibratory Dancing!



References:

Pololu USB AVR Programmer User's Guide
AVR ISP Programmers 
Stackexchange: How to use a Pololu 5v AVR ISP Programmer to program an AVR at 3.3v
forum.pololu.com: Pololu USB AVR Programmer - Ubuntu
Pololu: Pololu USB Software Development Kit
http://forum.arduino.cc/index.php?topic=73027.0;wap2
http://runawaybrainz.blogspot.ca/2013/05/arduino-pololu-usb-avr-programmer.html
http://provideyourown.com/2011/arduino-program-attiny/
http://www.open-electronics.org/arduino-isp-in-system-programming-and-stand-alone-circuits/
http://www.instructables.com/id/How-to-program-attiny-using-arduino-uno/
http://www.instructables.com/id/Using-the-Arduino-Uno-to-program-ATTINY84-20PU/
http://42bots.com/tutorials/programming-attiny84-attiny44-with-arduino-uno/
http://www.batsocks.co.uk/readme/isp_headers.htm
http://highlowtech.org/?p=1695