Top Internet of Things Daily & Weekly

Arduino and Raspberry Pi Working Together (Part 2): Now With I2C

Arduino and Raspberry Pi Working Together (Part 2): Now With I2C  #IoT #Cloud #BigData

  • The easiest way to connect our Arduino board to our Raspberry Pi is using a USB cable, but sometimes this communication is a nightmare, especially because there isn’t any clock signal to synchronize our devices and we must rely on the bitrate.
  • There are different ways to connect our Arduino and our Raspberry Pi, such as I2C, SPI, and serial over GPIO.
  • If we want to connect an Arduino board and a Raspberry Pi we must ensure that the Raspberry Pi is the master.
  • But the Raspberry Pi has 1k8 ohms resistors to the 3.3-volt power rail, so we can connect both devices (if we connect other I2C devices to the bus, they must have their pull-up resistors removed)

    That’s all we need to connect our Raspberry Pi to our Arduino board.

  • The Raspberry Pi will blink one LED (GPIO17) each second while also sending a message (via I2C) to the Arduino to blink another LED.

Set up a master-slave connection between a Raspberry Pi and an Arduino using I2C to send messages — an easier alternative for communication than a USB cable.

@craigbrownphd: Arduino and Raspberry Pi Working Together (Part 2): Now With I2C #IoT #Cloud #BigData

The easiest way to connect our Arduino board to our Raspberry Pi is using a USB cable, but sometimes this communication is a nightmare, especially because there isn’t any clock signal to synchronize our devices and we must rely on the bitrate. There are different ways to connect our Arduino and our Raspberry Pi, such as I2C, SPI, and serial over GPIO. Today, we’re going to speak about I2C, especially because it’s pretty straightforward if we take care of a couple of things. Let’s start.

I2C uses two lines — SDA (data) and SCL (clock) — in addition to GND (ground). SDA is bidirectional, so we need to ensure one way or another who is sending data (master or slave). With I2C, only the master can start communications. The master also controls the clock signal. Each device has a 7-bit direction, so we can connect 128 devices to the same bus.

If we want to connect an Arduino board and a Raspberry Pi we must ensure that the Raspberry Pi is the master. That’s because the Arduino works with 5V while the Raspberry Pi works with 3.3V. That means that we need to use pull-up resistors if we don’t want to destroy our Raspberry Pi. But the Raspberry Pi has 1k8 ohms resistors to the 3.3-volt power rail, so we can connect both devices (if we connect other I2C devices to the bus, they must have their pull-up resistors removed)

That’s all we need to connect our Raspberry Pi to our Arduino board.

Now we are going to build a simple prototype. The Raspberry Pi will blink one LED (GPIO17) each second while also sending a message (via I2C) to the Arduino to blink another LED. That’s the Python part:

And finally, the Arduino program. Arduino also answers to the Raspberry Pi with the value that it has been sent, and the Raspberry Pi will log the answer within the console.

Arduino and Raspberry Pi Working Together (Part 2): Now With I2C