Raspberry Pi + Gertboard + Arduino IDE

Hey guys, lately I’ve been playing with a Gertboard connected to a Raspberry Pi and I’ve noticed it isn’t that easy to setup the necessities to use the full potential of the Raspberry and the atmega chip on the Gertboard. So while surfing the net i stumbled upon some useful info and i wanted to share it with you guys. Only if you want… no need to read it… I am not forcing you… you can stop now… really… it is not a must… just stop now.

Ok let’s get to the good stuff. You should know that the atmega chip can be programmed, through ISP, with the Arduino IDE, after you install the IDE on the raspberry, obviously DAAAH! What is ISP you say? At this point it doesn’t matter, the important thing is that you have it and you can use it aaaaaand, unlike the Arduino UNO chip, you don’t need a bootloader on the atmega to program it via ISP. Well if you program the Arduino via ISP too you still don’t need a bootloader, but… you must be so confused right now. Let me get to the point.

You will need the Raspberry Pi with a SD card with raspbian installed on it and optional, but useful, TightVNC Server. If you need help getting those things on… 😐 … well then google them and come back later, this text will still be here.  After you got all this just go over to Gordon’s website: https://projects.drogon.net/raspberry-pi/gertboard/ and follow the tutorials over there for installing the Arduino IDE and setting up the atmega. Also the Gertboard Manual it’s a very useful resource.

After you setup everything you might want to develop a piece of software on the Pi to communicate with the atmega through serial so i recommend installing wiringPi on the Pi (DAAH!). And if you want to use the SoftwareSerial library on the Gertboard atmega you should modify a header file from the library to get it to work with the chip frequency, that is, surprise, 12MHz. Yeah, 12MHz. So we have 8MHz without an external oscilator, we have 16MHz with an external oscilator and we have 20MHz the max power of the atmega, with a 20MHz external oscilator again. But 12MHz??? Yeah, that’s because it runs at 3.3V and that’s the max frequency it can run at on 3.3V and then the interfacing with the Pi is easier cus the Pi GPIO’s run at 3.3V.

So in order to use the SoftwareSerial library go to /usr/share/arduino/libraries/SoftwareSerial/ and open up SoftwareSerial.cpp. Now after line 121 add the following code:

#elif F_CPU == 12000000

static const DELAY_TABLE PROGMEM table[] =
// baud rxcenter rxintra rxstop tx
{ 115200, 1, 11, 11, 8, },
{ 57600, 6, 26, 26, 23, },
{ 38400, 14, 41, 42, 39, },
{ 31250, 19, 51, 52, 49, },
{ 28800, 23, 56, 56, 53, },
{ 19200, 37, 86, 86, 83, },
{ 14400, 52, 116, 116, 113, },
{ 9600, 82, 175, 175, 173, },
{ 4800, 172, 354, 354, 351, },
{ 2400, 350, 711, 711, 708, },
{ 1200, 707, 1425, 1425, 1422, },
{ 300, 2850, 5711, 5711, 5708, },


Now just save the file and you can use the library without getting the wrong frequency error. Well this is it for now, you can now use serial sensors on the atmega and communicate with the Pi over serial for data gathering and stuff like that. Awesome, right?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s