loading

hello, guys, in this Instructable will show how to make communication between raspberry pi & Arduino via USB for this we are using firmata protocol.

Firmata is a protocol for communicating with microcontrollers from software on a computer.

I believe this is the easiest way to control Arduino via USB.
I found this, method in this old magazine . & this method really works great.

In this method, you have to upload a sketch in Arduino only one time & you get full access on your raspberry pi.

basically raspberry pi act as Master & Arduino act as a slave.

Must watch this video for detail guidance-https://youtu.be/s4o8T6F-zGU

like & subscribe for more such videos.

Step 1: Upload Sketch to Arduino

connect your Arduino your computer & upload StandardFirmata sketch.you will found this sketch in

Examples / Firmata / StandardFirmata and Upload the sketch.

Step 2: Installing Firmata to Raspberry Pi

pyFirmata is the magic that allows your
Arduino running Firmata to talk to Python. run this commands in terminal to install required modules.

sudo apt-get install python-serial mercurial
pip install pyfirmata

to check is this install properly on not.
open python idle & run

  import pyfirmata

if you get any error then pyfirmata is not installed properly

try another method:

sudo apt-get install python-serial mercurial
git clone  https://github.com/tino/pyFirmata
cd pyfirmata
sudo python setup.py install

Step 3: Simple Blinking LED Code

now build the circuit.
connect led to pin D13 of Arduino

connect Arduino to raspberry pi via USB.

by entering this command in terminal you will get a list of all USB devices

ls /dev/tty*

in my case, ACM0 is my Arduino.

now create new python file in idle copy & past this sketch.

you will get properly formatted sketch here Blinking LED code

import pyfirmata
import time board = pyfirmata.Arduino('/dev/ttyACM0')
pin13 = board.get_pin('d:13:o') 
while True:
	time.sleep(1)
        print("on") 

	pin13.write(1)
	time.sleep(1) 
	print("off") 
	pin13.write(0)

important links

Magpi magzin==https://drive.google.com/open?id=0B_7VHGHWspGcMndXNjhHakczRDg
firmata ==https://github.com/tino/pyFirmata


About This Instructable

857views

49favorites

License:

More by Saurabh Gangamwar47: Communication Between Raspberry Pi and Arduino Via Usb #firmata #python DIY Buck Converter Twoway Switching  
Add instructable to: