furrysalamander
Posts: 20
Joined: Wed Jan 02, 2013 12:12 am

Can somebody explain how to program an AVR with Raspberry Pi

Wed Jan 02, 2013 12:17 am

I want to program the attiny in the tv-b gone using my raspberry pi. I need to add projector codes to the TV codes that already been compiled. I have seen people program AVR's before, and I was wondering if someone could explain it to me step-by-step.



furrysalamander
Posts: 20
Joined: Wed Jan 02, 2013 12:12 am

Re: Can somebody explain how to program an AVR with Raspberr

Wed Jan 02, 2013 10:36 pm

Umm, ya, I think so. In order to use a gertboard do you have to program an onboard avr, or is this using a gertboard to program it? I'm still a little bit confused.

User avatar
MrBunsy
Posts: 185
Joined: Mon Feb 20, 2012 1:48 pm
Location: Southampton, UK
Contact: Website

Re: Can somebody explain how to program an AVR with Raspberr

Wed Jan 02, 2013 11:46 pm

That thread gives instructions on how to use the Raspberry Pi itself as an AVR programmer, using the GPIO, for the Gertboard. There's no reason why the same instructions couldn't be re-used to programme any old AVR, so long as you connect up the right pins.

Alternatively you could go down the more common route and use a USB programmer or a Dragon, although I've no idea if the Dragon is usable on the Pi.

furrysalamander
Posts: 20
Joined: Wed Jan 02, 2013 12:12 am

Re: Can somebody explain how to program an AVR with Raspberr

Wed Jan 02, 2013 11:49 pm

Hrm... Ideally what I want is to program right from the GPIO, but I'm a little confused by the article. Does anybody have a pinout with step by step instructions? I just got my pi, and I haven't used linux in over a year :)

User avatar
MrBunsy
Posts: 185
Joined: Mon Feb 20, 2012 1:48 pm
Location: Southampton, UK
Contact: Website

Re: Can somebody explain how to program an AVR with Raspberr

Thu Jan 03, 2013 10:00 am

I've found a better one - http://blog.stevemarple.co.uk/2012/07/a ... using.html Although I personally wouldn't bother with the buffer, provided you're careful and always check your wiring before turning anything on.

I've not programmed an AVR from a Pi before so I couldn't give guaranteed instructions, but what you'll need to do is link up the SPI GPIO pins on the Pi to the SPI pins on the AVR you want to programme, make sure the AVR is powered at 3.3v, and then run AVRdude with the normal commands.

KenHorse
Posts: 22
Joined: Tue Dec 18, 2012 7:30 pm

Re: Can somebody explain how to program an AVR with Raspberr

Thu Jan 03, 2013 3:54 pm

Could always install a bootloader in the AVR and then you can program it serially. While I don't use an Ardiuno, I use AVRs in my commericial products and have even written a loader program (in Python) to load the AVR. Works great with the Pi :D
Last edited by KenHorse on Thu Jan 03, 2013 3:56 pm, edited 1 time in total.

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Can somebody explain how to program an AVR with Raspberr

Thu Jan 03, 2013 3:55 pm

Hi furrysalamander. Sorry you got confused by my topic. English is not my native language, and it turned into a big wall of text. Basically, the Raspberry Pi is used as the AVR programmer. You don't need a gertboard. It works with any AVR, including the attiny85 for TV-B-Gone.

Install Gordon's avrdude + regular toolchain as in the post. I don't know if you have the ladyada kit, or if you built the circuit from scratch or otherwise. When using the pre-compiled .hex-file from ladyada, you only need Gordon's patched avrdude. The following instructions assume uploading ladyada's precompiled .hex-file. Link: http://www.ladyada.net/make/tvbgone/index.html
EDIT: You can use the Makefile 'as is' to compile your new codes into the hex. If not, edit the paths to avr-gcc. I didn't try on the Raspberry Pi, but it should work without editing.

Make the following connections (Raspberry Pi --> attiny85):
MOSI --> MOSI (PB0)
MISO --> MISO (PB1)
SCLK --> SCK (PB2)
CE0 --> RESET (PB5)
3V3 --> VCC (pin 8) --> but disconnect the battery from the circuit.
GND --> GND (pin 4)

You could edit the Makefile that ladyada provides, but it boils down to this:

The following command burns the fuses for the attiny85. I got that from the Makefile, assuming it's correct. I also think you can leave out the '-B 250' option.

Code: Select all

avrdude -p t85 -c gpio -v -B 250 -u -U lfuse:w:0xfd:m -U hfuse:w:0xdf:m
The following command uploads the hex-file to the attiny85:

Code: Select all

avrdude -p t85 -c gpio -v -U flash:w:tvbgone.hex
Hope that works for you!

furrysalamander
Posts: 20
Joined: Wed Jan 02, 2013 12:12 am

Re: Can somebody explain how to program an AVR with Raspberr

Thu Jan 03, 2013 4:43 pm

Thanks, I think I get it now. :D

furrysalamander
Posts: 20
Joined: Wed Jan 02, 2013 12:12 am

Re: Can somebody explain how to program an AVR with Raspberr

Thu Jan 03, 2013 4:44 pm

I'm going to program this with all the codes for the projectors in my school. >:D

Upshaw
Posts: 2
Joined: Wed Sep 25, 2013 3:28 am

Re: Can somebody explain how to program an AVR with Raspberr

Wed Sep 25, 2013 4:00 am

Panik, I just cant say thanks enough.

I had just finally taken a tiny step into the Arduino-ish world with (ironically enough) another Adafruit product, the Trinket, which is an ATTiny85 with a USB port, a usb/serial bootloader and naught else, and after several succesful experiments with servos, I2c comm, and a couple of other basic blinking light type projects I managed to kill the bootloader.
So while waiting for more Tinys to show up I dug around and found several much more complicated ways to reprogram, then luckily I found this post complete with simplified schematic and link to Gordons GPIO avrdude setup and less than 10 mins later my ATTiny is programmable again.
It still wont talk USB but who cares... I've got GPIO :) (and another 2.5K of flash memory!)

furrysalamander... deviously evil... in my day I just knew which outlet I could short out that would trip the breaker for the one the projector was plugged in to ;)

Thanks again Panik!

L8r,
Upshaw

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Can somebody explain how to program an AVR with Raspberr

Wed Sep 25, 2013 7:45 pm

Thanks for posting your experience Upshaw. Very happy you find it useful. :D

I think you should be able to upload the original bootloader using the same method, to make your Trinket as good as new. Unless of course, as you say, you don't care about a bootloader and use the extra flash memory for stuff that actually matters. Bootloaders are a little bit overrated. ;)
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Upshaw
Posts: 2
Joined: Wed Sep 25, 2013 3:28 am

Re: Can somebody explain how to program an AVR with Raspberr

Thu Sep 26, 2013 1:53 am

That was the first thing I tried (re-burning the boot loader) but it still doesn't quite work.
I've also found in further fiddling around that it's timing is way off. My servo control sketch even with timing tweaks wont go 90 degrees where I actually had the servo pegged either direction at just a little over 180 previously. So I'd guess usb timing is going to be unlikely either. Luckily I received a batch of bare ATTinys today so I can try that sketch on one of them and see if it's better.
And now I don't have to *build* a programmer... it's just a few jumpers on my RasPi header. :)

How did your TV Be Gone reprogramming go furrysalamander? Any luck?

Return to “Advanced users”