Top Internet of Things Daily & Weekly

Arduino and Raspberry Pi Working Together

Arduino and Raspberry Pi Working Together  #IoT #Cloud #BigData

  • With this small project, I want to use an Arduino board and Raspberry Pi together.
  • One (a green one) will be controlled by the Raspberry Pi directly via GPIO, and the other one (a red one) will be controlled by the Arduino board.
  • The Raspberry Pi will be the “brain” of the project and will tell the Arduino board when to turn on/off its LED.
  • Our Arduino board is connected directly to the Raspberry Pi via USB cable and we send commands via serial interface.
  • We can use I2C and other ways to connect an Arduino and a Raspberry Pi, but in this example, we’re using the simplest way to do it: A USB cable.

This blnky app merges an Arduino and a Raspberry Pi as well as Python and C, combining the benefits of both boards with a USB cable and a serial interface.

@craigbrownphd: Arduino and Raspberry Pi Working Together #IoT #Cloud #BigData

Basically, everything we can do with Arduino it can be done with a Raspberry Pi (and vice versa). Sure, there are things that are easy to do with Arduino (connecting sensors for example), but other things (such as working with REST servers and databases) are “complicated” with Arduino and C++ (they are possible but require a lot of low-level operations). Meanwhile, those difficult tasks are pretty straightforward with Raspberry Pi and Python (at least for me and because of my background).

With this small project, I want to use an Arduino board and Raspberry Pi together. The idea is blinking two LEDs. One (a green one) will be controlled by the Raspberry Pi directly via GPIO, and the other one (a red one) will be controlled by the Arduino board. The Raspberry Pi will be the “brain” of the project and will tell the Arduino board when to turn on/off its LED. Let’s show the code.

As we can see, the script is a simple loop and blinks the LED (using pin 12) with an interval of one second. Our Arduino board is connected directly to the Raspberry Pi via USB cable and we send commands via serial interface.

Finally, the Arduino program:

Here, our Arduino board is listening to the serial interface (with serialEvent), and each time we receive “\n”, the main loop will turn on/off the LED depending on the value (1 = on, 0 = off).

We can use I2C and other ways to connect an Arduino and a Raspberry Pi, but in this example, we’re using the simplest way to do it: A USB cable. We only need an A/B USB cable. We don’t need any other extra hardware (such as resistors) and the software part is pretty straightforward also.

Arduino and Raspberry Pi Working Together