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

Python Rpi3 BMP180气压计传感器接口问题,python,linux,raspberry-pi,i2c,adafruit,Python,Linux,Raspberry Pi,I2c,Adafruit,我现在正在我的树莓皮3上做气压计传感器。 不幸的是,它并没有真正起作用。我的BMP180传感器接线如下: VIN -> 3V3 (1) GND -> GND (9) SCL -> GPIO3 (5) SDA -> GPIO2 (3) 对电缆和连接进行了双重检查并更换了几次,因此这些不是问题所在。我还在raspi配置中启用了I2C。如果我键入i2cdetect-y1我会得到类似的结果,因此未检测到任何连接: 0 1 2 3 4 5 6 7 8

我现在正在我的树莓皮3上做气压计传感器。 不幸的是,它并没有真正起作用。我的BMP180传感器接线如下:

VIN -> 3V3 (1)
GND -> GND (9)
SCL -> GPIO3 (5)
SDA -> GPIO2 (3)
对电缆和连接进行了双重检查并更换了几次,因此这些不是问题所在。我还在raspi配置中启用了I2C。如果我键入
i2cdetect-y1
我会得到类似的结果,因此未检测到任何连接

     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\u Python\u 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
回溯(最近一次呼叫最后一次):
文件“simpletest.py”,第37行,在
传感器=BMP085.BMP085()
文件“build/bdist.linux-armv7l/egg/Adafruit\u BMP/BMP085.py”,第69行,在__
文件“build/bdist.linux-armv7l/egg/Adafruit\u BMP/BMP085.py”,第72行,in\u load\u calibration
文件“build/bdist.linux-armv7l/egg/adafruitgpio/I2C.py”,第202行,在readS16BE中
文件“build/bdist.linux-armv7l/egg/adafruitgpio/I2C.py”,第179行,在readS16中
文件“build/bdist.linux-armv7l/egg/adafruitgpio/I2C.py”,第166行,在readU16中
文件“build/bdist.linux-armv7l/egg/Adafruit_PureIO/smbus.py”,第187行,在read_word_数据中
IOError:[Errno 110]连接超时
我在网上找到了一些解决方案,但没有任何帮助。 如果你们中有人能解决这个问题,我会很高兴的。
谢谢,祝你今天愉快,Leo

首先,如果你使用Raspberrian with GUI,你需要在raspberry上启用i2c接口:
Pi开始菜单>首选项>raspberry Pi配置
并在
接口
选项卡中打开i2c。或者,如果您正在使用终端,请仅执行以下操作:
sudo raspi配置->接口选项->I2C

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

回答(v0.5最新更新2020年2月19日GMT1914附录F)

让我想想。我假设您使用的是以下过时的python程序。请告诉我其他情况

(一)

我发现第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) 旧Rpi(2014)可能使用I2C0而不是I2C1,自动检测功能可能无法识别Rpi3/4并选择错误的数字,不是1,而是0或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 BMP180库已折旧,不再使用 支持

我建议将OP切换到


参考资料

(一)

(二)

(三)

(四)

(五)

(六)

(七)

(八)

(九)

(10)


附录

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

(1) 您应该在RPI40引脚头中只使用两个I2C时钟和数据引脚

(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运行,但不能为BMP180运行。警告:我只是一个友好的爱好者。不保证没有任何东西不会融化或爆炸!按照爱好者的建议自担风险!:)


附录D-修改AdaFruit BMP180 Rpi3/4计划的建议

主测试程序实际上很短

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

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

下一步是更新bmp085类。见下面的附录E


附录E
# 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()))
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.