Search code examples
python-3.xarduinoimporterrorraspberry-pi2firmata

Trouble running pyfirmata on raspberry pi 2 with python 3


I am trying to run pyfirmata on my raspberry pi 2. I have it installed in here:

/home/pi/pyFirmata

But when I try to run the following code:

from pyfirmata import Arduino, util
import time

board = pyfirmata.Arduino('/dev/ttyACM0')
analog_pin = board.get_pin('a:0:i')
it = pyfirmata.util.Iterator(board)
it.start()
analog_pin.enable_reporting()

while True:
    reading = analog_pin.read()
    if reading != None:
        voltage = reading * 5.0
        print("Reading= %f\t Voltage= %f" % (reading, voltage))
        time.sleep(1)

I get the following error message:

Traceback (most recent call last):
  File "/home/pi/Arduino_Avoltage.py", line 1, in <module>
    from pyfirmata import Arduino, util
ImportError: No module named pyfirmata

I have read the "read me" file that was installed with the pyfirmata and the Arduino has standard firmata installed on it. I can't figure out what I did wrong. I need this to work with python 3, any suggestions? Thanks.


Solution

  • You should put pyFirmata in site-packages:

    /home/pi/Lib/site-packages/pyFirmata