用于ms5803-14ba的python库用于覆盆子pi over i2c的压力传感器

ms5803p的Python项目详细描述


MS5803-14BA

MS5803年

用于MS5803-14BA的Python 3库,用于I2C上的覆盆子PI压力传感器。

基于Adafruit Arduino LibraryControl Everything Python Library。当把原始读数修正为实际的温度和压力时,有些数学问题很复杂,可以从MS5803-14BA datasheet中验证。

支持在任何支持的过采样率(OSR)下从传感器读取压力和温度值。更高的osr导致更高的分辨率/精度,但需要更长的转换时间。支持的osr速率是[256、512、1024、2048、4096],也可以在MS5803.OSRs处获得。

安装

在pypi上提供,因此您可以使用

pip3 install ms5803py

或者克隆此存储库并运行

python3 setup.py install

用法

ms5803和rpi使用i2c协议进行通信,因此需要在pi上设置i2c,如this Adafruit tutorial中所述。之后,ms5803需要连接到覆盆子pi,如this Adafruit tutorial所述。

完成后,您必须找到ms5803的i2c地址。为此,请在插入ms5803之前和之后运行以下命令。无论显示什么地址,都是您想要的地址:

sudo i2cdetect -y 1

它应该是0X760x77,如MS5803-14BA datasheet中所述,这取决于ms5803上的csb(chip select)管脚是高还是低。在Sparkfun breakout board上,i2c地址是0x76,因此如果在初始化传感器时没有指定地址,我将其设置为默认值。

有关用法示例,请参见python3 example.py

import ms5803py
import time

s = ms5803py.MS5803()
while True:
    # Do the batteries-included version, optionally specifying an OSR.
    press, temp = s.read(pressure_osr=512)
    print("quick'n'easy pressure={} mBar, temperature={} C".format(press, temp))

    # Use the raw reads for more control, e.g. you need a faster sample
    # rate for pressure than for temperature. Use a high OverSampling Rate (osr)
    # value for a slow but accurate temperature read, and a low osr value
    # for quick and inaccurate pressure readings.
    raw_temperature = s.read_raw_temperature(osr=4096)
    for i in range(5):
        raw_pressure = s.read_raw_pressure(osr=256)
        press, temp = s.convert_raw_readings(raw_pressure, raw_temperature)
        print("advanced pressure={} mBar, temperature={} C".format(press, temp))
    time.sleep(1)

结果:

quick'n'easy pressure=835.7 mBar, temperature=26.64 C
advanced pressure=835.3 mBar, temperature=26.64 C
advanced pressure=834.2 mBar, temperature=26.64 C
advanced pressure=835.3 mBar, temperature=26.64 C
advanced pressure=834.2 mBar, temperature=26.64 C
advanced pressure=834.2 mBar, temperature=26.64 C
quick'n'easy pressure=835.1 mBar, temperature=26.65 C
advanced pressure=835.3 mBar, temperature=26.63 C
advanced pressure=837.7 mBar, temperature=26.63 C
advanced pressure=834.2 mBar, temperature=26.63 C
advanced pressure=831.8 mBar, temperature=26.63 C
advanced pressure=835.3 mBar, temperature=26.63 C
...

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Google Billing Library:QueryPurchaseAsync:取消购买的订阅资源未返回   java转换列表mapsturct中的单个对象   java简单算法。我做不好   包含集合的@ManyToMany映射的java JPA2持久性   在Java中序列化和反序列化对象时发生BuffereImage错误   java使用ui:param传递值并在backingbean中访问它们   java从应用程序读取配置。yml至POJO列表地图   java中在while循环外部调用文件值   java如何与来自不同类的UI交互   java如何在jTable中显示2D数组?   在Java 8中,类为什么不从接口继承默认方法?   java类。getAnnotation和getAnnotations无法正常工作   java处理pagertabstrip上的触摸事件   java GWT和struts2异常   用Java解析HTTP查询字符串   java这段代码SQL注入安全吗?