简体   繁体   English

使用python监听i2c输入更改

[英]Listening to i2c input changes with python

Let's say I have a raspberry pi here and I want to write a Python script that turns on the light as soon as a i2c signal reaches the pi and some pin gets high. 假设我在这里有一个树莓派,我想编写一个Python脚本,当i2c信号到达pi并且某个引脚变高时,它会立即点亮。 I do not want to use polling for this task, as it could slow down the process (I know just a bit but I'ts just bad practice and puts load on the CPU and so on, so I don't want to permacycle asking for the input state) 我不想为此任务使用轮询,因为它可能会减慢该过程的速度(我知道一点,但我的做法很不好,并且将负载加到CPU上,依此类推,所以我不想让周期询问输入状态)

Is there any kind of server or callback function I could use to realize this with a python script? 我是否可以使用任何类型的服务器或回调函数通过python脚本实现此目的? Which library could I use to reach such a behaviour? 我可以使用哪个库来达到这种目的?

First Ideas are enviromental variables/the i2c Interface in the Linux system that I could listen to constantly somehow and catch it to make it do what I want it to. 第一个想法是环境变量/ Linux系统中的i2c接口,我可以以某种方式不断聆听并捕获它以使其按我的意愿去做。

As I see it no need to use python but I don't see whole picture so I don't know if this will help You, 如我所见,无需使用python,但看不到整个图片,因此我不知道这是否对您有帮助,
just regarding this part of question: 就这部分问题而言:

Is there any kind of server or callback function... 是否有任何类型的服务器或回调函数...

rpio.poll(pin, callback());

Watch pin for changes and execute the callback callback() on events. 监视引脚是否有变化,并在事件上执行回调callback() callback() takes a single argument, the pin which triggered the callback. callback()有一个参数,即触发回调的引脚。

The optional direction argument can be used to watch for specific events: 可选的direction参数可用于监视特定事件:

rpio.POLL_LOW: poll for falling edge transitions to low. rpio.POLL_LOW:轮询下降沿转换为低电平。
rpio.POLL_HIGH: poll for rising edge transitions to high. rpio.POLL_HIGH:轮询上升沿到高电平的过渡。
rpio.POLL_BOTH: poll for both transitions (the default). rpio.POLL_BOTH:轮询两个转换(默认)。

Complete documentation - this is the npm module documentation 完整的文档 -这是npm模块文档

My example of configuring node.js server 我的配置node.js服务器的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM