Raspberry Pi-GertDuino Serial

Using a serial connection between the Raspberry Pi and the GertDuino to get data from the program running on the ATmega328, processing the data on the Pi and then sending back control signals to the ATmega328 can result in a much more powerful system than just running a stand-alone program on the ATmega328. Here's a very simple demo that uses a Python program running on the Pi to toggle the leds on the GertDuino by telling the program running on the ATmega328 which led to toggle. The ATmega328 then sends back the current state of the led.

First, we need to edit a couple of files to prevent Linux from using the serial port
sudo nano /boot/cmdline.txt

The file will look something like this:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Remove all items in red so that the file looks like this:
dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Save the file and then edit the next file.
sudo nano /etc/inittab

Look for:
#Spawn a getty on Raspberry Pi serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

You need to comment out the second line so that it looks like:
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Shut down the Pi and make sure that the jumpers are in place for programming the ATmega328 as shown on page 6 of the user manual. Add the serial jumpers to connect the Pi and the ATmega328 as shown on page 5 of the user manual and restart the Pi.
Here's a compact way of installing the jumpers.

I couldn't get the pySerial module working under Python 3.2 so the program is written in Python 2.7. You need to install pySerial for Python 2.7.
sudo apt-get install python-serial

Download the Python and Arduino programs.

Run the Python program:
chmod +x PiGertduinoSerial.py
./PiGertduinoSerial.py

Run the Arduino IDE and open the Arduino program and upload it.

You should now be able to toggle any of the leds by entering a number between 0 and 5.

Happy computing.