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:
- You can’t use a normal PC.
- 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
- The Raspberry Pi uses way less power than even a laptop.
- You can run it off a power bank when you don’t have electricity.
- Saves time when you’re already using it as an IoT terminal.
Cons
- 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
- A Raspberry Pi with Raspberrry Pi OS and USB ports
- An Arduino
- One USB Type-A to USB Type-B connector
- Computer peripherals (monitor, keyboard, and mouse)
- 250Ω resistor (optional)
- Small LED bulb (any color, optional)
- Breadboard and jumper wires (optional)
Installing the Arduino IDE
Open Chromium (or any browser) and go to https://www.arduino.cc/en/software.
Pick “Linux ARM 32 bits.”
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.
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.
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 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.
Click “Extract files.” That’s the opened-up, brown box with an orange arrow pointing to the right.
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.
Close Archiver, then go to the new folder and double-click on the “install.sh” file.
Click “Execute” in the new window.
The Arduino IDE should be available at “Pi logo -> Electronics -> Arduino IDE.”
Programming with the Arduino IDE
Run the Arduino IDE from the Pi logo. You’ll find a green window where you can write your code.
Copy and paste the following code:
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.
To save, click on “File -> Save” or press Ctrl + S on the keyboard.
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.
To upload to Arduino, click on “Sketch -> Upload” or press Ctrl + U on the keyboard.
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.
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.
If you did it right, the LED bulb should light up and dim at regular 0.5-second intervals.
To access the Serial Monitor, click on “Tools -> Serial Monitor” or press Ctrl + Shift + M on the keyboard.
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.
Terenz is a hobbyist roboticist trying to build the most awesome robot the world has ever seen. He could have done that already if he wasn’t so busy burning through LEDs as a second hobby.
Our latest tutorials delivered straight to your inbox