[英]using the iio python package
Hello there fellow Devs :)你好,开发人员:)
I want to listen for the information given by the MMA8452 acceleration sensor with python.我想用python监听MMA8452加速度传感器给出的信息。 To do this i want to use the libiio package for python.
为此,我想使用 python 的 libiio 包。
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:但是,如果我想执行使用“iio.context()”函数创建上下文的初始步骤,则会收到此错误:
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?有人可以帮我让 iio 包工作吗?
For my hardware: I use the Raspberry Pi3 model B, with Raspberian-stretch-lite v4.9对于我的硬件:我使用 Raspberry Pi3 B 型,带有 Raspberian-stretch-lite v4.9
Thanks in advance, Holger提前致谢,霍尔格
You should just need to install the libiio python package to be able to use it.您只需要安装 libiio python 包即可使用它。 In libiio/bindings/python/ run: $sudo python setup.py install
在 libiio/bindings/python/ 运行: $sudo python setup.py install
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.这是一个适用于我的系统的小示例脚本(Python 2.7),因为我有一个加载了 iio 驱动程序的 mcp3204 adc。 I used 'apt install python-libiio' to install the python bindings for libiio.
我使用“apt install python-libiio”来安装 libiio 的 python 绑定。
#! /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) )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.