Setting up the Arduino IDE on Raspbian

 If you have used the Sleepy Pi setup script you DO NOT need to do this. The script has already set this up for you.

The following instructions relate to installation on the standard Raspberry Pi Operating System (OS) Raspbian. Following the principals shown here, it should be possible to apply these same modifications to other Raspberry OS’s.

The Arduino processor on the Sleepy Pi can be programmed directly from the Arduino IDE running on the Raspberry Pi.

The first step is to load the Arduino environment onto the Raspberry Pi. If you haven’t already done so, it’s a good idea to ensure that your Raspbian is up to date by opening up an LXTerminal window and executing the following:

Note the dist-upgrade will ensure that you have the latest versions of RPi.GPIO which will be required later.

Now install the Arduino IDE with:

(click Y to any dependencies)

Setting up the Serial Pins

The Arduino processor on the Sleepy Pi can be programmed directly from the Raspberry Pi using the serial GPIO lines on the RPi and another GPIO line to reset the the Arduino to allow automatic code upload. These pins are:

GPIO 14: TXD

GPIO 15: RXD

GPIO 22: Reset (see next section)

By default Raspbian has exclusive access to the serial pins to output status, debug data and logging in. We need to change that using the following steps.

Step 1: Disable Serial login

Wheezy

Raspbian allows you to login using the serial port. To use the Sleepy Pi we need to disable this. To do this, we need to edit /etc/inittab.

In an LXTerminal window type:

Scroll down the bottom and you will find the lines:

You need to comment the last line out (i.e. disabling it) with a “#” and save it, so that it results in:

Jessie and Raspberry Pi 3

Raspbian Jessie no longer has the /etc/inittab file and replaces it instead with a mechanism called systemd and you use a tool called systemctl to enable / disable services.

In a terminal type the following commands, for all Raspberry Pi’s except Raspberry Pi 3:

Instead, for Raspberry Pi 3:

On Jessie, you also need to enable the serial port in either rasp-config of in /boot/config.txt with:

and add the line:

Step 2. Disable Boot info

When Raspbian boots up it outputs boot information to the serial port and hence streams it to the Sleepy Pi (which is not particularly interested in it). To disable this we need to edit the /boot/cmdline.txt in LXTerminal:

It will look something like:

Delete the “console=serail0,115200″ parts so that you are left with:

This is the file I use:

Step 3. Link the Serial port to the Arduino IDE

NOTE: For Raspberry Pi 3 Omit Step 3 – /dev/ttyS0 is the default mapping not /dev/ttyAMA0 which is used for the Bluetooth.

The Arduino IDE wants to use the /dev/ttyS0 serial port, but we need to use the /dev/ttyAMA0 which is linked to the GPIO. In order to do this we need to create a permanent link that maps AMA0 to S0. To this we need to create a small file. We can do this in LXTerminal by the following sequence:

In the new file that it creates type the following:

Save this file as a new file called “80-sleepypi.rules” to: /etc/udev/rules.d/

This is the one I use:

Setting up the Reset (DTR) pin

The Sleepy Pi Arduino processor reset line in connected to GPIO 22. To automatically upload code from the Arduino IDE we need to pulse this line low to rest the Arduino and enter bootload mode.

On a normal Arduino system connected to a computer via a USB / serial cable the reset line is connected to the DTR line. To replicate this behavior on the Raspberry Pi we need to hack the AVRDude programming software. Dean Mao has detailed a great hack for this. He’s produced a modified version of Avrdude (avrdude-autoreset) and written a piece of python code (autoreset) that runs in the background and pulses the GPIO line when required.

Download the avrdude-rpi files from Github . Select “Download ZIP” file which will download the file into your /home/pidirectory.

NOTE: this is a subtly modified version of the original Dean Mao version so only use this version.

Open up a File Manager window from the bottom toolbar, locate the ZIP file in your /home/Pi directory and right-click and select xarchiver to extract the files to a folder in /home/Pi. These will extract into a folder named “avrdude-rpi-master“.

If you are using a terminal rather than the GUI, you can use the following from the command lines to download and unzip :

Next, copy the files to the appropriate places from a LXTerminal window using the following commands:

This renames your original avrdude, so that you have a backup and can replace it with the new one.

Then link the new avrdude-autoreset to avrdude with the ‘ln” command so that when something calls for avrdude, the new version runs instead.

Adding the Sleepy Pi to the Arduino environment

To enable the Sleepy Pi to be selected from the IDE you need to add a folder and file to your sketchbook. If it is a fresh install and you haven’t yet run the Arduino environment you’ll need to create a sketchbook folder (skip this step if it already exists).

In LXTerminal type:

to create folders “hardware” and “sleepy pi” in your Arduino sketchbook.

Download and copy the boards.txt file to the Sleepy Pi folder.

This file should look like this:

Reboot

And finally reboot your Raspberry Pi to complete and load all our changes. You can use:

Leave a Reply