loading

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!

<p>picocom /dev/ttyUSB0 -b 9600 -r -l</p>
<p>I am getting </p><p>2</p><p>01</p><p>4</p><p>03</p><p>6</p><p>05</p><p>8</p><p>07</p><p>...</p><p> and so on. Why? Pl help</p>
<p>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 .</p>
<p>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 </p>
<p>I appreciate that you put this Instructable together, but I could suggest a few improvements:</p><p>1. A link to an example USB cable product would be helpful. Is it some kind of special cross-over cable?</p><p>2. I'm not sure what this means: 'the result should be content &quot;<em>/dev/ttyACM0</em>&quot; and you are good to go.'</p><p>3. Your explanation of serial communication is perhaps a bit over simplified. Do I need to send any initializing sequence or anything?</p><p>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?</p><p>Thanks.</p>
<p>If you haven't found the answers or if someone else stumbles upon this:</p><p>1) No, any ol' USB cable will work</p><p>2) That means that if the Arduino is the first Serial connection the Pi OS &quot;sees&quot; 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)</p><p>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.</p><p>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)!</p><p>Happy hacking!</p>
<p>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?</p><p>Thanks in advance,</p>
<p>RPi has only one PWM output and GPIO pins are very sensitive (as far as<br> I know). If you need to control many servos and already own an Arduino,<br> it's better and cheaper to use it than buy some PWM module. Hope it <br>helps</p>
<p>Understood. Thanks!</p>
<p>If you'd like to just see if it is working before messing with python (and the missing serial module) then you can just run this from to the linux (assuming Rasbian here but should work for others) command line to verify connectivity:</p><p>cat /dev/ttyACM0</p><p>This will print out what the Arduino device is sending to the console. Then you can go fight with Python.</p>
<p>6. When you connect the USB cable, the Arduino may not come up as device /dev/ttyACM0. Please provide a way to find which device has been assigned to your USB serial port.</p>
<p>5. It may also help to be clear that in this example you are sending fromt he Arduino and receiving with the RasPi. You may want to show how to go the other way, or even how to have two way communication.</p>
<p>Hi! very good tutorial .. but can i only use Data+ and Data- in the usb cable because im powering up my arduino through pololu shield ??</p>
<p>Hi, just one question, how do we make the Pi continuously check for whether an arduino has been connected or not and transfer data when it detects it?</p>
<p>Is it possible to power the Arduino with the USB and do serial communitation at the same time?</p>
<p>Yup, it is possible. because serial cable consist of Vcc, GND, Data +, and Data - . Below is the pinout diagram of cable USB A and USB B.</p>
<p>i usually make my USB cable myself w/ coax cable for high quality serial communication </p>
<p>I'm adding this solution for people who make the same mistake as I did.</p><p>In most cases: rename your project file 'serial.py' and delete serial.pyc if exists, then you can do simple 'import serial' without attribute error.</p><p>Problem occurs when you import 'something' when your python file name is 'something.py'.</p>
<p>yup it's the bug. i tried myself.</p>
<p>is arduino ide must be installed on raspberry pi to do serial communication?</p>
<p>not really, you could use <strong>picocom</strong> to <u>start the communication automatically</u>. But, it is recommended to install arduino ide so you could troubleshoot your code. </p>
<p>is arduino ide must be installed on raspberry pi to do serial communication?</p>

About This Instructable

120,420views

114favorites

License:

Bio: A candle loses nothing of its light when lighting another
More by AdrieSentosa:LED Acrylic Trophy / Placard Raspberry Pi - Remote Desktop Connection IoT Service Robot 
Add instructable to: