Communication Between Raspberry Pi and Arduino Via Usb #firmata #python




Introduction: Communication Between Raspberry Pi and Arduino Via Usb #firmata #python

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-

like & subscribe for more such videos.

Step 1: Upload Sketch to Arduino

connect your Arduino your computer & upload StandardFirmata 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
cd pyfirmata
sudo python 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:


important links

Magpi magzin==
firmata ==

1 Person Made This Project!


  • Pocket-Sized Speed Challenge

    Pocket-Sized Speed Challenge
  • Audio Challenge 2020

    Audio Challenge 2020
  • Maps Challenge

    Maps Challenge

3 Discussions


2 years ago

Help me to solve this problem! Thanks all!!!

Traceback (most recent call last):

File "<pyshell#2>", line 1, in <module>

board = pyfirmata.Arduino('/dev/ttyACM0')

AttributeError: 'module' object has no attribute 'Arduino'


2 years ago


Interesting and the very simple example works.

But if I put a print one gets a

<bound method of <pyfirmata.pyfirmata.Pin object at 0x76a1afd0>>

Which I assume is an error saying this is a read-only pin.

More examples would be most helpful: such a read a pin, Analogue input, PWM output.

Vladimir Ivanov
Vladimir Ivanov

Reply 2 years ago

You need to change 'o' to 'i' in 'get_pin('d:13:o')

d - digital pin

a - analog pin

o - output

i - input

s - servo

p - PWM

I think that should help you a little, if you still need it :)