-
Notifications
You must be signed in to change notification settings - Fork 0
Compiling Arduino Sketch on Raspberry Pi
AJ but at Work edited this page Jun 4, 2025
·
9 revisions
This guide walks you through setting up and using arduino-cli to compile and upload Arduino sketches directly from a Raspberry Pi (e.g., Pi 4B). No Arduino IDE needed.
curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh(Optional: move it to your path)
mkdir -p ~/.local/bin
mv arduino-cli ~/.local/bin/
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcarduino-cli config initThis creates the ~/.arduino15/ config directory.
arduino-cli core update-index
arduino-cli core install arduino:avrmkdir -p ~/Arduino/MySketch
arduino-cli sketch new ~/Arduino/MySketchEdit the .ino file:
// ~/Arduino/MySketch/MySketch.ino
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}ls /dev/ttyUSB* /dev/ttyACM*Typical result: /dev/ttyUSB0 or /dev/ttyACM0
arduino-cli compile --fqbn arduino:avr:nano ~/Arduino/MySketchFor old-bootloader Nanos, use:
arduino:avr:nano:cpu=atmega328old
arduino-cli upload --fqbn arduino:avr:nano -p /dev/ttyUSB0 ~/Arduino/MySketchCreate a file named upload.sh in the same folder as your sketch:
#!/bin/bash
SKETCH_DIR="$(dirname "$(realpath "$0")")"
BUILD_DIR="$SKETCH_DIR/build"
PORT="/dev/ttyUSB0"
FQBN="arduino:avr:nano" # or nano:cpu=atmega328old
arduino-cli compile --fqbn $FQBN --build-path $BUILD_DIR $SKETCH_DIR
arduino-cli upload --fqbn $FQBN -p $PORT --input-dir $BUILD_DIR --verboseMake it executable:
chmod +x upload.shThen run it:
./upload.sh-
Nano using old bootloader? Use
:cpu=atmega328oldand-b57600in manualavrdude -
Board port keeps changing? Use
ls /dev/ttyUSB*before upload -
Don't see
.hexfile? Use--build-pathto force a known output folder -
Serialundefined in VS Code?- Include
#include <Arduino.h> - Make sure IntelliSense knows the core paths and defines
- Include
-
Want stable port name? Use a
udevrule or dynamic port detection script
You can now:
- Write and edit Arduino code from your Pi
- Compile it with full C++ power (g++, threads, etc.)
- Upload it directly to your Nano or Uno with one script
All without opening the Arduino IDE ever again. 💥