Skip to content

Installation

kolban edited this page Dec 24, 2015 · 10 revisions

Our goal is to end up with an Arduino IDE environment into which we can enter or load sketches, compile them and then run them on an instance of a Raspberry Pi. We are currently assuming that you have access to a PC upon which you are running the Arduino IDE. In time, we will support Windows and Mac but for just now, we will assume just a Linux based PC (or a guest Linux running on some other operating system). We are also assuming that your Pi is network connected to your PC.

The configuration of our story will come in two parts. There is configuration to be done on the PC and there is configuration to be done on the Pi. Here is the list of logical steps we will be performing and then we will break those down into more detailed steps:

####On the PC

  1. Install the latest Arduino IDE.
  2. Configure the IDE to know about a new board type called "RaspberryPI"
  3. Download and install an ARM cross compiler tool-chain used to compile Arduino sketches on the PC for execution on the Pi

####On the Pi

  1. Configure the Pi to accept the application developed and compiled on the remote PC over the network.

####Install the latest Arduino IDE In this step you need to install the latest Arduino IDE. This can be freely downloaded from the Arduino website. Since we are illustrating Linux here, download one of either the 32 bit or 64 bit Linux variants. I am going to assume the 64 bit version. At the time of writing, the download arrived as a single file called arduino-1.6.7-linux64.tar.xz. Our goal is to install our Arduino IDE into the directory /usr/local. Now we execute the command:

$ sudo tar -xvf arduino-1.6.7-linux64.tar.xz --directory /usr/local

The result will be a new directory called /usr/local/arduino-1.6.7. This is the Arduino install home directory. It is within there that you will find the program called arduino which, if started, would launch the Arduino IDE. However, we have more work yet to do.


####Configure the IDE to know about a new board type called "RaspberryPI" Change to the Arduino IDE home directory (/usr/local/arduino-1.6.7) and then into the hardware sub-directory. It is here that information about different platforms that the IDE can target is located. From there, create a new folder called RaspberryPi.

$ sudo mkdir RaspberryPi

Change into that directory.

$ cd RaspberryPi
$ pwd
/usr/local/arduino-1.6.7/hardware/RaspberryPi
$

Now we need to install the files necessary for building Pi applications. We will use the git command to download the latest materials from the Internet.

$ sudo git clone https://github.com/me-no-dev/RasPiArduino piduino

The result will be a new directory called piduino. We want to change into that directory.

$ cd piduino

We will find a number of files that start with platform.txt.

$ ls platform.txt*
platform.txt  platform.txt.arm-linux-gnueabihf  platform.txt.arm-none-linux-gnueabi
$

Care is needed here. The platform.txt is the Arduino IDE configuration file used to define how the IDE will build the application. Our eventual goal is to automate this step but for now, we need to choose one of these files and make it the one that will actually be used. The one for our story is called platform.txt.arm-linux-gnueabihf. We will rename this to be platform.txt.

$ sudo mv platform.txt.arm-linux-gnueabihf platform.txt

####Install the ARM compiler tool-chain A standard C/C++ compiler on an Intel based Linux PC doesn't know how to compile to generate ARM executable code that will run on a Pi. As such, we need to download the set of tools that run on an Intel Linux machine but generate ARM code. Fortunately, the good folks over at Raspberry Pi have packaged these tools for us. The repository for the tools can be found on Github. We recommend creating a directory at /user/local/dev and cloning the repository there.

$ sudo mkdir /usr/local/dev
$ cd /usr/local/dev
$ git clone https://github.com/raspberrypi/tools
...
$

Our last step on the PC is to associate the new tool-chain with the tools to be used by the Arduino IDE. We do this by creating a link between the Arduino IDE directories and the newly extracted tools.

Change directory to:

$ cd /usr/local/arduino-1.6.7/hardware/RaspberryPi/piduino/tools

Now create a symbolic link from arm-linux-gnueabihf to /usr/local/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64

$ sudo ln -s /usr/local/dev/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64 arm-linux-gnueabihf
$

Now we can move on to the Pi configuration.

####Configure the Pi First we open a terminal window onto the Pi.

Next we need to download a temporary copy of the RasPiArduino project. We will do this in /tmp.

$ cd /tmp
$ sudo git clone https://github.com/me-no-dev/RasPiArduino
...
$

Next we change into the extracted project's tools directory:

$ cd /tmp/RasPiArduino/tools

We are now going to configure the avahi subsystem to know about a new Arduino based service. This subsystem knows how to publish information over the LAN via a broadcast mechanism. This will allow the Arduino IDE to dynamically locate the Pis on which the Arduino sketches can run.

$ sudo cp arduino.service /etc/avahi/services/arduino.service
$ sudo service avahi-daemon restart

Next we need to install some tools into the path:

$ sudo cp /tmp/RasPiArduino/tools/arpi_bins /usr/local/bin
$ sudo ln -s /usr/local/bin/run-avrdude /usr/bin/run-avrdude

And finally, the telnet package is also a pre-requsite.

$ sudo apt-get install telnet

When the deployment from the Arduino IDE executes, we will be prompted for the root password of the root user on the Pi. If you don't know that password, reset it now.

We are now finished with the temporary extraction of the RasPiArduino project and can delete it.

$ sudo rm -rf /tmp/RasPiArduino

###Testing the installation On the PC, change to the /usr/local/bin/arduino-1.6.7 directory and start arduino. The Arduino IDE will start. From the Tools menu, select Board -> RaspberryPi or Board -> RaspberryPi B+/2. From the Tools menu you should also be able to find your Pi listed.

$ arduino

Tools menu

Now we need a sketch to test. An example would be:

void setup() {
  Console.print("Hello from RasPi\n");
}

void loop() {
  Console.print(millis());
  Console.print("\n");
  delay(1000);
}

This sketch says hello at the start and then logs the time since Pi boot to the console every second.

It is assumed that you are familiar with using the Arduino IDE with Arduino boards so no further instructions will be supplied on writing sketches or using the general features of the Arduino IDE. When you verify the sketch, the result should be Done compiling. Next you can test the Upload feature. This will make a network request to the Pi, copy the compiled application and start it running. You will get a message back saying Sketch Started. If you now run the Serial Monitor, a connection will be made to the Pi and you will see the output from the running sketch.

If the sketch output is not being sent to the Serial Monitor, its output can be found in /run/sketch.log on the Pi. This file can be tailed to follow the progress.


###Copying the executable When you have performed your testing and wish to get a stand-alone executable for running on the Pi without an IDE being present, you can execute the Sketch > Export compiled Binary menu command from the IDE. This will create a file called <sketch>.ino.<piType>.bin in the same directory where you saved the sketch. This file is a Pi native executable. If you copy that to the Pi (eg. using FTP or other file transfer technique) then you can run it as you desire.


###Problem reporting and Troubleshooting It is still very early days in the project however we are very interested to hear about problems. The best way to report a problem is to create an issue in Github against the project.

Depending on the nature of the problem, if we have seen common patterns of such and while we work upon a fix, here are some tests and circumventions.

####Switch on full diagnostics If there are problems with the IDE compiling or uploading, switch on full logs of these aspects from within the File > Preferences dialog. Within there you will find a couple of check boxes on the line labeled Show verbose output during.... Select both boxes and re-run the task. Include the output in any problem reports as needed.

####No Port entry If under the Tools > Port menu, no Pi is listed but yet you believe that your Pi is running fine and on the network, on the PC run avahi-browse -a and look for a service called _arduino._tcp. If that is not present, that may mean that your Pi can not be found on the broadcast network.

Clone this wiki locally