1. Go to https://www.raspberrypi.org/downloads/ and download the latest Raspberry OS – Raspbian Stretch. Install it to your Raspberry (either by using the NOOBS installer, or by installing it to your SD card directly).
2. RasPiArduino framework requires root permissions to run, and it is a good idea to have them protected by a strong password. You can skip this step if you already set your root password during the system setup. Open the Raspberry terminal and type the command
You are now logged in as root. Set the password with command
and confirm the password by typing it again when prompted.
3. Optional, but highly recommended step. The rest of this setup is done in Raspberry terminal. To make things easier, I suggest using SSH to control the Raspberry terminal from your PC over the local network. Otherwise, you will have to keep another keyboard and a monitor on your desk which is quite inconvenient.
Setting up SSH on Raspberry is very simple, just follow this short guide here: https://www.raspberrypi.org/documentation/remote-access/ssh/.
Once you have finished that, you will need some sort of SSH terminal program on your PC. The one I use is called MobaXterm; it is free for personal use and very easy to control. It also supports for SFTP (SSH File Transfer Protocol), which allows you to move files to your Raspberry by just dragging and dropping them. You also have to force root to enter password when logging in through SSH. To do that, use the following command
sed -i “s/PermitRootLogin without-password/PermitRootLogin yes/” /etc/ssh/sshd_config
4. Now you have to disable Serial Console on boot. Open the file /boot/cmdline.txt and change its content to
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
5. Next step is to disable Serial TTY entirely by using the command
systemctl disable serial-getty@ttyAMA0
6. Now you have to disable loading the kernel sound module. To do that, use the command
sed -i “s/dtparam=audio=on/#dtparam=audio=on/” /boot/config.txt
7. Optional step. You can set up avahi service to allow you to upload Arduino sketches directly from Arduino IDE, as if you were programming an ordinary Arduino board. Open the file /etc/avahi/services/arduino.service (or create it, if it doesn’t exist) and copy the following text into it:
<?xml version=”1.0″ standalone=’no’?><!–*-nxml-*–>
<!DOCTYPE service-group SYSTEM “avahi-service.dtd”>
Once that is done, you have to restart the avahi service by using
service avahi-daemon restart
8. Install telnet and git. The easiest way to do that from terminal is to use the package manager. First, make sure the package list is up to date.
Then, install telnet and git.
apt-get install telnet git
9. Clone the RasPiArduino framework repository into into your Raspberry.
git clone https://github.com/me-no-dev/RasPiArduino.git piduino
Once it is cloned, make all the important files executable.
chmod +x piduino/tools/arpi_bins/*
Then, copy them into user directory.
cp piduino/tools/arpi_bins/* /usr/local/bin
We don’t need the rest of the RasPiArduino framework repository, so you can remove it.
rm -rf piduino
10. Now you have to create symbolic links for the run-avrdude script, which is one of the RasPiArduino files that we copied and made executable in the previous step.
ln -s /usr/local/bin/run-avrdude /usr/bin/run-avrdude
11. Optional step. You can synchronize the time and make the sketch start on boot. First, install NTP (Network Time Protocol) utilities.
apt-get install ntpdate
Next, open the file /etc/rc.local and change its content to
_IP=\$(hostname -I) || true if [ “\$_IP” ]; then
printf “My IP address is %s\n” “\$_IP”
# Sync Time
ntpdate-debian -u > /dev/null
# Start Sketch
/usr/local/bin/run-sketch > /dev/null
12. All done! You can now reboot your Raspberry Pi. If everything went successfully, you will be able to connect to your Raspberry from Arduino IDE. Select the correct board (RaspberryPI B+/2) and the correct port (the local IP address of your Raspberry).
If you followed the above steps, your Raspberry should now be ready to be programmed from Arduino IDE. There’s just one small detail missing. The core of Arduino function is interaction with the outside world using its various digital and analog inputs and outputs. Raspberry has the GPIO header, and in the following picture, you can see the mapping and the functions of all the different pins. The number in RasPiArduino Pin # column corresponds to the GPIO pin number, and it is the number you will use in the sketches to reference the pin.
Note that Raspberry Pi has only 4 pins with PWM output and no pins that can read analog voltage! Also, unlike most Arduino boards, Raspberry runs on 3.3V logic – digital 1 is represented by 3.3 V signal. The Raspberry GPIO pins are not 5V tolerant! If you apply 5V directly to them, there’s a good chance you will destroy your Raspberry Pi!