There is a problem when connecting an Arduino to the GPIO on a RaspberryPi. The logic level on the Arduino is five volts and the RaspBerryPi requires 3.3 volts. Sending a five volt signal to a GPIO pin will damage the RaspberryPi. When I wire something wrong I want to a see spectacular blow-up. You will see nothing, no fireworks, not even a little smoke. No fun, it just stops working.
This tutorial will illustrate three different ways to convert 5 volts from an Arduino into 3.3 volts for a RaspberryPi.
1 – A voltage divider
2 – An Optoisolator (Optocoupler)
3 – A bi-directional level shifter
The RaspberryPi program in this tutorial uses the wiringPi
libraries, written by Gordon Henderson, for programming the GPIO in C.
wiringPi must be installed. Instructions for download, installation and use are located at http://wiringpi.com
wiringPi uses it’s own pin numbering scheme.
All RaspberryPi pin numbers are wiringPi numbers unless otherwise specified.
You will need a way to run wires from the RaspberryPi to the breadboard. You can use male/female jumper wires but one of the Pi Cobblers listed on this page from Adafruit will make it a lot easier: http://www.adafruit.com/search?q=cobbler
Step 1: Building the Circuit
To build the circuit you will need:
LED – RGB Common Anode https://www.sparkfun.com/products/10821
4 270-560 Ohm resistors (For LEDs and Optoisolator)
2 10K resistors (Pulldowns)
3 1K resistors (For voltage divider)
Bi-directional Level Shifterhttps://www.sparkfun.com/products/314 orhttps://www.sparkfun.com/products/314
Male Headers (For level shifter) https://www.sparkfun.com/products/116
For my build I used the Sparkfun level shifter and my diagram shows the Adafruit part. The reason for this is that I don’t have the Fritzing part for the Sparkfun level shifter. The two parts are electrically identical, but the pinouts are different. Make sure you check the pinouts for the part you use.
Sparkfun also sells a good resistor assortment that includes all the resistors you need for this project and many more, look here:https://www.sparkfun.com/products/10969
Sparkfun has a good tutorial for their level shifter here:https://learn.sparkfun.com/tutorials/bi-direction…
Follow the diagram above to build the circuit.
Step 2: The Voltage Divider
The voltage divider is a simple circuit made up of two resistors.
To calculate the output voltage use this formula: Vout = Vin * (R2 / (R2 + R1))
3.3 volts is 2/3 of 5 volts so the value of R2 should be double R1.
I used 1K resistors with two resistors in series for R2 and one for R1.
When the pin on the Arduino goes high the signal is sent to the RaspberryPi.
Step 3: The Optoisolator
The Optoisolator is sometimes referred to as an Optocoupler. The two names sound opposite but the Optoisolator does both. It allows you to pass a signal from one device to another with no electrical connection. The small four pin IC contains an LED and a photo diode. When the LED is lit current is allowed to pass through the photo diode.
For more detail: Arduino to RPi: three ways to convert 5 volts to 3.3 volts