Teensy 2.0 as AVR ISP programmer

Intro

Hi. I'm going to try and capture my process of turning the Teensy 2.0 into an AVR ISP programmer. That is, I just want to use the Teensy 2.0 as a means of programming other AVRs (in this case an ATTiny45) via USB.

There be dragons. And hopefully we can slay them as I document enough.

In my environment, I'm using 64-bit Debian (unstable).

Schematic

Using the Teensy 2.0 pinout:

and the ATTiny45 pinout reference:

...we draw the following simple circuit:

Please use this table for the connections:

Tiny   Teensy
----   ------
 1      B0
 2      (no connection)
 3      (no connection)
 4      GND
 5      B2
 6      B3
 7      B1
 8      VCC

Some notes:

  • Power and ground are straightforward
  • Teensy SCK is connected to Tiny45 SCK
  • Teensy MISO is connected to Tiny45 MISO
  • Teensy MOSI is connected to Tiny45 MOSI
  • Teensy SS/PB0/pin1 is connected to RESET' on the tiny45

The Hardware

So then we build it. We pull out a breadboard, connect up power and ground, and add the Teensy and ATTiny45. We then make the above mentioned connections. We think it looks good when it looks something like this:

Trust nothing!

Because we're cynical skeptics, we check all connections with our meter....

Vcc...OK!
Ground...OK!
SCK...OK!
MISO...OK!
MOSI....OK!
SS/RESET'....OK!

Looks ok so far. All 5 connections look to be ok. :)

Initial Environment

udev devices/permissions

Let's set up the environment. We understand that plugging in a Teensy requires us to have some udev rules set up, so we grab the latest version from PJRC:


$ wget http://www.pjrc.com/teensy/49-teensy.rules
--2012-01-12 22:10:19-- http://www.pjrc.com/teensy/49-teensy.rules
Resolving www.pjrc.com (www.pjrc.com)... 67.19.59.50
Connecting to www.pjrc.com (www.pjrc.com)|67.19.59.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1804 (1.8K) [text/plain]
Saving to: `49-teensy.rules'

100%[=========================================================================>] 1,804 --.-K/s in 0.001s

2012-01-12 22:10:20 (1.35 MB/s) - `49-teensy.rules' saved [1804/1804]

$ sudo mv 49-teensy.rules /etc/udev/rules.d/

Please note that this grants 0666 (global readability/writability) to the device, and may be (an unlikely) security concern in your environment.

We then restart udev to make sure it sees the changes:

$ sudo /etc/init.d/udev restart
Stopping the hotplug events dispatcher: udevd.
Starting the hotplug events dispatcher: udevd.

The Software

Arduino

We need the arduino software, so we go to the arduino site and grab the latest version:

$ wget http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz
--2012-01-12 22:21:09-- http://arduino.googlecode.com/files/arduino-1.0-linux64.tgz
Resolving arduino.googlecode.com (arduino.googlecode.com)... 74.125.127.82
Connecting to arduino.googlecode.com (arduino.googlecode.com)|74.125.127.82|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4351508 (4.1M) [application/x-gzip]
Saving to: `arduino-1.0-linux64.tgz'

100%[===========================================================================================>] 4,351,508 308K/s in 17s

2012-01-12 22:21:26 (248 KB/s) - `arduino-1.0-linux64.tgz' saved [4351508/4351508]

And then we extract the tarball:

$ tar -xzf arduino-1.0-linux64.tgz

Teensyduino

In order to program for and to program the Teensy, we need Teensyduino, a software add-on to the Arduino IDE. We download the latest version from PJRC:

$ wget http://pjrc.com/teensy/td_107/teensyduino.64bit
--2012-01-12 22:27:49-- http://pjrc.com/teensy/td_107/teensyduino.64bit
Resolving pjrc.com (pjrc.com)... 67.19.59.50
Connecting to pjrc.com (pjrc.com)|67.19.59.50|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2780140 (2.7M) [text/plain]
Saving to: `teensyduino.64bit'

100%[===========================================================================================>] 2,780,140 309K/s in 11s

2012-01-12 22:28:00 (254 KB/s) - `teensyduino.64bit' saved [2780140/2780140]

make it runnable:

$ chmod 755 teensyduino.64bit

and then we install it by running it:

$ ./teensyduino.64bit

sadly it's a graphical installer, so we get to click through some screens:

Click next:

Enter in the path where you extracted the Arduino IDE (above):

