Connecting and Interfacing Raspberry Pi with Arduino
Hi lovely people! 👋 I am working on a greenhouse monitoring project and I had to connect my Arduino to the internet over WiFi. I wanted to push some sensor data to my server. I could have bought a WiFi shield for the Arduino but why spend more money when you already have a Pi with WiFi card?
I ended up connecting Arduino with my Pi and pushing sensor data to my server through the Pi. The process was super simple.
Step 1: Start serial communication on Arduino
In your Arduino code you need to start serial communication during setup and send some data to the Raspberry Pi. I am using the loop function to send the data every half-second:
Serial.println(“Welcome to Arduino :)”);
Add any other code you might need for your project and upload the code on Arduino.
Step 2: Connecting Arduino & Raspberry Pi
Connect the Arduino using the USB cable to the Raspberry Pi after the code has been uploaded to Arduino.
Step 3: Enable I2C on the Raspberry Pi
We need to enable I2C communication on the Raspberry Pi. I2C is a common standard which allows one device to talk to another. You can enable this from the terminal by running:
$ sudo raspi-config
Now select 5 Interfacing Options from the list. Now select I2C from the list and select enable.
Step 4: Write code on Pi to read incoming data
Create a file code.py on your desktop on the Raspberry Pi.