Can't get Python libftdi to work

Hey,

I am merging my home automation setup from Domoticz to Home Assistant, so I am still new to it. I recently used the Hassbian image to setup Home Assistant.

One of the steps is to get my relay board to work, using the pylibftdi library.

I’ve installed the needed dependencies:
sudo apt-get install libftdi-dev
pip install pylibftdi

However, when I run my old python script it yields an error. The following python test-script, also returns an error.
import sys, pylibftdi as ftdi
print(ftdi.Driver().list_devices())

The error is:
Traceback (most recent call last):
File “./testftdi.py”, line 32, in
print(ftdi.Driver().list_devices())
File “/home/pi/.local/lib/python2.7/site-packages/pylibftdi/driver.py”, line 240, in list_devices
raise FtdiError(msg)
pylibftdi._base.FtdiError: libusb_open() failed (-4)

I cannot get it to work. Does anyone have an idea why this error could be thrown? Is there something in the Hassbian image that would prevent this Python library to malfunction?

Thanks!

When you did the pip install, were you in the homeassistant python venv?

I don’t think so :slight_smile: , I installed it logged in as root user.

source /srv/homeassistant/bin/activate
`pip install pylibftdi’

Ideally as the homeassistant user.

Thanks, I tried this. But it said the package was already installed

(homeassistant) homeassistant@hassbian:/home/pi $ pip install pylibftdi
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pylibftdi in /srv/homeassistant/lib/python3.7/site-packages (0.17.0)

Running the sample script still yields the same error after this. :frowning:

Is libusb installed?

Yep,

pi@hassbian:/home/homeassistant $ python -m pylibftdi.examples.info
pylibftdi version     : 0.17.0
libftdi version       : libftdi_version(major=1, minor=4, micro=0, version_str='1.4', snapshot_str='unknown')
libftdi library name  : libftdi1.so.2
libusb version        : libusb_version(major=1, minor=0, micro=22, nano=11312, rc='', describe='http://libusb.info')
libusb library name   : libusb-1.0.so.0
Python version        : 2.7.16
OS platform           : Linux-4.14.98-v7+-armv7l-with-debian-buster-sid

I can’t get list_devices to work, however I just managed to fix the bitbang part which sends commands to the relayboard. That’s enough to get everything working! \o/

I think your problem is that you need to run as root or sudo. There are ways around this, but you should try to run your python script via sudo, and to see if this works.