Raspberry Pi + Arduino (for specific values of Raspberry Pi and Arduino!)
Raspberry Pi and Arduino have rather large ecosystems that can complement each other if you can plug them together sensibly.
Arduino has analog, real-time, low power, and a wide variety of ready-made software and hardware.
Raspberry Pi also has a lot of ready-made software and hardware including Linux, camera and HDMI ports, and most recent versions offer Wi-Fi and Bluetooth onboard.
So let’s try to bring these worlds together, in a small and low-power footprint!
Raspberry Pi Zero W
Arduino Pro Mini 3.3V / 8 MHz (important to use the 3.3V version, otherwise you’ll need a logic level converter!)
Header pins for Pi Zero W and Pro Mini (may be supplied with the boards)
C4Labs Zebra Zero Plus Breadboard case
Jumper wires – male/male and male/female
Options: SD card with NOOBS, microUSB power supply, analog and digital sensors, LED’s, PiNoir camera, FTDI USB programming board
= This example uses a 8GB SD card, 2A microUSB power supply, PiNoir camera, Adafruit PIR module, Sunfounder photoresistor breakout, DS18B20 temperature sensor, and a red LED.
I picked up a Pi Zero W as a $10 special at my local Micro Center along with an 8 GB SD card for the OS. I installed Linux (Debian Jessie) on the Pi Zero W.
Since the Pi Zero W is barebones, I wanted to put it into a case that would protect it and make prototyping easy.
The C4Labs case jumped out since it holds the Pi and a small breadboard in a nice wood and plastic case and has markings for the Pi GPIO header,
saving me from checking online every time I wanted to add a jumper.
I was separately working on Arduino and found a very cheap option – the Pro Mini. I started with the 5V model and a FTDI USB board, but you pretty much need the FTDI
board every time you want to work on it, and it was “local-only” unless I could find some method to connect and control remotely. The Pro Mini only has serial options, and it
occurred to me to connect it to the Pi Zero W’s serial interface so I could read sensor data from the Pro Mini. The Pi uses 3.3V logic level so I ordered some Pro Mini 3.3V
boards from Amazon for $5 each (actually $9.99 for 2 with headers). I soldered headers onto the Pro Mini 3.3V and installed it on the breadboard and connected to the Pi:
Pi +5V -> Pro Mini “RAW” input (do not connect the 3.3V line! Let the Pro Mini regulate from the 5V line!)
Pi ground -> Pro Mini ground
Pi TX (BCM 14) -> Pro Mini RX
Pi RX (BCM 15) -> Pro Mini TX
I used the FTDI USB programmer to load a simple blink + serial example on the Pro Mini and a Python script onto the Pi to capture the output, and it worked! Every time the
Pro Mini blinked, I got a message on the Pi as the Python script echoed the serial output from the Pro Mini.
However, the FTDI USB board and cable is a bit unsightly and heavy, and the Pi only has one built-in USB port anyways. Fortunately, Adafruit has published a tutorial on
programming an Arduino board from Pi GPIO pins using SPI. The full tutorial is here:
The only thing confusing about these instructions is figuring exactly which pin numbers to connect – neither the Pi Zero W or Pro Mini boards list the SPI pinouts.
I referred to these diagrams to work it out:
For Pro Mini: https://learn.sparkfun.com/tutorials/using-the-arduino-pro-mini-33v
For Pi Zero: https://pinout.xyz/pinout/spi
I ended up using Pi’s SPI0 channel, connecting Pi BCM 10 to Pro Mini’s D11, Pi BCM 9 to Pro Mini’s D12, and Pi BCM 11 to Pro Mini’s D13. I also connected Pi BCM 12 to a
Pro Mini RST pin.
Be sure to set your avrdude config to match. The avrdude configuration uses BCM pin numbering if you change the pins.
# Linux GPIO configuration for avrdude.
# Change the lines below to the GPIO pins connected to the AVR.
id = “pi_1”;
desc = “Use the Linux sysfs interface to bitbang GPIO lines”;
type = “linuxgpio”;
reset = 12;
sck = 11;
mosi = 10;
miso = 9;
I ran the test command “sudo avrdude -p atmega328p -C ~/avrdude_gpio.conf -c pi_1 -v” and it worked! I was then able to program my Pro Mini using SPI.
The only catch: I had to use the Arduino GUI upload, capture the verbose output, and copy the -U flag to the command line to actually program my board. Maybe I’ll figure out
how to get the GUI to upload it for me soon, and post an update here.
So we can now program the Arduino with some manual steps and interact with it over serial. Best of both worlds, right?
It’s cheap too – $25 for the Pi Zero W, Pro Mini 3.3V, and C4Labs breadboard case – the case was $10, so if you BYOBreadboard, just $15 plus parts from around my bench!
So far I am still looking for uses for this beyond real-time interrupts and ADC, let me know if you build on this!