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)
root@R2-D2:~/project# cat arduino-headless
#!/bin/bash
Xvfb :1 -nolisten tcp -screen :1 800x600x24 +extension RANDR &
xvfb=”$!”
DISPLAY=:1 arduino “$@”
##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
- 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)
- In case the Application Arduino.mk is not on the default path (/usr/share/arduino), do a locate of the application
- lrwxrwxrwx 1 root root 29 Apr 2 20:22 Arduino.mk -> /usr/share/arduino/Arduino.mk
- Create a Makefile file with the following options
- 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
REMOTELY - 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 ^^
- 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)
The sample codes of waza.ino: (which blinks based on the number given)