Ir al contenido principal

Duplicating/cloning an arduino chip using an "Arduino as ISP" and avrdude

So today I had to write several ATtiny85 with a small silly program I wrote years ago to control LED lighting via PWN, but the source was nowhere to be found. I could rewrite it in an afternoon, but my arduino is kind of rusty so I decided to clone an already written ATtiny85 I had around using my Arduino as ISP bought from CT3 I used for projects that didn't need a full arduino board.

Requirements:

  • An Arduino as ISP board (not necessarily the one I use)
  • avrdude installed

Some of the actions you'll run might need root permission if you've not configured serial access for your user, or if you have a newer kernel that controls access to dmesg.

First, I connect my Arduino as ISP and check the port it's been assigned:

~# dmesg|tail -n 10
[  179.219531] usb 2-3.4: reset high-speed USB device number 6 using xhci_hcd
[ 4137.875481] usb 9-4: new full-speed USB device number 2 using ohci-pci
[ 4138.064654] usb 9-4: New USB device found, idVendor=2a03, idProduct=0043
[ 4138.064661] usb 9-4: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[ 4138.064665] usb 9-4: Product: Arduino Uno
[ 4138.064669] usb 9-4: Manufacturer: Arduino Srl
[ 4138.064673] usb 9-4: SerialNumber: 85439303333351E02292
[ 4138.102738] cdc_acm 9-4:1.0: ttyACM0: USB ACM device
[ 4138.103861] usbcore: registered new interface driver cdc_acm
[ 4138.103865] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

So, ttyACM0, fine!

Then, we put the chip we wanna read on our ISP and read it with avrdude:

~# avrdude -p t85 -P /dev/ttyACM0 -c avrisp -b 19200 -U flash:r:flash.bin:r
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e930b (probably t85)
avrdude: reading flash memory:
Reading | ################################################## | 100% 5.89s
avrdude: writing output file "flash.bin"
avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)
avrdude done.  Thank you.

Sounds about right! We've read the chip and written its contents to flash.bin. Let's swap the chip for the new empty one and write it:

~# avrdude -p t85 -P /dev/ttyACM0 -c avrisp -b 19200 -U flash:w:flash.bin
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e930b (probably t85)
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: reading input file "flash.bin"
         avrdude: input file flash.bin auto detected as raw binary
         avrdude: writing flash (1280 bytes):
         Writing | ################################################## | 100% 1.83s
         avrdude: 1280 bytes of flash written
         avrdude: verifying flash memory against flash.bin:
         avrdude: load data flash data from input file flash.bin:
         avrdude: input file flash.bin auto detected as raw binary
         avrdude: input file flash.bin contains 1280 bytes
         avrdude: reading on-chip flash data:
         Reading | ################################################## | 100% 0.93s
         avrdude: verifying ...
         avrdude: 1280 bytes of flash verified
         avrdude: safemode: Fuses OK (E:FF, H:DF, L:62)
         avrdude done.  Thank you.

Great! You're good to go! :D