The Raspberry Pi operates at 3.3V, but you want to know how to connect the 5V output of a module to a GPIO pin on the Pi without damaging it.
Use a pair of resistors as a potential divider to reduce the output voltage. Figure 8-7 shows how you might use the 5V serial connection of an Arduino to a Raspberry Pi.
To make this recipe, you will need:
• 270Ω resistor (“Resistors and Capacitors” on page 380)
• 470Ω resistor (“Resistors and Capacitors” on page 380)
The TXD signal from the Pi is a 3.3V output. This can be connected directly to a 5V input on the Arduino without any problem. The Arduino module will recognize anything over about 2.5V as being high.
The problem arises when you need to connect the 5V output of the Arduino module to the RXD pin of the Pi. This must not be connected directly to the RXD input. The 5V signal could damage the Pi. Instead, the two resistors shown in Figure 8-7 are used.
Discussion
The resistors used here will draw a current of 6mA. Given that the Pi uses a fairly hefty 500mA, this will not noticeably affect the current consumption of the Pi.
If you want to minimize the current used by the potential divider, then use larger value resistors, scaled proportionally—for example, 27kΩ and 47kΩ, which will draw a miserly 60 μA.
See Also
For more information on connecting Raspberry Pi to Arduino, see Chapter 14.
If you have multiple signals to convert between 3.3V and 5V, then it’s probably best to use a multichannel level converter module—see Recipe 8.13.
Table A-4. Resistors and capacitors | |
270Ω 0.25W resistor | Mouser: 293-270-RC |
470Ω 0.25W resistor | Mouser: 293-470-RC |
1kΩ 0.25W resistor | Mouser: 293-1k-RC |
3.3kΩ 0.25W resistor | Mouser: 293-3.3k-RC |
4.7kΩ 0.25W resistor | Mouser: 293-4.7k-RC |
10 kΩ trimpot | Adafruit: 356, SparkFun: COM-09806, Mouser: 652-3362F-1-103LF |
Photoresistor | Adafruit: 161, SparkFun: SEN-09088 |
220nF capacitor | MCM: 31-0610, Mouser: 80-C322C224M5U5HA |