0

Hello there fellow Devs :)

I want to listen for the information given by the MMA8452 acceleration sensor with python. To do this i want to use the libiio package for python.

To install it I manually built it following the instructions given in this guide

It seemed to be installed fine, cuz I have no Problem importing the Package because it is located in my site-packages folder.

However if I want to do the initial step of creating a context with the "iio.context()"-function, I get this error:

Traceback (most recent call last):
File "./bindings/python/examples/iio_info.py", line 89, in <module>
main()
File "./bindings/python/examples/iio_info.py", line 34, in main
ctx = iio.Context(uri)
File "/usr/local/lib/python2.7/dist-packages/iio.py", line 730, in __init__
self._context = _new_default()
File "/usr/local/lib/python2.7/dist-packages/iio.py", line 33, in _checkNull
raise OSError(err, _strerror(err))
OSError: [Errno 2] No such file or directory

Can someone help me get the iio package working?

For my hardware: I use the Raspberry Pi3 model B, with Raspberian-stretch-lite v4.9

Thanks in advance, Holger

2 Answers2

0

You should just need to install the libiio python package to be able to use it. In libiio/bindings/python/ run: $sudo python setup.py install

0

Here's a little sample script (Python 2.7) that works on my system, since I have an mcp3204 adc with an iio driver loaded. I used 'apt install python-libiio' to install the python bindings for libiio.

#! /usr/bin/python

import time, iio

ctx = iio.LocalContext()
ctrl = ctx.find_device('mcp3204')

voltages = ['voltage0', 'voltage1', 'voltage2', 'voltage3']
for id in voltages:
    chan = ctrl.find_channel(id)
    print("{0}: {1}".format( chan.id, chan.attrs['raw'].value) )