Raspberry Pi - Arduino Serial Communication

162,407

129

28

Posted

Introduction: Raspberry Pi - Arduino Serial Communication

In this project, we will be making a communication between Arduino and Raspberry Pi which transfer vital information by sending data one bit at a time.

Serial communications are essential for every Micro-controllers to communicate between Micro-controllers and another device. The Micro-controller sends these 1 and 0 (bits) that contain necessary information one by one, or Serially. These bits form together and turn into bytes (composed of 8 bits). For further information, check it out sparkfun binary tutorials.

It’s a fairly easy project and can be used either on its own or part of something bigger (Check it Out >> Integrated Weather Station).

Step 1: List of Material

For this project, we will be using:

- Arduino boards (mine Arduino Uno Rev3)

- Raspberry Pi 2

- USB cable cost :~1.00 USD

Step 2: Hardware Connection

In common, the connections are fairly easy. Just connect Arduino USB Plug to Raspberry PI with USB cable and check the connection between Arduino and Raspberry pi by type "ls /dev/tty*" in Raspberry Pi terminal, the result should be content "/dev/ttyACM0" and you are good to go.

Step 3: Raspberry Pi Programming

Below is the Raspberry Pi Serial Communication code. Upload serial_test.ino code to your Arduino (Mine Arduino Uno Rev3) , Run serial_test.py Python code in Raspberry PI, Connect Arduino to Raspberry Pi through USB cable, and you should have no problems.

Step 4: Enjoy!

After making sure that everything works smoothly, you can take this project into bigger project (Check it Out >> Integrated Weather Station)!

Power through batteries or a plug and you’re good to go!

6 People Made This Project!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Paper Contest 2018

    Paper Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

20 Comments

picocom /dev/ttyUSB0 -b 9600 -r -l

what if i wanna send data from pi to Arduino ; am trying control Stepper motor using arduino and in the other side there is pi with some image processing works , need to send angle / step to stepper to move on from pi to arduino

Are you struggling with the sending of data from the Raspberry Pi or the receiving data on the Arduino?

I am getting

2

01

4

03

6

05

8

07

...

and so on. Why? Pl help

made it but send data from pi3 to arduino to move motor , facing pb of keep serial 9600 connection open to be able to send data from pi3 .

IMG_20170602_020525.jpg

I appreciate that you put this Instructable together, but I could suggest a few improvements:

1. A link to an example USB cable product would be helpful. Is it some kind of special cross-over cable?

2. I'm not sure what this means: 'the result should be content "/dev/ttyACM0" and you are good to go.'

3. Your explanation of serial communication is perhaps a bit over simplified. Do I need to send any initializing sequence or anything?

4. Some Arduino clones have a micro USB cable connector that they also use for power. Can you still use a USB-to-USB connection? How is the Arduino powered then?

Thanks.

If you haven't found the answers or if someone else stumbles upon this:

1) No, any ol' USB cable will work

2) That means that if the Arduino is the first Serial connection the Pi OS "sees" that should be the name...if not you'll have to find what the filename of the connection is (everything in Linux is a file, even the keyboard and wifi card! If you know what to look for you can have some fun with this)

3) Serial is an extremely simple protocol, there is some magic that happens when doing Serial over USB but the FDI drivers will handle that. Once you get a hold of it in this method you can act just like you are reading and writing with user input. Reading up on Serial isn't a terrible idea for general knowledge, one hint that might save you some heartache: Serial uses 8 bits to represent characters, so it is NOT exactly ASCII or UTF-8. This can cause some annoying issues, it was my biggest pain point in my first Serial project.

4) The Vin pin and Gnd pin (I use the nearest to Vin, not sure if it matters) can be used to power any Arduino. Some also have other power inputs, but just know by connecting it directly you are taking responsibility for the quality of the power, it won't be converted or protected by the board. Make sure you use the right voltage (5V or 3.3V)!

Happy hacking!

What's the advantage of connecting an Arduino to a RPi if the RPi can read GPIO by itself? Can you please give me an example in which RPi alone won't work without an Arduino?

Thanks in advance,

RPi has only one PWM output and GPIO pins are very sensitive (as far as
I know). If you need to control many servos and already own an Arduino,
it's better and cheaper to use it than buy some PWM module. Hope it
helps

Understood. Thanks!