How to Program an Arduino with a Raspberry Pi

Now you have more great uses for your Raspberry Pi.

Arduino And Rpi

Running a program on an Arduino is easy, but have you tried doing it with a Pi? The Raspberry Pi is powerful enough to be a standalone computer and is also good enough to program a microcontroller.

Here, we use a Raspberry Pi 3 Model B+ to make an Arduino Uno blink an LED!

We’ll cut this up into two parts: how to install the Arduino IDE and how to use the IDE on the Raspberry Pi. While it’s possible to program the Arduino through Platformio, doing it this way should be much simpler for someone new.

Why You Want to Use a Raspberry Pi to Program Arduino

Typically, you would want to do it because:

  1. You can’t use a normal PC.
  2. You’re in it for the learning experience.

But there’s more to it than that. In fact, there’s a good tradeoff between using a standalone PC and using your Raspberry Pi!

Pros

  1. The Raspberry Pi uses way less power than even a laptop.
  2. You can run it off a power bank when you don’t have electricity.
  3. Saves time when you’re already using it as an IoT terminal.

Cons

  1. Overheating might become an issue for the Raspberry Pi if you don’t have ventilation.

As it is, the Raspberry Pi is good enough if you’re making a quick, do-it-in-a-weekend IoT project. Just plug in your sensors, peripherals, and Arduino, then type in your code to see it work along with the rest of your system.

But if you’re still in the “have to figure out how this circuit works” stage, then please use a proper desktop PC. It’s gonna help with the headaches.

The Things You’ll Need

  1. A Raspberry Pi with Raspberrry Pi OS and USB ports
  2. An Arduino
  3. One USB Type-A to USB Type-B connector
  4. Computer peripherals (monitor, keyboard, and mouse)
  5. 250Ω resistor (optional)
  6. Small LED bulb (any color, optional)
  7. Breadboard and jumper wires (optional)

Installing the Arduino IDE

  1. Open Chromium (or any browser) and go to https://www.arduino.cc/en/software.
Chromium Arduino Url Homepage
  1. Pick “Linux ARM 32 bits.”
Chromium Arduino Arrowed Homepage
  1. That should bring you to a page that allows you to download and/or donate. You can click “JUST DOWNLOAD” if you don’t want to donate.
Chromium Arduino Download Donate Page
  1. This should open a new window. You can change the file name at the top and the download location at the left. The “Save” button is at the bottom-right corner.
Chromium Arduino Download Folder
  1. You’ll find it in the Downloads folder (or whichever folder you chose) when it has finished downloading. Double-click on it to run the Archiver app. It might take a couple of minutes before it opens up.
Archiver Raspberry Pi Arduino Opening
  1. Archiver will open your file, but it’ll take a little while to finish reading it. There’s a circle down toward the lower left that blinks red and green. Wait for it to finish before doing anything else. You may as well grab a glass of water at this point.
Archiver Raspberry Pi Extracting Files
  1. Click “Extract files.” That’s the opened-up, brown box with an orange arrow pointing to the right.
Archiver Raspberry Pi Button Extract Files
  1. This opens a new window that lets you pick some settings. You can change the top textbox’s value to point to the “Downloads” folder. Otherwise, it should point to the “tmp” folder by default. Click “Extract” toward the bottom right to finish downloading.
Archiver Raspberry Pi Extract Window
  1. Close Archiver, then go to the new folder and double-click on the “install.sh” file.
File Explorer Raspberry Pi Install Sh
  1. Click “Execute” in the new window.
Archiver Execute Button
  1. The Arduino IDE should be available at “Pi logo -> Electronics -> Arduino IDE.”
Raspberry Pi Icon Tray

Programming with the Arduino IDE

  1. Run the Arduino IDE from the Pi logo. You’ll find a green window where you can write your code.
Arduino Ide Raspberry Pi
The Arduino IDE looks the same way on the Raspberry Pi as it does on a regular Windows PC.
  1. Copy and paste the following code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  Serial.println("LED on");
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  Serial.println("LED off");
}

The code makes the LED turn on and print “LED on” on the Serial Monitor for 0.5 seconds, then does the opposite, turning the LED off and printing “LED off” for the same amount of time.

  1. To save, click on “File -> Save” or press Ctrl + S on the keyboard.
Arduino Ide Save Button
  1. Connect the cables. The Arduino Uno uses a USB Type-A to USB Type-B connector. The square-ish side goes to the Arduino, while the rectangle side goes to the Raspberry Pi.
Type A To Type B Usb Connector 2
Left to right: USB Type-A and USB Type-B
  1. To upload to Arduino, click on “Sketch -> Upload” or press Ctrl + U on the keyboard.
Arduino Ide Upload Button
  1. Upon uploading, the TX and RX LEDs will blink rapidly, then run your program, which makes the L LED turn on or off every 0.5 seconds.
Arduino Raspberry Pi Led Internal 3
  1. To make things a little easier to see, you can try connecting an LED bulb and a 250Ω resistor between D13 and GND. Do this on a breadboard to make it easier and make sure to disconnect the Arduino from the Raspberry Pi before doing anything with the pins.
Ltspice Schematic Arduino External Led
  1. If you did it right, the LED bulb should light up and dim at regular 0.5-second intervals.
Arduino Blink External
After 0.5 seconds, the LED turns from being lit up to dimming.
  1. To access the Serial Monitor, click on “Tools -> Serial Monitor” or press Ctrl + Shift + M on the keyboard.
Arduino Ide Serial Monitor

Arduino Etiquette

With that done, you should be able to start making anything with the Raspberry Pi and Arduino. To backtrack a bit, if you’re going to do this often, you need to learn a bit about making things easier with the Arduino.

Always remember the phrase: pins off, code up, power out.

Pins Off

Let’s start by taking all the wires off the pins. If you take along time on a new project, chances are you mat have already forgotten your pin designations. You might, for instance, wire up an output pin on “HIGH” together with another output pin on “LOW.” That’s one easy way to break a GPIO pin on a microcontroller chip!

Code Up

Code up is simple: upload your code. Always keep in mind that the Arduino is always powered up while it’s connected to the USB port.

Power Out

Lastly, when you’re going to update your circuits, always turn off the power by removing the Arduino from all power sources. The last thing you’d want to happen is putting the wrong wire in the wrong place at the worst moment to make smoke pop out of whatever you’re doing. Remember, short circuits can ruin your project instantly.

Frequently Asked Questions

Can you also program the Arduino Uno on Raspberry Pi?

Any board, as long as it’s supported by the Arduino IDE, would work with Raspberry Pi. It’s basically the same as coding on a normal PC with a Linux distribution.

Which Raspberry Pi boards will this method work with?

The ability to program Arduino should work with all of the Raspberry Pi microprocessor boards except the Zero, which doesn’t have built-in USB ports. This also won’t work on the Nano, which can’t run Raspberry Pi OS.

Can I run multiple Arduino boards on the Raspberry Pi at the same time?

Yes, you can, but there’s a catch: the Raspberry Pi’s USB output is limited to about 1.2A of current. If you’re using multiple servos, then having them all move around at the same time may cause some boards to restart after experiencing a sudden power dip.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox