Raspberry Pi传感器检测不起作用

问题描述 投票:0回答:3

我目前正在使用Raspberry Pi 3上的气压计传感器。不幸的是,它并没有真正起作用。我的BMP180传感器的接线如下:

VIN -> 3V3 (1)
GND -> GND (9)
SCL -> GPIO3 (5)
SDA -> GPIO2 (3)

电缆和连接已仔细检查并更换几次,所以它们不是问题。我也在raspi-config中启用了I2C。如果我键入i2cdetect -y 1,则会得到类似的内容,因此未检测到连接

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --    

如果在所有内容都[[正确连接并检查]时运行Adafruit的示例/测试代码(〜/ BMP180Code / Adafruit_Python_BMP / examplessimpletest.py),我将得到类似的输出:

Traceback (most recent call last): File "simpletest.py", line 37, in <module> sensor = BMP085.BMP085() File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 69, in __init__ File "build/bdist.linux-armv7l/egg/Adafruit_BMP/BMP085.py", line 72, in _load_calibration File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 202, in readS16BE File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 179, in readS16 File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 166, in readU16 File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 187, in read_word_data IOError: [Errno 110] Connection timed out
我在网上查找了一些解决方案,但没有任何帮助。如果你们中的某人对此有解决方案,我将很高兴。谢谢,祝你有美好的一天,狮子座
python linux raspberry-pi i2c adafruit
3个回答
0
投票
您可以在link下检查如何启用I2C Raspberry

Link


0
投票
首先,如果您将Raspberrian与GUI一起使用,则需要在树莓派上启用i2c接口:Pi Start Menu > Preferences > Raspberry Pi Configuration,然后在Interface选项卡中打开I2C。或者,如果您仅使用终端:sudo raspi-config -> Interfacing Options -> I2C

我的第二个建议是再次检查接线。 I2C在SDL和SCL引脚上使用漏极开路连接。据我所知,Sparkfun BMP180传感器内置了上拉电阻器来保持线路电压。检查您的模型是否具有上拉电阻。如果不是,则必须在电路中插入一些电阻器。


0
投票

Answerv0.2最近更新2020feb19gmt0416

让我看看。我假设您正在使用以下过时的python程序。否则请让我知道。

((1)Adafruit /Adafruit_Python_BMP Archived (2014)

我发现第27〜40行中的以下注释对于调试很有用:

# For the Raspberry Pi this means you should hook up to the only exposed I2C bus # from the main GPIO header and the library will figure out the bus number based # on the Pi's revision. # Optionally you can override the bus number: # sensor = BMP085.BMP085(busnum=2)


Comments

((1)Old Rpi(2014)可能使用I2C0而不是I2C1,自动检测功能可能无法知道Rpi3 / 4并选择错误的数字,而不是1或2(对于BeagleBone可能是2)] >>

((2)python程序用于BMP085,但是您正在使用BMP180。您可能想检查所有不兼容性,并对配置函数进行必要的修改。

(3)错误消息是

"File "build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py", line 187, in read_word_data, IOError: [Errno 110] Connection timed out"

[您的“ i2cdetec -y 1”显示未检测到I2C设备,这可能意味着

((a)硬件接线不正确(确定,因此您已仔细检查了接线(打开/短路所有点对点,相邻点等)或

]

(b)软件问题,例如(i)配置错误,(ii)软件库错误。

无论哪种方式,您都可能收到上面的“超时,无法连接”错误消息。


故障排除建议

] >>((1)您可能想要尝试并错误地修改程序中的相关总线号,例如

将默认的I2C总线号从2更改为1。

((2)要确保硬件接线和软件驱动程序等正常,(a)卸下无检测BMP控制器,(b)换入任何其他I2C控制器,然后再次“ i2cdetect-y 1”。如果可以愉快地检测到新家伙,那么显然旧家伙是坏人:(


讨论和推荐

] >>OP使用的AdaFruit NMP180库已弃用,不再受支持。我会建议..//


参考

((1)Adafruit_2014 BMP085/BMP180 Python Library (Depreciated, No Longer Supported)

((2)BMP085 Datashet v2.5- Bosch 2009

((3)BMP180 Datasheet - Bosch 2009

((4)BMP280 Digital Pressure Sensor Datasheet v1.14 Bosch 2015

((5)UM10204 I2C-bus specification and user manual (referred in BMP180 Datasheet Section 5, Max clock = 3.4MHz) - 2014 NXP


附录

] >>

附录A-I2C接线和上拉电阻等

((1)您应该只使用Rpi 40引脚接头连接器中的两个I2C时钟和数据引脚。

(2)这两个引脚已经具有足够强的1k8上拉电阻。无需添加更多的上拉电阻,因为上拉电阻太大。

((3)实际上,如果您在同一总线上放置两个I2C设备,例如多于4个,而其他设备具有4k7或10k上拉电阻,则产生的上拉电阻可能远远小于1k8,并且过载I2C引脚电流。我通常删除器件上拉电阻,以免Rpi I2C引脚过载。

(由于上述原因(3),请删除同一总线上的所有其他I2C设备。

((5)您的硬件I2C连接线不能太长,最好小于30cm。超过此时间可能会导致阻抗过高(对于I2C,通常限制为400pf)。


附录B-BMP085和BMP180之间的区别

我浏览两个数据表以进行比较和对比。我的结论是:(a)BMP180是BMP085的后继产品,(b)它们在功能上相同,这意味着软件编程应该是“相同的”。

通常,行业惯例是新的硬件版本是向后兼容的,即BMP085程序可以为BMP180运行,反之亦然。警告:我只是一个友好的爱好者。没有保证没有什么不会融化或炸毁的!遵循爱好者的建议,后果自负! :)


附录D-建议为Rpi3 / 4修改AdaFruit BMP180程序

主测试程序实际上很短。

关键的设置问题是I2C总线号。

该程序的默认值为I2C总线#2。我建议更改默认值到I2c总线#1。

# AdaFruit BMP180 Program Author: Tony DiCola # https://github.com/adafruit/Adafruit_Python_BMP/blob/master/examples/simpletest.py import Adafruit_BMP.BMP085 as BMP085 # Default constructor will pick a default I2C bus. # For the Raspberry Pi this means you should hook up to the only exposed I2C bus # from the main GPIO header and the library will figure out the bus number based # on the Pi's revision. sensor = BMP085.BMP085() # Optionally you can override the bus number: # sensor = BMP085.BMP085(busnum=2) print('Temp = {0:0.2f} *C'.format(sensor.read_temperature())) print('Pressure = {0:0.2f} Pa'.format(sensor.read_pressure())) print('Altitude = {0:0.2f} m'.format(sensor.read_altitude())) print('Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure()))

下一步是更新类bmp085。请参阅下面的附录E。


[[附录E-使用Eazy Steup的AdaFruit BMP085库bmp085类-Adafruit的Tony DiCola

以下来自AdaFruit BMP085库的通知说该库已过时。 AdaFruit建议:

((a)切换至python中的circuitpython传感器库,

((b)切换到BMP280。

现在我们有问题。这个旧库使用的AdaFruit EazySetup不再受支持,可能与Rpi3 / 4不兼容。

DEPRECATED LIBRARY Adafruit Python BMP This library has been deprecated! https://github.com/adafruit/Adafruit_Python_BMP/blob/master/README.md the bmp085 and bmp180 are no longer made, and are replaced by the bmp280 we are now only using our circuitpython sensor libraries in python we are leaving the code up for historical/research purposes but archiving the repository. check out this guide for using the bmp280 with python! https://learn.adafruit.com/adafruit-bmp280-barometric-pressure-plus-temperature-sensor-breakout Adafruit Python BMP Python library for accessing the BMP series pressure and temperature sensors like the BMP085/BMP180 on a Raspberry Pi or Beaglebone Black. Designed specifically to work with the Adafruit BMP085/BMP180 pressure sensors ----> https://www.adafruit.com/products/1603 To install, download the library by clicking the download zip link to the right and unzip the archive somewhere on your Raspberry Pi or Beaglebone Black. Then execute the following command in the directory of the library:~~ sudo python setup.py install Make sure you have internet access on the device so it can download the required dependencies.


答案结束
© www.soinside.com 2019 - 2024. All rights reserved.