Go Down

Topic: Can't work with pyFirmata (Read 1 time) previous topic - next topic

markUK

I'm working on a project that involves experimenting with Arduino Mega and I'm learning about it from this book https://books.google.co.uk/books/about/Python_Programming_for_Arduino.html?id=O0PfBgAAQBAJ&printsec=frontcover&source=kp_read_button&redir_esc=y#v=onepage&q&f=false

I'm in stage where I need to import pyfirmata library but for whatever reason it keeps throwing an import error.

I installed the library using pip3 and when that didn't help I built it from source therefore I'm quite confident that I've got it in my system. I even got a file path where it is installed. Within my Python site-packages directory.

The book is favouring Python 2.7 but I figured I can make this work in Python 3 as well. I tried import pyfirmata, from pyfirmata import Arduino and in both cases I get import error.

It shouldn't be that hard to get this to work. What should I try ?

Code: [Select]
#!/usr/bin/python
# Import required libraries
import  pyfirmata
from time import sleep

I also tried replacing the first line with the exact file path of the directory but no effect.

ron_sutherland

Your scrip is running Python 2 not 3 try...

Code: [Select]
#!/usr/bin/env python3
my projects: https://github.com/epccs

jamesdinsmore

I had a similar issue that turned out to be my Raspberry Pi setup was incomplete. I had not run the pyfirmata setup for Python3:

sudo apt-get install python-pip python-serial
sudo pip install pyfirmata          {yo, note lower-case f}

then navigate to pyfirmata folder: (probably cd pyfirmata)
sudo python3 setup.py install

James

Go Up