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:
$ sudo apt-get update
$ sudo apt-get dist-upgrade
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:
$ sudo apt-get install arduino
(click Y to any dependencies)
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: TXDGPIO 15: RXDGPIO 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.
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:
$ sudo nano /etc/inittab
Scroll down the bottom and you will find the lines:
#Spawn a getty on Raspberry Pi Serial line
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
You need to comment the last line out (i.e. disabling it) with a “#” and save it, so that it results in:
#Spawn a getty on Raspberry Pi Serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
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:
$ sudo systemctl stop serial-getty@ttyAMA0.service
$ sudo systemctl disable serial-getty@ttyAMA0.service
Instead, for Raspberry Pi 3 & 4:
$ sudo systemctl stop serial-getty@ttyS0.service
$ sudo systemctl disable serial-getty@ttyS0.service
On Jessie / Stretch, you also need to enable the serial port in either rasp-config of in /boot/config.txt with:
$ sudo nano /boot/config.txt
and add the line:
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:
$ sudo nano /boot/cmdline.txt
It will look something like:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait
Delete the “console=serail0,115200″ parts so that you are left with:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p6 rootfstype=ext4 elevator=deadline rootwait
This is the file I use:
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:
$ sudo nano
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:
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/pi directory.
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 :
sudo unzip master.zip
Next, copy the files to the appropriate places from a LXTerminal window using the following commands:
$ cd ./avrdude-rpi-master/
$ sudo cp autoreset /usr/bin
$ sudo cp avrdude-autoreset /usr/bin
$ sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
This renames your original avrdude, so that you have a backup and can replace it with the new one.
$ sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude
Then link the new avrdude-autoreset to avrdude with the ‘ln” command so that when something calls for avrdude, the new version runs instead.
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:
$ mkdir /home/pi/sketchbook
$ mkdir /home/pi/sketchbook/hardware
$ mkdir /home/pi/sketchbook/hardware/Sleepy_pi
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:
And finally reboot your Raspberry Pi to complete and load all our changes. You can use:
$ sudo reboot
Your email address will not be published. Required fields are marked *