Close

Raspberry Pi I2C Connection to Arduino

A project log for White Cell Pressurization via Microcomputers

For the National Science Foundation project "SBIR Phase II: A spectroscopic THz Sensor for Mixed Gas Analysis and Air Pollution Monitoring"

thomas-loganThomas Logan 08/28/2020 at 22:450 Comments

This week, I've been working on upgrading the system by adding a Raspberry pi 3. The goal is for the Rpi to tell the Arduino to maintain the chamber at a specific pressure based on the needs of the current mission, and by listening to data readouts from the Arduino, the Rpi can respond with more commands accordingly. I'm using an I2C connection between the Rpi and Arduino, as the USB port will not be easily accessible when the system is housed in the chassis and is not secure enough for flight.

I've configured the Rpi to send data over the I2C connection, and tested this with a simple Python code to turn on and off the Arduino's onboard LED. 

I'm now exploring another simple code in which both the Rpi and Arduino send information to each other (the Rpi sends a byte, and the Arduino sends a byte in return). For this, I'm following the example code on this web page: https://roboticsbackend.com/raspberry-pi-master-arduino-slave-i2c-communication-with-wiringpi/ However, Python tells me I have a syntax error in the first line {int main (int argc, char **argv)} even though I copied it verbatim from their example!

Once I solve this syntax problem, the real challenge will be figuring out how to write both the Python and Arduino codes to perform the tasks of operating a vacuum pump, opening and closing a solenoid, and reading a pressure sensor in order to regulate the pressure in the vacuum chamber. I don't have much coding experience myself, so any suggestions for first steps would be extremely helpful!

Also, I created this simple schematic (which I've added to the images for this project) which shows how the various boards and devices are connected. We will be creating a custom board which integrates all these boards into a single board.

Discussions