Uploading code to the Arduino via Raspberry Pi SSH - FAR-Lab/Developing-and-Designing-Interactive-Devices GitHub Wiki
If you want to update your code remotely you can use the Raspberry Pi to compile and upload the code to the Arduino. The InteractionEngine has already all tools installed that are necessary to do this from an RPI.
- Navigate to the sketchbook folder located in home or
~
.
cd ~/sketchbook/
- Create a folder for your project in the sketchbook folder and change directory to it.
mkdir yourFolderName/
cd yourFolderName/
- Copy over the template
makefile
from the blink example with thecp
command.
cp ~/sketchbook/blink/makefile makefile
- Create a new
.ino
arduino code file, or upload the file from somewhere else. In this example, we are trying to upload and install the example for the old Nokia screens available from Adafruit. To copy the example file directly from Github, find the .ino file in the GitHub page, and use thewget
command to download the raw file into the folder you created.
wget https://raw.githubusercontent.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library/master/examples/pcdtest/pcdtest.ino
- Now we need to download and install the required libraries that are used by the Arduino board to communicate with the display. At the top of the Arduino-code file (pcdtest.ino) we can see that we require three additional libraries. This is notated in the Arduino with the
#include
command. The three libraries are:
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
-
SPI
is a library that is always included with the Arduino development environment(IDE) so we don't need to worry about it for now.
The other two libraries are not standard but are easily found on Google or GitHub.
-
Adafruit_GFX
library is available from GitHub from Adafruit. It is a basic graphics library. -
Adafruit_PCD8544
Is the actual 'device driver' for the display. Again theCode for that is on Github
Most common libraries for Arduino will be available over GitHub. So these installation instructions should apply independently of the library you are trying to install.
- Let's make a new libraries folder inside the sketchbook folder.
cd ~/sketchbook/
mkdir libraries
cd libraries
- Now that we created and moved the new libraries folder we can download the libraries with
git clone
git clone https://github.com/adafruit/Adafruit-GFX-Library
git clone https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library
- After downloading we need to rename the folder. We need to remove the "-Library" and "-Nokia-5110-LCD-library" part respectively. We do this by
moving
the folder to its new name like so:
mv Adafruit-GFX-Library Adafruit-GFX
mv Adafruit-PCD8544-Nokia-5110-LCD-library Adafruit-PCD8544
Typically you can find the desired folder name in the installation instructions that come with the packages you are trying to install.
You folder structure should look for this example something like the following (tree -L 3
):
pi@ixe[XX]:~/sketchbook $ tree -L 3
.
├── Arduino.mk -> /usr/share/arduino/Arduino.mk
├── blink
│ ├── blink.ino
│ ├── build-uno
│ │ ├── blink.eep
│ │ ├── blink.elf
│ │ ├── blink.hex
│ │ ├── blink.hex.sizeok
│ │ ├── blink.ino.d
│ │ ├── blink.ino.o
│ │ ├── core
│ │ ├── libcore.a
│ │ ├── libs
│ │ └── userlibs
│ └── makefile
├── helloYouSketch
│ ├── build-uno
│ │ ├── core
│ │ ├── helloYou.elf
│ │ ├── helloYou.hex
│ │ ├── helloYou.hex.sizeok
│ │ ├── helloYouSketch.eep
│ │ ├── helloYouSketch.elf
│ │ ├── helloYouSketch.hex
│ │ ├── helloYouSketch.hex.sizeok
│ │ ├── helloYouSketch.ino.d
│ │ ├── helloYouSketch.ino.o
│ │ └── libcore.a
│ ├── helloYouSketch.ino
│ └── makefile
├── libraries
│ ├── Adafruit-GFX
│ │ ├── Adafruit_GFX.cpp
│ │ ├── Adafruit_GFX.h
│ │ ├── Adafruit_SPITFT.cpp
│ │ ├── Adafruit_SPITFT.h
│ │ ├── Adafruit_SPITFT_Macros.h
│ │ ├── fontconvert
│ │ ├── Fonts
│ │ ├── gfxfont.h
│ │ ├── glcdfont.c
│ │ ├── library.properties
│ │ ├── license.txt
│ │ └── README.md
│ └── Adafruit-PCD8544
│ ├── Adafruit_PCD8544.cpp
│ ├── Adafruit_PCD8544.h
│ ├── examples
│ ├── library.properties
│ ├── license.txt
│ └── README.txt
└── yourFolderName
├── makefile
└── pcdtest.ino
Notice how the folder names have been changed to Adafruit-GFX
and Adafruit-PCD8544
.
- Now we need to edit the a makefile inside your project to also include the libraries. We do this by specifing the libraries folder name behind the
Arduino_LIBS=
field. After adding the libraries the makefile should look something like this:
BOARD_TAG = uno
ARDUINO_PORT = /dev/ttyUSB0
ARDUINO_LIBS = SPI Adafruit-GFX Adafruit-PCD8544
ARDUINO_DIR = /usr/share/arduino
include ../Arduino.mk
We added the standard SPI
library, Adafruit-GFX
and Adafruit-PCD8544
separated by a space.
- One thing that this command line version of Arduino does not do is automatically create for us are
funtion prototypes
.function prototypes
define at the top of the program what a function is called without defining what it actually does. To compile and run our example code with the display example we need to add the following lines above thevoid setup(){}
function. If you are running a different example just go through and see where functions are defined. If you find one copy the first line of the function above void setup, remove the loos{
and add a;
.
void testdrawline(void);
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) ;
void testdrawchar(void);
void testdrawcircle(void);
void testfillrect(void);
void testdrawtriangle(void);
void testfilltriangle(void);
void testdrawroundrect(void);
void testfillroundrect(void);
void testdrawrect(void);
- Compiling
Once You have defined the funtion prototypes you can go ahead and run make
to compile the program. Notice how it will create a build-uno
folder.
make
- Uploading
The code is uploaded with the command make upload
. This does not work if you have not compiled it before.
make upload
- Monitor the Arduino Arduino Make also has a build in function to connect as a SerialMonitor Just run:
make monitor
Important
To close the monitor hit CONTROL+a
and then type k
for "kill" and then y
for "yes".
These are the essential steps in setting up a new project that can compile and upload code to the Arduino.