gpt4 book ai didi

python - 使用 python mraa 读取英特尔爱迪生上的温度传感器值

转载 作者:太空宇宙 更新时间:2023-11-04 03:13:32 24 4
gpt4 key购买 nike

我已经用 intel edison 配置了温度传感器。我正在尝试使用以下 python 代码读取温度传感器值

import mraa
import time
import sys
import math

tmp = mraa.Gpio(2)
tmp.dir(mraa.DIR_IN)
i=0
while i<100:
print "Let's talk about Temperature %s." % tmp.read()
time. sleep(3)
i+=1
exit()

但此代码始终返回 0 作为读取值。

我是 intel edison 和 python 的新手。所以任何帮助都会很感激。谢谢

最佳答案

mraa 是用于 I/O 通信的低级骨架库。如果是基本的模拟传感器,它就可以完成工作,但我建议您改用 upm。

import time
import pyupm_grove as grove

# Create the temperature sensor object using AIO pin 0
temp = grove.GroveTemp(0)

for i in range(0, 10):
celsius = temp.value()
fahrenheit = celsius * 9.0/5.0 + 32.0;
print "%d degrees Celsius, or %d degrees Fahrenheit" \
% (celsius, fahrenheit)
time.sleep(1)

# Delete the temperature sensor object
del temp

如果不行,可能需要更新库

echo "src mraa-upm http://iotdk.intel.com/repos/3.0/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf
opkg update
opkg upgrade libmraa0
opkg upgrade upm

关于python - 使用 python mraa 读取英特尔爱迪生上的温度传感器值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37120074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com