Here's a practical example of interfacing a Raspberry Pi with an Arduino using I²C, one of the simplest and most flexible methods for communication between a Pi and a microcontroller.
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Project: Raspberry Pi (Master) ↔ Arduino (Slave) over I²C
Goal:
- Raspberry Pi sends a command to Arduino
- Arduino replies with a sensor value or a message
1. Wiring
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Optional: Add 4.7kΩ pull-up resistors from SDA and SCL to 3.3V
2. Arduino Code (I²C Slave)
Upload this code to your Arduino using the Arduino IDE.
3. Raspberry Pi Code (Python I²C Master)
Setup:
Python Script:
Expected Output on Raspberry Pi:
And on the Arduino Serial Monitor:
Extend It!
You can:
- Modify Arduino to return sensor readings (e.g., temperature)
- Send structured commands (e.g., control a motor)
- Use SPI or UART for higher speed or bi-directional streaming