Before we can start to program the ATmega, we need to initialise the chip. The chip itself needs to be told about various parameters such as it’s clock speed, how much flash to reserve for the bootloader (none in our case) and so on.
This is known as “programming the fuses”.
The first thing to do is to connect the Gertboard to your Raspberry Pi and install 4 jumper wires from the Pi’s GPIO to the ATmegas ISP port. The manual has a much better picture than my photos show below, however:
The wires to connect up are as follows:
- GPIO pin 8 -> ISP pin 5 (RESET)
- GPIO pin 9 -> ISP pin 1 (MISO)
- GPIO pin 10 -> ISP pin 4 (MOSI)
- GPIO pin 11 -> ISP pin 3 (SCLK)
The obvious down-side of doing it this way is that you can’t use the Raspberry Pi’s SPI interface when developing code for the ATmega. Hopefully this will not be an issue.
Some photos to help visualise the connections:
This is an overall picture of the Gertboard with the GPIO ribbon cable removed so you can see what’s happening.
This is a close-up of the Raspberry Pi’s GPIO side. The 4 wires are Red (GPIO 11; SCLK), Green (10; MOSI), White (9; MISO) and Yellow (8; RESET) The two photos are taken from each side of the board. You may have to remove the 2-pin jumpers from the Gertboard to make the connections.
This is the other end of the wires – White is pin 1 (MISO), Red is pin 3 (SCLK), Yellow is pin 5 (RESET) and Green is on pin 4 (MOSI) Note that there are 2 unused pins on this connector, the top and bottom pins on the right-hand side. Please do not connect to these pins – they are connected to +3.3v and 0v respectively.
Another view of the above. Ignore the additional white wire on the right-hand side…
Once that’s done, connect the Gertboard to the Pi and power up. Once Linux has booted on the Pi, then run the avrsetup command.
avrsetup
You will be propmpted for the type of ATmega microcontroller; 1 for an ATmega 328p or 2 for the ATmega168.
If this command works OK, you should see the following:
Initialising a new ATmega microcontroller for use with the Gertboard. Make sure there is a new ATmega chip plugged in, and press .. 1 for an ATmega328p or 2 for an ATmega168: 1 Initialising an ATmega328p ... Looks all OK - Happy ATmega programming!
And that’s it. You can now run-up the ardunio IDE and start to use it to send code into the ATmega microcontroller.
Hi Gordon,
A short note of feedback for you. I’ve literally just tried this out on my Gertboard (almost complete – waiting on an MCP4802). I can confirm it works fine – I’ve run Blink and Button using the Arduino IDE – Boom!
So – thank you for all your work. It is appreciated.
PS A note for those running the Arduino IDE on Raspberry Pi: Before uploading a sketch the first time you will need to select the programmer to be RaspberryPi GPIO under the “Tools” / “Programmer” menu.
Glad its all going!
-Gordon
Ref: Last Post
Please ignore the PS..
DOH! – I’ve just seen your page “Using Arduino IDE with the Gertboard”
Excellent Gordon. Well done and thank you. That all worked a treat.
Alex
Thanks,
John
Brilliant Gordon, thanks. All working well.
Hi Gordon,
Thanks for your stunnig help with gertboard and raspberry-pi but I get this error when I try to run arduino IDE after I have followed all the steps with no problems at all:
pi@raspberrypi ~ $ arduino
/usr/lib/jvm/java-6-openjdk-armhf/jre/lib/rt.jar: invalid LOC header (bad signature)
Exception in thread “main” java.lang.NoClassDefFoundError: sun/misc/ExtensionDependency
at sun.misc.URLClassPath$JarLoader.parseExtensionsDependencies(URLClassPath.java:934)
at sun.misc.URLClassPath$JarLoader.getClassPath(URLClassPath.java:914)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:317)
at sun.misc.URLClassPath.getResource(URLClassPath.java:184)
at java.net.URLClassLoader$1.run(URLClassLoader.java:209)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at java.lang.ClassLoader.loadClass(ClassLoader.java:314)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: processing.app.Base. Program will exit.
It seems a java problem…
I hope you can help me…
Thank you very much again
IT does seem like a Java problem, but it’s not one I’ve seen myself…
I’d go through the usual update procedures:
sudo apt-get update
sudo apt-get upgrade
then remove and re-install the arudino ide:
sudo apt-get purge arduino
sudo apt-get install arduino
and see if that makes any differnece..
-Gordon
Thank you very much for your quick answer Gordon. I am very gratefull.
I was the hole Monday evening trying to upgrade, update, remove, purge and so forth… But It was imposible to find out the solution. Finally I decided to make a new clean installation of Raspbian in my SD and everything works perfect!!
Great job Gordon!
PS. Feedback: I actually login Rasperry-pi via ssh. I’m afraid of arduino IDE is a bit slow due to the JVM requirements. Everything works much more smoothly ir you are connected directy to a TV without ssh or VNC…
-Sergio
Yes, it is a little slow. I normally program ATmegas/Arduinos via standard vim & Makefiles – command linestuff, but I’ve not had time to do a write up on that way… one day!
-Gordon
Thanks for the tutorial. I’m hoping it won’t be long before you give some guidance on using the I2C bus as I have an idea that calls for a digital potentiometer and the ones I have are I2C controlled.
Bizarrely, much of the text is missing from the web pages when viewed on the R-Pi with Midori 0.4.3-1 but its all there with iceweasel 10.0.10.
Regards,
Philip
I never did get on with Midori – it’s probably something to do with the theme that my site is using… However, I have used Chromium on my Pi successfully, and that renders most sites really well. Have a look here: http://hexxeh.net/?p=328117859
-Gordon
Gorden,
Does this also set the timers on the atmega? Apparently you need to set the timers on the atmega to their default values.
Can you please give me some guidance on this?
The timers are set by the arduino startup code. As long as you use the Gertboard definition then they’ll be set correctly – as that definition passes in the clock speed of 12MHz into the libraries. If using them yourself, then you’ll need to take that 12MHz into account as the standard Arduno platform is (mostly) 16MHz
-Gordon
I’ve embarked on a project to develop a public domain design for a solar pump supervisor (SPS) based on ATtiny45/85 or ATtiny44/84. I’ve installed your support package and the one from High-Low Tech (http://hlt.media.mit.edu/?p=1695) on my RasPi without difficulty. Thanks to both!
I’ve drafted a SPS sketch and would like to upload via an ISP port on my prototype PCB.
Problem: avrsetup does not support ATtiny. Any suggestions/help would be greatly appreciated.
Further to my previous post … It seems I don’t need to use avrsetup. After following your steps for installing and setting up the Arduino IDE and adding the ATtiny support package from High-Low Tech, I’m able to upload sketches to an ATtiny84 and have set the fuses for 8MHz internal clock via the (unlikely name) Burn Bootloader command of the Arduino IDE. Thank you VERY much. I’m now confident that I need no more than the RasPi to develop the sketches I need to deploy. I will fully disclose deployable (ExpressPCB) PCB designs for ATtiny when they have been tested.
Hi Lloyd,
I’ve been a bit slow on my repies here this week, but glad you’re sorted now!
-Gordon
Hi There
First of all many thanks to Gordon for the great work..
Two days ago I was playing with a thermistor and the ATmega chip everything was working fine, upload and test a couple of programs when I get the following message:
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
I’ve tried to upload a program just with the 4 wires connected only…and nothing.
Tried to setup the chip again and the same message appears.
Use a different SD card and nothing.
Reinstalled ATmega software…no…no.
Tried on a second Pi…same results….
Last thing I tried was to connect ATMega directly to the Raspberry pi GPIO pins and guess what…same message again…
So I’m thinking it’s a problem with the actual ATmegachip, I’ve ordered a replacement so I can check if that is the case.
In the mean time I’d like to know if there any way to reset the ATMega chip.
Thanks
Hi There,
Unlikey the ATmega is ‘bricked’, but you never know…
One thing I have noticed very recentky is that some regular updates of the base Debian installs a new version of the arduino software – and that then overwrites the boards.txt and /etc/avrdude.conf files. My installation script won’t overwrite these if the .bak file exists – something I need to fix soon, so it might be worthwhile seeing if this is the case, and if so, remove the “.bak” files:
sudo rm /usr/share/arduino/hardware/arduino/boards.txt.bak /usr/share/arduino/hardware/arduino/programmers.txt.bak
and then re-run the origianl setup.sh script again.
However, assuming that’s OK, try running the avrsetup script again – programming the fuses multiple times is OK.
My suspicion is that an update has installed new avrdude, config files, etc. which is something I didn’t anticipate at the time.
Let me know if any of this helps..
-Gordon
Same Problem as above.
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Not able to find any solution to this. Can you please help ?
The below command did the trick ..
sudo rm /usr/share/arduino/hardware/arduino/boards.txt.bak /usr/share/arduino/hardware/arduino/programmers.txt.bak
Long live Gordon 🙂 , thanks for helping people like me….
hi, i am trying to do this with my own atmeg8 (8PU), but so far have never got it right. i can’t get the avrsetup to work. besides the gpio interface and the fuse values(which i took from boards.txt) would i need to tweak anything for this chip specifically? avrdude just says device not responding. i have tested all gpios separately and that’s fine. ground and 3v3 are connected as it seems they should be. then the SPI interface is direct to pi. if i connect lights all flash as expected except the MISO. i guess that means it could be a dead chip? i would next test with an arduino board to make sure i am not doing something stupid.
I think you’ll need to check the fuse values for the atmega8, but you can use avrdude to do a sinple chip erase which will at least let you know if it’s working OK.
Try:
avrdude -c gpio -t m8 -e -v
and see what happens …
-Gordon
I also meet problem of initializing avrsetup
trying:
avrdude -c gpio -t m8 -e -v
it shows the following message:
avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is “/etc/avrdude.conf”
User configuration file is “/home/pi/.avrduderc”
User configuration file does not exist or is not a regular file, skipping
avrdude: No AVR part has been specified, use “-p Part”
Valid parts are:
t10 = ATtiny10 [/etc/avrdude.conf:15258]
t8 = ATtiny9 [/etc/avrdude.conf:15218]
t5 = ATtiny5 [/etc/avrdude.conf:15178]
t4 = ATtiny4 [/etc/avrdude.conf:15138]
ucr2 = 32UC3A0512 [/etc/avrdude.conf:15117]
x128a4 = ATXMEGA128A4 [/etc/avrdude.conf:15019]
x64a4 = ATXMEGA64A4 [/etc/avrdude.conf:14922]
x32a4 = ATXMEGA32A4 [/etc/avrdude.conf:14825]
x16a4 = ATXMEGA16A4 [/etc/avrdude.conf:14728]
x256a3b = ATXMEGA256A3B [/etc/avrdude.conf:14631]
x256a3 = ATXMEGA256A3 [/etc/avrdude.conf:14534]
x192a3 = ATXMEGA192A3 [/etc/avrdude.conf:14437]
x128a3 = ATXMEGA128A3 [/etc/avrdude.conf:14340]
x64a3 = ATXMEGA64A3 [/etc/avrdude.conf:14243]
x256a1 = ATXMEGA256A1 [/etc/avrdude.conf:14146]
x192a1 = ATXMEGA192A1 [/etc/avrdude.conf:14049]
x128a1d = ATXMEGA128A1REVD [/etc/avrdude.conf:13952]
x128a1 = ATXMEGA128A1 [/etc/avrdude.conf:13855]
x64a1 = ATXMEGA64A1 [/etc/avrdude.conf:13758]
m6450 = ATMEGA6450 [/etc/avrdude.conf:13569]
m3250 = ATMEGA3250 [/etc/avrdude.conf:13380]
m645 = ATMEGA645 [/etc/avrdude.conf:13191]
m325 = ATMEGA325 [/etc/avrdude.conf:13002]
usb82 = AT90USB82 [/etc/avrdude.conf:12822]
usb162 = AT90USB162 [/etc/avrdude.conf:12638]
usb1287 = AT90USB1287 [/etc/avrdude.conf:12449]
usb1286 = AT90USB1286 [/etc/avrdude.conf:12260]
usb647 = AT90USB647 [/etc/avrdude.conf:12072]
usb646 = AT90USB646 [/etc/avrdude.conf:11883]
m32u4 = ATmega32U4 [/etc/avrdude.conf:11695]
t84 = ATtiny84 [/etc/avrdude.conf:11512]
t44 = ATtiny44 [/etc/avrdude.conf:11330]
t24 = ATtiny24 [/etc/avrdude.conf:11148]
m128rfa1 = ATMEGA128RFA1 [/etc/avrdude.conf:10960]
m2561 = ATMEGA2561 [/etc/avrdude.conf:10766]
m2560 = ATMEGA2560 [/etc/avrdude.conf:10573]
m1281 = ATMEGA1281 [/etc/avrdude.conf:10385]
m1280 = ATMEGA1280 [/etc/avrdude.conf:10196]
m640 = ATMEGA640 [/etc/avrdude.conf:10008]
t85 = ATtiny85 [/etc/avrdude.conf:9827]
t45 = ATtiny45 [/etc/avrdude.conf:9648]
t25 = ATtiny25 [/etc/avrdude.conf:9468]
pwm3b = AT90PWM3B [/etc/avrdude.conf:9287]
pwm2b = AT90PWM2B [/etc/avrdude.conf:9104]
pwm3 = AT90PWM3 [/etc/avrdude.conf:8921]
pwm2 = AT90PWM2 [/etc/avrdude.conf:8737]
t2313 = ATtiny2313 [/etc/avrdude.conf:8550]
m328p = ATMEGA328P [/etc/avrdude.conf:8362]
t88 = attiny88 [/etc/avrdude.conf:8176]
m168 = ATMEGA168 [/etc/avrdude.conf:7988]
m88 = ATMEGA88 [/etc/avrdude.conf:7802]
m48 = ATMEGA48 [/etc/avrdude.conf:7615]
t861 = ATTINY861 [/etc/avrdude.conf:7427]
t461 = ATTINY461 [/etc/avrdude.conf:7238]
t261 = ATTINY261 [/etc/avrdude.conf:7049]
t26 = ATTINY26 [/etc/avrdude.conf:6892]
m8535 = ATMEGA8535 [/etc/avrdude.conf:6734]
m8515 = ATMEGA8515 [/etc/avrdude.conf:6576]
m8 = ATMEGA8 [/etc/avrdude.conf:6415]
m161 = ATMEGA161 [/etc/avrdude.conf:6275]
m32 = ATMEGA32 [/etc/avrdude.conf:6100]
m6490 = ATMEGA6490 [/etc/avrdude.conf:5907]
m649 = ATMEGA649 [/etc/avrdude.conf:5722]
m3290p = ATMEGA3290P [/etc/avrdude.conf:5539]
m3290 = ATMEGA3290 [/etc/avrdude.conf:5354]
m329p = ATMEGA329P [/etc/avrdude.conf:5169]
m329 = ATMEGA329 [/etc/avrdude.conf:4985]
m169 = ATMEGA169 [/etc/avrdude.conf:4805]
m163 = ATMEGA163 [/etc/avrdude.conf:4647]
m162 = ATMEGA162 [/etc/avrdude.conf:4451]
m1284p = ATMEGA1284P [/etc/avrdude.conf:4261]
m644p = ATMEGA644P [/etc/avrdude.conf:4069]
m644 = ATMEGA644 [/etc/avrdude.conf:3879]
m324p = ATMEGA324P [/etc/avrdude.conf:3688]
m164p = ATMEGA164P [/etc/avrdude.conf:3497]
m16 = ATMEGA16 [/etc/avrdude.conf:3319]
c32 = AT90CAN32 [/etc/avrdude.conf:3128]
c64 = AT90CAN64 [/etc/avrdude.conf:2938]
c128 = AT90CAN128 [/etc/avrdude.conf:2748]
m128 = ATMEGA128 [/etc/avrdude.conf:2570]
m64 = ATMEGA64 [/etc/avrdude.conf:2389]
m103 = ATMEGA103 [/etc/avrdude.conf:2249]
8535 = AT90S8535 [/etc/avrdude.conf:2128]
8515 = AT90S8515 [/etc/avrdude.conf:2014]
4434 = AT90S4434 [/etc/avrdude.conf:1931]
4433 = AT90S4433 [/etc/avrdude.conf:1807]
2343 = AT90S2343 [/etc/avrdude.conf:1683]
2333 = AT90S2333 [/etc/avrdude.conf:1555]
2313 = AT90S2313 [/etc/avrdude.conf:1442]
4414 = AT90S4414 [/etc/avrdude.conf:1329]
1200 = AT90S1200 [/etc/avrdude.conf:1214]
t15 = ATtiny15 [/etc/avrdude.conf:1081]
t13 = ATtiny13 [/etc/avrdude.conf:908]
t12 = ATtiny12 [/etc/avrdude.conf:775]
t11 = ATtiny11 [/etc/avrdude.conf:711]
OK. Do read the manual page for it, please.
It looks like I goofed and said -t m8 when it should have been -p m8.
-Gordon
So I resolved the issue. I had used the wrong fuses and “killed” the chip without an external clock. I revived it using the details in this thread:
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=42&t=24759
Command line that I used to program the fuses correctly.
avrdude -vvvv -c gpio -p atmega8 -U lock:w:0x3F:m -U lfuse:w:0xe4:m -U hfuse:w:0xda:m
The boards.txt above also had to be edited correctly to match.
Glad you’re going now.
It just makes the Pi more versatile – combined compiler and programmer in-one!
Just be sure to re-check boards.txt if it stops working after an apt-get update/upgrade operation. If a new Arduino IDE is installed then it will potentially overwrite them.
-Gordon
Hi Gordon
Followed your instructions and am trying to run blink, but I get a verification error on upload at byte 0000 0xc!= 0x00.
I also tried using avrdude -c gpio -p m328p -e -v
which runs, but then returns device signature = 0x000000, Yikes! Invalid device signature.
I’ve tried reconnecting the wires a couple of times and have double checked the config files, but can’t see anything obvious.
Any ideas on something I can try?
Thanks for a great site, a goldmine of Pi stuff!
BBz
If anyone’s read this, sorry for wasting your time!! I must learn to RTFM. Following a similar post elsewhere on this thread I realised that the 3v3 jumper needs to be fitted. I overlooked this in Gert’s manual (where the statement exists plain as day)
Anyway, all sorted
Thx & rgds
BBz
Hi,
Just catching up on this now – glad its sorted now!
-Gordon
well to read the manual is a good idea. But I cannot find anything which tells me where do I have to set a jumper?!
@bob_binz: What do you mean with “3v3 jumper needs to be fitted”. I might have overlooked this statement as well. Somehow.
Curiously I got the same problem, and I am afraid I got the chip briked.
avrdude: Device signature = 0x000000
avrdude: Yikes! Invalid device signature.
I called avrsetup, which worked perfectly:
pi@raspberrypi ~/atmel/init $ avrsetup
Initialising a new ATmega microcontroller for use with the Gertboard.
Make sure there is a new ATmega chip plugged in, and press
.. 1 for an ATmega328p or 2 for an ATmega168: 1
Initialising an ATmega328p …
Looks all OK – Happy ATmega programming!
And tried then to upload blinky.c
pi@raspberrypi ~/atmel/init $ make install
avr-gcc blinky.c -o blinky -Wall -Os -std=gnu99 -mmcu=atmega328p -I.
avr-objcopy -O ihex blinky blinky.hex
rm -f blinky
avrdude -p atmega328p -c gpio -v -U flash:w:blinky.hex
avrdude: Version 5.10, compiled on Jun 18 2012 at 12:38:29
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is “/etc/avrdude.conf”
User configuration file is “/home/pi/.avrduderc”
User configuration file does not exist or is not a regular file, skipping
Using Port : unknown
Using Programmer : gpio
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
———– —- —– —– —- —— —— —- —— —– —– ———
eeprom 65 5 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : GPIO
Description : Use sysfs interface to bitbang GPIO lines
avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude done. Thank you.
make: *** [install] Error 1
Even more distrubing is that avrsetup does not longer work:
avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Any idea or guidance what I can do now?
Kind Regards and Thanks a lot,
Thorsten
Ok, sorry. Found it referenced here:
https://projects.drogon.net/raspberry-pi/gertboard/using-the-arduino-ide/
It’s odd that it somehow seems to work, when the jumper isn’t attached.
Thanks,
Thorsten
Hi Gordon,
Thanks a lot for this helpful information. Anyhow, I am a novice to the Raspberry Pi’s GPIO. I wanted to know if you could explain to me what is the difference between a Pi with a Gertboard, a Pi with an Arduino board, and a Pi by itself, in terms of its GPIO usage capabilities. Thanks a lot
The Pi has 3.3v outputs which some say are easy to damage… The Gertboard buffers the Pi’s outputs, so if you blow up an output on the Gertboard it’s one chip to replace and not the whole Pi. The Gertboard has additional drivers too for higher current and a motor driver, as well as analog input and output chips.
Arduino is a hardware/software combination revolving round the ATmega processor – it’s a microcontroller which doesn’t normally run an operating system. The Gertboard has an ATmega processor and is largely Arduino compatible. The ATmega has analog inputs which the Pi doesn’t, it also has more hardware PWM channels avalable – the Pi only has one.
So the Pi on its own is still very capable – add on the Gertboard for some buffering and additional interfacing and an ATmega.
The Arduino is mostly standalone with more IO capabilities than the Pi has, but it’s also much slower with much less RAM (2KB vs. 512MB)
-Gordon
Great, thanks. This was exactly what I was looking for. Do you know if I use an ADC converter, will I be have analog ports? I am trying to expand its capabilities so I can use a RPi like an Arduino. Thanks a lot for the quick reply.
The ATmega is the same processor as in an Arduino 2009 or Uno, etc. So it has the same analog inputs.
-Gordon
Oh sorry I wasn’t very clear in my question. I meant that what would happen if I used an ADC with a RPi standalone? Would I be able to have analog on the RPi without a gertboard or an Arduino this way? Thanks in advance
Sure. Just wire it up. If you use the same one (or similar) to what’s on the Gertboard, then you can recycle the gertboard driver software I wrote too.
Just remember everything is 3.3v.
-Gordon
Awesome. Thanks for all the info. I know I’ll be coming back to your site! Anyhow, thanks once again.
My apologies, I have another question. Would this ADC be okay? http://www.adafruit.com/products/856. And I’m not sure if its 3.3v, it doesn’t say. Thanks a million.
Yes- it’ll be fine. They even have a tutorial in connecting it up too.
-Gordon
You’re a hero. 🙂
I followed a procedure of installing Arduino IDE, then connected the cables to the pins GP8 – GP11. Not sure about the jumpers on pins GP14 and GP15. Are they needed?
The problem started with avrsetup, it shows no response, no messages on the terminal – nothing.
Why can it be?
avrsetup should print some messages… it’s just a little shell script. The GP14 and 15 jumpers connect the Pi’s serial port to the ATmega’s serial port.
-Gordon
Hi Gordon,
Thanks for all the work you’ve done for us with this. I hope I’m not coming across as ungrateful, but there’s a problem in the avrsetup script. It ignores really bad errors reported by avrdude. I’ve modified my setup so that the avrdude full output is always displayed (as described at http://wiki.yobi.be/wiki/Arduino#Monitoring_avrdude_calls ), and this is is what I saw:
root@raspberrypi:~# avrsetup
Initialising a new ATmega microcontroller for use with the Gertboard.
Make sure there is a new ATmega chip plugged in, and press
.. 1 for an ATmega328p or 2 for an ATmega168: 1
Initialising an ATmega328p …
/usr/bin/avrdude -qq -c gpio -p atmega328p -U lock:w:0x3F:m -U efuse:w:0x07:m -U lfuse:w:0xE7:m -U hfuse:w:0xD9:m
avrdude.orig: AVR device not responding
avrdude.orig: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
Looks all OK – Happy ATmega programming!
Without the mod all I saw was:
root@raspberrypi:~# avrsetup
Initialising a new ATmega microcontroller for use with the Gertboard.
Make sure there is a new ATmega chip plugged in, and press
.. 1 for an ATmega328p or 2 for an ATmega168: 1
Initialising an ATmega328p …
Looks all OK – Happy ATmega programming!
It was quite puzzling until I could see the avrdude output. So I thought I’d let you know that avrsetup was getting fooled.
Cheers,
Laszlo
That whole thing is in the middle of a re-write, so hang in there. Almost considering reverting to serial programing due to the issues some people have (e.g. when leaving stuff connected to hte ATmega then trying to re-program…)
-Gordon
Hi Gordon,
Thank you for putting all of this together. I really appreciate your efforts.
Kind Regards,
Nathan
Thanks for all the effort you’ve put into this project. I am now down to initializing the ATmega chip. Every thing has gone well so far but now I can’t figure out which chip is installed on my gertboard. There isn’t marking number one on the chip and I find no documentation stating which model it is. Any help would be greatly appreciated.
It’s an ATmega328p
(or should be!)
-Gordon
Here I am again, with new developments. With a very bright light at just the right angle and a very strong magnifying glass I was able to identify my ATmega chip as a 328p. It took a lot of patience (with which I am not overly equipped) and persistence (which I do possess), but I finally was able to read it. Thanks for any effort you have put into responding to my original post.
I had this all up & running – nice easy setup, worked first go, thank you! – but on attempting to load a second program, I get a verify error. Have powered it all down & removed all extra wires, re-run the scripts – verify error..
I have changed -qq to -q in the avrsetup script, avrdude gets good responses when setting fuses.
Any ideas on what may be happening here?
You may have something connected to the lines on the ATmega that the Pi is using to program it with.
-Gordon
Hi Gordon, thanks a lot for this tutorial!
/usr/bin/avrdude -q -V -p atmega328p -C /etc/avrdude.conf -c gpio -b 57600 -P /dev/ttyS1 \
-U flash:w:build-cli/blink.hex:i
avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e950f
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 “build-cli/blink.hex”
avrdude: writing flash (2130 bytes):
avrdude: 2130 bytes of flash written
avrdude: safemode: Fuses OK
avrdude done. Thank you.
No error at all, compile and upload seems find, but my led just wont blink!
Any idea why? I tried using Arduino IDE it went perfectly fine, but I just want the liberty of compiling and uploading stuff via command line like the above. Please help anyone?
The device is /dev/ttyAMA0 not /dev/ttyS1.
However this will only work if the ATmega has a serial bootloader burned into it. Try dropping the -P /dev/ttyS1 from the command.
Then run this: gpio reset
after the upload.
-Gordon
Hi Gordon,
I have just a stupid question from my side regarding the clock for the ATMega328p and the instruction Serial.begin(115200);
On my Gertboard a have a 12MHz Resonator. When I initialze my interface with Serial.begin(115200);
then I can also measure a Communication with 115,2kBaud…so far.
But what happens if I take now this programmed ATmega328p to a separate PCB supplied with 5V instead of 3v3
and a 16MHz resonator instead of 12MHz ?
From my point of view I should than measure a Baudrate of 16/12*115,2 = 153,3
Should I then on my Gertboard – in order to have on my separate PCB a Baudrate of 115,2kBaud- write Serial.begin(86400).
This would bring me than on my seprate PCB then to the expected 115,2kBaud.
Thanks
You need to tell the Arduino IDE that the clock is 16MHz – the baud rate calculation relies on the CPU Frequency. You need to find boards.txt and edit that.
-Gordon
First off, a *huge* thanks for getting this stuff together, Gordon!
I have been happily programming ATMegas for a bit now, starting with your Gertboard route, and have managed to get things working programming via the Pi with the ATMega328p on a standalone breadboard with 12MHz crystal etc.
I’m doing some relatively heavy-duty stuff now and am trying out some alternative methods of programming (eg using avrisp mk ii) and as part of this was trying to understand everything in your boards.txt entry for the Gertboard/SPI route.
I see a number of lines with gert328.bootloader.* – but I thought that by going through SPI we bypass bootloading and just write direct?
So I wondered if I could ask what role (if any) do the gert328.bootloader.* lines in boards.txt play?
Is this for an alternative bootloader based approach to the SPI programming route? I see the high fuse is 0xDA, differing from the avrsetup entry of 0XD9 – setting BOOTSZ to 01 (1024w) – so it looks like some thought’s gone into how much space to set aside.
Thanks again for getting me started on all this, it’s a lot of fun!
The boards.txt file isthe definition for the target board – arduino uno, nano, 2009, etc. so look in it & see:
gert328.upload.using=gpio
gert328.upload.protocol=gpio
that tells the Arduino IDE to use the gpio upload method, and avrdude.conf has the definition for the gpio uploader.
You have the full 32KB of Flash avalable to you this way. I am working on some documentation to use a serial uploader though. That may suit some people – it’s actually marginally faster on the Pi too…
-Gordon
Got you – thanks! I would certainly be interested in a serial uploader since I’m looking at SPI applications nowadays (SD cards in particular) so swapping things around SPI is a pain. Will faff around with bootloaders myself in the meantime and see if I can get things going.
Hi Gordon, thanks for this article. I have a question here:
1. Which one is more suitable for a home automation project? Arduino or Gertboard?
I have get two of them yet but how do i connect either one of them to Raspberry Pi? the above mention, “Once that’s done, connect the Gertboard to the Pi and power up.” but how? 🙁 Is there an easy guide on your blog? 🙂
A lot will depend on what you’re connecting up and your own ability. I use Arduino via the USB serial with good results – Gertboard has an ATmega on-board so you can sue that too – I’d only use the Gertboard if it had devices I actually needed though – the ULN2803, or the motor driver (and maybe the analog inputs)
-Gordon
Im using the LXterminal to execute the command but it says command not found. I have the oct 2012 edition gertboard. Please help asap!!!!!!!!
what command?
I just got my Gertboard all hooked up and I placed the jumpers as you said but all the leds are lit and avrsetup is failing with AVR device not responding, initialization failed, rc=-1. Any ideas?
Thank you sir,
It is working!
Thanks Gordon for your excellent tutorial. Everything worked perfectly.
I have a question about timing. Avrsetup programs the low fuse bits to use the external clock source. But, there is no programming that I can see telling the chip the frequency of that clock source. I don’t see how the chip provides the correct timing unless it knows the clock frequency. Am I missing something?
Thanks,
Marty
Code running on the ATmega, and the ATmega chip itself doesn’t “know” what its clock frequency is. You need to tell your code what the frequency is, that way it can set the registers, etc. appropriately (e.g. timers, baud rate, etc.) See the F_CPU define in C/C++ code.
The fuse bits just select internal or external clock, and a divide by 1 or divide by 8. (And for the external clock there are some bits to suggest to the driver what it is – low power crystal,creamic resonator, etc.)
So with an external clock the actual frequency is dictated by the crystal (or ceramic resonator) You just need to know what its speed is – 12MHz on the Gertboard or 16 on the Gertduno.
-Gordon
Gordon
I used the procedures defined above to setup the environment for the Arduino IDE on the PI. It worked immediately and continued to work fine as I implemented the sketches in the Gertboard manual until I loaded the “AnalogReadSerial” sketch. with the minicom monitor. This all worked fin:e as well. But now I cant load any sketches to the board… I get the error:
avrdude: AVR device not responding
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override this check
I get the same error when I run avrsetup. The connections look fine. Any ideas? The ‘AnalogReadSerial’ is still running on the Gertboard ATmega chip
Thanks
It’s probable that the arduino calles the avrdude command without asking it to erase the chip first – try a manual
avrdude -c gpio -e
command first.
-Gordon
I have a GERTBoard Rev 5 and RasPi B, and noticed that the layout of the pins is a little different. Will i still follow the connections listed above:
GPIO pin 8 -> ISP pin 5 (RESET)
GPIO pin 9 -> ISP pin 1 (MISO)
GPIO pin 10 -> ISP pin 4 (MOSI)
GPIO pin 11 -> ISP pin 3 (SCLK)
Also, did the latest release of Raspbian allow for not having to use this connection setup? So, that we might use the SPI pins for future projects?
I meant I have a Gertduino Rev 5..
with the Gertboard/Gertduino installed you really can’t use the SPI pins for your own use. They’re for programming the ATmega and on the Gertboard accessing the A/D and D/A
-Gordon
avrsetup: command not found
Why? I have followed through the all the previous steps…
./avrsetup
-Gordon
Hi!
Gertboard newbie here and still reading into it.
Is my assumption (partially based on the article above) that you always have to use those 4 patchwires to initialize / program the ATmega?
Thus sacrificing 4 GPIO pins?
Is there a direct way to program the ATmega, perhaps without the Arduino IDE, so that I can fully utilize all the GPIO pins?
/Robin
You can unplug the 4 wires after you have programmed the ATmega
And yes, you can use the ATmega without the Arudino IDE.
-Gordon