Hi! 😊

Compile and Run Arduino Codes from Raspberry Pi

Compile and Run Arduino Codes from Raspberry Pi


Perhaps wondering how to compile the Arduino codes on the raspberry pi terminal. After spending a couple of days browsing the net, I came up with the following tutor which works great and don’t need the Arduino GUI.

At first, i did go for the default Arduino Program that is to run the Java program on a headless screen..but that did not go well for me…needless to say that I lost a couple of hours roaming around the configs..so ..  Below is a script that i tried to use which is available on the Arduino Website: (Xvfb [similar to VNC] is good but was not working for me)

[email protected]:~/project# cat arduino-headless 
Xvfb :1 -nolisten tcp -screen :1  800x600x24 +extension RANDR &
DISPLAY=:1 arduino “[email protected]

##kill -9 $xvfb

So i have followed this step by step tutor (lost a bit midway..^^) but finally came up with the codes running on my arduino device…

  • Install the application arduino-mk
                     [email protected]:~# apt-get install arduino-mk
  • Install the application’s dependencies MAKE, gcc… (build-essentials) on linux
  • Create a Working folder
    • Mine was in /root/project and go to the directory  (mkdir /root/project && cd /root/project)
    • Add a symbolic link like this one:
      ln -s /usr/share/arduino/Arduino.mk Arduino.mk)

      • lrwxrwxrwx 1 root root   29 Apr  2 20:22 Arduino.mk -> /usr/share/arduino/Arduino.mk
        • In case the Application Arduino.mk is not on the default path (/usr/share/arduino), do a locate of the application
          (locate Arduino.mk on terminal)
    • Create a Makefile file with the following options
                     [email protected]:~/project# cat Makefile 
                     BOARD_TAG = uno
                     ARDUINO_PORT = /dev/ttyUSB0
                     ARDUINO_LIBS =
                     ARDUINO_DIR = /usr/share/arduino
                     include Arduino.mk
          • BOARD_TAG — name of your board [mine was UNO] 
            view the text file /usr/share/arduino/hardware/arduino/boards.txt to get a list of available board
          • ARDUINO_PORT (the path of the connected arduino)
            To know path –  follow this tuto:
                             ls -l /dev/ >> /root/dev.1.txt 
                         Pluggin your Arduino device (with the Usb Port of the Arduino to the USB port of the Raspberry Pi)
                             ls -l /dev/ >> /root/dev.2.txt
              Then do a diff on those two files to know which device is added.
          • ARDUINO_DIR — the path where the arduino is installed
          • include the whole folder (Arduino.mk)Use the command make help to get a list of the available options
  • You are one step closer towards compiling the arduino codes. (A file with .ino extention)
    • Upload the arduino codes to the working directory – below a sample codes for led testing  on pin 13 and ground on ground ^^
           [email protected]:~/project# ll
           -rwxrwxrwx 1 root root  127 Apr  2 20:00 arduino-headless
            lrwxrwxrwx 1 root root   29 Apr  2 20:22 Arduino.mk -> /usr/share/arduino/Arduino.mk
           -rwxrwxrwx 1 root root  111 Apr  3 03:40 Makefile
           -rw-r–r– 1 root root 2398 Apr  9 14:07 waza.ino
  • To verify the codes (launch the command make) on the working directory, there should not be any errors unless the codes is creepy. A folder named build-uno should appear.
  •    To upload the codes on the Arduino, launch the command make upload (a lot of compilation should appear on the terminal…)
  • Now the codes are uploaded, time to interact with the arduino from the Raspberry Pi
    • We can use the command screen to interact with it:
    • screen /dev/ttyUSB0(press the buttons 1,2.. to see the led lighting) 😀
    • In order to exit the screen (Ctrl+A then press k, choose y – to kill the window)
== > Compile and upload Arduino codes REMOTELY without physical access to the arduino 😀

The sample codes of waza.ino: (which blinks based on the number given)

#define led 13
void setup() {
  Serial.begin (9600);
  pinMode(led, OUTPUT);
void move(int n) {
switch (n) {
case 1: 
Serial.println(“.. Blink Once”);
case 2: 
Serial.println(“.. Blink twice fast”);
delay (300);
delay (300);
void getInputs() {
if (Serial.available())  {
Serial.println(“Input: “);
      move(Serial.read() – ‘0’);
void loop()
Coming soon with another post of controlling a remote RPI car based on Arduino using a web interface (Html.PHP and Ajax) that connects to a Client server system based on Python which then interacts with the Arduino…
Made with ♡ ♥💕❤ from Mauritius