Rpi3 BMP180气压计传感器接口问题

时间:2020-02-18 05:54:28

标签: python linux raspberry-pi i2c adafruit

im目前正在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: -- -- -- -- -- -- -- --    

如果我在一切均正确连接并检查(〜/ BMP180Code / Adafruit_Python_BMP / examplessimpletest.py)时让Adafruit的示例/测试代码运行,我将得到如下输出:

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

我在网上查找了一些解决方案,但没有任何帮助。 如果你们中的某人对此有解决方案,我将很高兴。 谢谢,祝你有美好的一天,狮子座

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:1)

答案 v0.5最新更新2020feb19gmt1914附录F

让我看看。我假设您正在使用以下过时的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)

评论

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

(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 BMP180库不再使用,不再使用 支持。

我建议OP切换到

AdaFruit BMP280/BME280 CircuitPython Library

Pimoroni BMP280/BME280 Python Library


参考

(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)BME280 Combined Humidity and Pressure Sensor Datasheet v.16 - Bosch 2018sep

(6)What's the difference between the BMP280 and the BME280 atmospheric sensors - 20,565 views 2017mar02

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

(8)Adafruit BMP280 I2C or SPI Barometric Pressure & Altitude Sensor - US$10

(9)BMP280 Temperature, Pressure, & Altitude Sensor Python Library - Pimoroni 2019nov08

(10)BMP280 Pip Install - PyPi


附录

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

(1)您应该仅使用Rpi 40引脚接头连接器中的两个I2C Clock和Data引脚。

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

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

(4)由于上述原因(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)切换到AdaFruit CircuitPython传感器库(注1),

(b)切换到BMP280。

现在我们遇到了问题。这个旧库使用了不再支持的AdaFruit EasySetup工具,可能与Raspberry Pi不兼容

注1-Circuit Python与Raspberry Pi操作系统Raspbian 10破坏者不是100%兼容。

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.

附录F-BME280学习笔记

我一直在使用陀螺仪,加速度计和磁力计,但从未使用过压力计。我还使用过温度和湿度传感器,但从来没有使用过压力传感器,因为我一直认为压力或高度传感器仅适用于登山者,不适用于我的业余家庭自动化。但是,在研究了OP的问题之后,我发现有一个新传感器在一个芯片中具有三个测量值:温度,湿度和压力。我还发现,尽管OP的AdaFruit BMP085甚至BMP180库已被贬值,但实际上还有另一个新的后继产品BMP280和BME280。我还发现,Pimoroni似乎已经与Lada Ada合作,出售了她的BEM280接线板,并且同时创建了一个库。我希望Pimoroni的python库不是CircuitPython,而是标准Python。

我正在阅读Pimoroni的产品,并写了一些learning notes供以后参考:

/继续,...


答案结束