Click All (it's small and hard drives are big), then Next:

After the progress bars flutter, you should see a screen like this:

Installing the ArduinoISP firmware

Crank up the circuit by plugging a mini USB cable into the Teensy on the breadboard (the other end goes into the computer)

Launch the arduino IDE:

$ /home/jason/prog/atmel/arduino-1.0/arduino

And then choose File -> Examples -> ArduinoISP from the menu.

Click on the "upload" icon to compile the project and upload the firmware to the Teensy:

the ArduinoIDE/Teensyduino will launch the Teensy loader. It will display some stuff (loading/reboot ok) before showing the default loader screen:

At this point, the Teensy should now be running the ArduinoISP firmware and should be capable of programming an ATTiny45 (and a bunch of others!)

To be very sure, we wire an LED and 3k resistor up to pin 11 (PC6) on the Teensy. When the ArduinoISP firmware is running, it kinda throbs in a slow heartbeat pattern.

GREAT SUCCESS! So far we think we're good.

Let's Program the Tiny45 - Take 1

Since the original goal (if you've forgotten by now) was to program the ATTiny45, let's try doing that.

We compile a small program for the Tiny45 (using avr-gcc, documented elsewhere) and attempt to upload the .hex file using avrdude:

$ avrdude -p t45 -c arduino -P /dev/ttyACM0 -U flash:w:servo.hex:i

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9206
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: reading input file "servo.hex"
avrdude: writing flash (204 bytes):

Writing | | 0% 0.00s
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x11
avrdude: stk500_cmd(): programmer is out of sync

The above text in red indicates that we have failed. I wonder if we can read the contents of the Tiny45?

$ avrdude -p t45 -c arduino -P /dev/ttyACM0 -U flash:r:/tmp/dump.hex:i

avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny45
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.04s

avrdude: Device signature = 0x1e9206
avrdude: reading flash memory:

Reading | ################################################## | 100% 6.24s

avrdude: writing output file "/tmp/dump.hex"

avrdude: safemode: Fuses OK

avrdude done. Thank you.

Yes, it appears as though we can read the tiny45 using avrdude just fine (even though the contents of the dump just show that it's been erased).

WTF.

Footnotes

TBD

References

http://provideyourown.com/2011/arduino-program-attiny/
http://hlt.media.mit.edu/?p=1229
http://hlt.media.mit.edu/?p=1695
http://code.google.com/p/arduino-tiny/issues/detail?id=34
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/

AttachmentSize
ATTiny45-Pinout.png27.3 KB
teensy_pinout2a.png208.23 KB
teensy_avrisp_tiny45_circuit.png65.55 KB
teensy_avrisp_circuit.jpg194.17 KB
teensyduino_installer1.png94.64 KB
teensyduino_installer2.png44.15 KB
teensyduino_installer3.png47.07 KB
teensyduino_installer4.png58.52 KB
upload-to-teensy-from-arduino-ide.png28.78 KB
teensy-loader.png50.21 KB

Comments

Possible solution

Following these instructions almost exactly I got the same error. I'm using a Teensy++ 2.0 board and an ATTiny85, so the pins are a little different but not much. I was trying to run avrdude from the ArduinoIDE (changed the Programmer to ArduinoISP) and I tried all the ATTiny85 options, all of them gave the same error as you get.

When I ran avrdude from the command line, however, it ran okay.

/home/roger/arduino-1.0/hardware/tools/avrdude -C /home/roger/arduino-1.0/hardware/tools/avrdude.conf -c stk500v1 -v -v -v -v -p t85 -P /dev/ttyUSB000 -b9600 -U flash:w:~/tmp/BlinkWithoutDelay.cpp.hex:i

I haven't yet checked that the ATTiny does anything. Reading back also gives no error and returns me a 12 byte hex file. That seems a little small maybe but I'm encouraged.

oops. It wasn't working after all but it is now

oops. No it wasn't working but it seems to be working for me now. In spite of what I wrote above it was giving the same protocol error as before but I had not looked carefully enough.

Since then I found this http://code.google.com/p/arduino-tiny/issues/detail?id=34 Which refers to this file: http://mega-isp.googlecode.com/files/ArduinoISP.04.zip

Which I downloaded and fiddled about with the pin numbers, changed the speed to 9600 and I think that was all (I will try and attach the file but I'm new here so it might not let me). Anyway, I flashed my Teensy++ 2.0 using ArduinoIDE 1.0

Then I ran avrdude from the command line: /home/roger/arduino-1.0/hardware/tools/avrdude -C/home/roger/arduino-1.0/hardware/tools/avrdude.conf -c stk500v1 -v -v -v -v -pattiny85 -P/dev/ttyUSB000 -b9600 -Uflash:w:/tmp/build4483866087774593940.tmp/BlinkAttiny85.cpp.hex:i

That gave me a successful flash. This is in my log:

Reading | ################################################# | 98% 3.03savrdude: Send: U [55] . [e0] . [03] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [18] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [0b] . [be] . [0f] . [90] . [0f] . [be] . [0f] . [90] . [1f] . [90] . [18] . [95] . [f8] . [94] . [ff] . [cf] . [00] . [e1] . [00] . [00] . [00] . [00] . [08] . [00] avrdude: Recv: . [10] Reading | ################################################## | 100% 3.11s

avrdude: verifying ... avrdude: 2008 bytes of flash verified ....

The blinky program doesn't seem to be running in the ATTiny yet but at least I have some reason to think it is loaded.

Dumping the contents of the ATtiny using -Uflash:r:/tmp/hexdump.hex:i generates a 4.8k file which is encouraging. Note that unlike various circuits around the web I did not connect RESET to VCC through a resistor or capacitor. I wired it as shown above (ie with SS connected to Pin 1 on the ATTiny and nowhere else).

My attempt at this

Hi, thanks for all the information!

I used this post and some other sources to make a working programmer for some atmega8l's i had, a few months ago. So I had the thing working, on my breadboard until today, when I finally soldered it up. Already haven forgotten what I did, I decided to document what I ended up with, for myself if nothing else.. Remembering how much I had to trawl the internets to get it working myself.

So here's what I have - hope this helps someone having the same problems as me..

http://folk.uio.no/buzh/Arduino/TeensyISP/

Cheers, Andreas