Skip to main content

Python library for MS5803-14BA pressure sensor for Raspberry Pi over i2c

Project description

MS5803-14BA

ms5803py

Python 3 library for MS5803-14BA pressure sensor for Raspberry Pi over i2c.

Based off of the Adafruit Arduino Library and the Control Everything Python Library. Some of the math is complicated when correcting raw readings to actual temperatures and pressures, that math can be verified from the MS5803-14BA datasheet.

Supports reading the pressure and temperature values from the sensor at any of the supported OverSampling Rates (OSR). A higher OSR leads to greater resolution/accuracy but requires a longer conversion time. The supported OSR rates are [256, 512, 1024, 2048, 4096], also available at MS5803.OSRs.

Installation

Available on PyPi, so you can install on your RPi using

pip3 install ms5803py

or clone this repository and run

python3 setup.py install

Usage

The MS5803 and the RPi use the I2C protocol to communicate, so you need to have I2C set up on your pi, as explained in this Adafruit tutorial. After that, the MS5803 needs to be hooked up to the Raspberry Pi as described in this Adafruit tutorial.

After doing that, you must find the I2C address of your MS5803. To do this, run the following command both before and after plugging in the MS5803. Whatever address shows up is the one you want:

sudo i2cdetect -y 1

It should be either 0X76 or 0x77, as described in the MS5803-14BA datasheet, depending on if the CSB (Chip Select) pin on the MS5803 is high or low. On the Sparkfun breakout board the I2C address is 0x76, so I have that set as the default if you don't specify an address when initializing the sensor.

See python3 example.py for an example of usage:

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)

results in:

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
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ms5803py-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

ms5803py-1.0.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file ms5803py-1.0.0.tar.gz.

File metadata

  • Download URL: ms5803py-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ms5803py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ed68e032e8193904355e08e537e79acc277c9a1b07f2886126e187410f98bde0
MD5 84870ddf89ba3005e26dbb882db21da1
BLAKE2b-256 a58e96c92b91c359a931b81b2c03b9e09df4f4a611e90b5d777691172dc317dc

See more details on using hashes here.

File details

Details for the file ms5803py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ms5803py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for ms5803py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c7e2c6b0191d5772e4ed6bfe800e360dc0975aadbfd7b091dcdb4aaf339533
MD5 858671b139ba033cbd31b1f0feac7a44
BLAKE2b-256 2aea4929914787bc369494cff84e1fe3e60c4eff1650ff62d492f302c84a24a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page