Arduino on the Pi

Posted on January 8, 2013 | Category :All, Pi in the sky ideas | No Comments on Arduino on the Pi

pi_logoplus ArduinoLogo

What a combination. High level Raspberry Pi gui with processing power and Arduino hardware smarts.

Now. How do we make it all work together.

I started with a Raspberry Pi model B 512

I brought an 8MHz 3.3v Arduino ATmega328 with boot loader Complete kit (Check the drop down menu under options) This is a diy clone of the Arduino Uno.

I built the kit on some prototype board. Very simple build.

(Pictures on the way)

The hardware connection from the RPi to the Arduino clone is simple.  Supply the clone with 5v to the Vin pin, 0v to one of the ground pins. Hook a wire up from the Arduino RX pin (D0) to RPi GPIO08 and Arduino TX pin(D1) to RPi GPIO10

Also connect a 0v line from the Rpi (GPIO6) to the Arduino clone Gnd connector.

That’s the hardware. Now for some software setup.

The linux distribution I’m using is the 2012-10-28-wheezy-raspbian available here.

You will need to be root to do most of this. You can either use the sudo command. eg. ‘sudo nano /boot/command.txt’ to edit the command.txt file, or you can become root by entering ‘sudo su’.

This will make you root until you enter exit or reboot the pi.

First. You will need to edit the /boot/command.txt

This is the unedited line from the standard installation.

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

We need to remove any serial port information and make it look like this :-

dwc_otg.lpm_enable=0 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

Edit the last line in /etc/ Add a # symbol in front of the last line

#TO:32:respawn:/sbin/getty -L ttyAMA0 115200 vt100

This will free up the serial port for our use.

Next , add the pi user to the dialout group.

usermod -a -G dialout

Last you need to add a link to the correct serial port because the Arduino environment does not recognise AMA0 as a serial port.

Create a new file

touch /etc/init.d/link_serial

Edit the file and enter the following text


ln -s /dev/ttyAMA0 /dev/ttyS1

Save the file now.  Enter the following command to make the file executable.

CHMOD 755 /etc/init.d/link_serial

Now we need to make sure the file is executed every time the Pi boots.

update-rc.d link_serial defaults

You will get a warning

insserv: warning: script ‘link_serial’ missing LSB tags and overrides

This is not a problem.

To install the Arduino software environment enter the following command.

sudo apt-get install arduino

Reboot you Pi now.

You should now be able to program your Arduino clone via the serial GPIO pins on the Raspberry Pi.

You need to hold the reset button down until the program starts to download. Then release it as it starts. This takes a little practice…..


Comments 0

Leave a Reply

Your email address will not be published. Required fields are marked *


Powered by WordPress 4.9.4 | Theme MxS2