Home Code Raspberry Pi and MS5611 barometric pressure sensor example

Raspberry Pi and MS5611 barometric pressure sensor example

by shedboy71

This barometric pressure sensor is optimized for altimeters and variometers with an altitude resolution of 10 cm. The sensor module includes a high linearity pressure sensor and an ultra-low power 24 bit ΔΣ ADC with internal factory calibrated coefficients. It provides a precise digital 24 Bit pressure and temperature value and different operation modes that allow the user to optimize for conversion speed and current consumption. A high resolution temperature output allows the implementation of an altimeter/thermometer function without any additional sensor. The MS5611-01BA can be interfaced to virtually any microcontroller. The communication protocol is simple, without the need of programming internal registers in the device.

Small dimensions of only 5.0 mm x 3.0 mm and a height of only 1.0 mm allow for integration in mobile devices. This new sensor module generation is based on leading MEMS technology and latest benefits from MEAS Switzerland proven experience and know-how in high volume manufacturing of altimeter modules, which have been widely used for over a decade. The sensing principle employed leads to very low hysteresis and high stability of both pressure and temperature signal.

features

 

  • High resolution module, 10 cm
  • Fast conversion down to 1 ms
  • Low power, 1 µA (standby < 0.15 µA)
  • QFN package 5.0 x 3.0 x 1.0 mm3
  • Supply voltage 1.8 to 3.6 V
  • Integrated digital pressure sensor (24 bit ΔΣ ADC)
  • Operating range: 10 to 1200 mbar, -40 to +85 °C
  • I2C and SPI interface up to 20 MHz
  • No external components (Internal oscillator)
  • Excellent long term stability

 

 

Connection

Raspberry Pi Module connection
3v3 Vcc
Gnd Gnd
SCL SCL
SDA SDA

 

Code

This example comes from https://github.com/ControlEverythingCommunity/MS5611-01BXXX

My module uses I2C address 0x77, so the code had to be modified

[codesyntax lang=”python”]

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# MS5611_01BXXX address, 0x77(119)
# 0x1E(30) Reset command
bus.write_byte(0x77, 0x1E)

time.sleep(0.5)

# Read 12 bytes of calibration data
# Read pressure sensitivity
data = bus.read_i2c_block_data(0x77, 0xA2, 2)
C1 = data[0] * 256 + data[1]

# Read pressure offset
data = bus.read_i2c_block_data(0x77, 0xA4, 2)
C2 = data[0] * 256 + data[1]

# Read temperature coefficient of pressure sensitivity
data = bus.read_i2c_block_data(0x77, 0xA6, 2)
C3 = data[0] * 256 + data[1]

# Read temperature coefficient of pressure offset
data = bus.read_i2c_block_data(0x77, 0xA8, 2)
C4 = data[0] * 256 + data[1]

# Read reference temperature
data = bus.read_i2c_block_data(0x77, 0xAA, 2)
C5 = data[0] * 256 + data[1]

# Read temperature coefficient of the temperature
data = bus.read_i2c_block_data(0x77, 0xAC, 2)
C6 = data[0] * 256 + data[1]

# MS5611_01BXXX address, 0x77(118)
# 0x40(64) Pressure conversion(OSR = 256) command
bus.write_byte(0x77, 0x40)

time.sleep(0.5)

# Read digital pressure value
# Read data back from 0x00(0), 3 bytes
# D1 MSB2, D1 MSB1, D1 LSB
value = bus.read_i2c_block_data(0x77, 0x00, 3)
D1 = value[0] * 65536 + value[1] * 256 + value[2]

# MS5611_01BXXX address, 0x76(118)
# 0x50(64) Temperature conversion(OSR = 256) command
bus.write_byte(0x77, 0x50)

time.sleep(0.5)

# Read digital temperature value
# Read data back from 0x00(0), 3 bytes
# D2 MSB2, D2 MSB1, D2 LSB
value = bus.read_i2c_block_data(0x77, 0x00, 3)
D2 = value[0] * 65536 + value[1] * 256 + value[2]

dT = D2 – C5 * 256
TEMP = 2000 + dT * C6 / 8388608
OFF = C2 * 65536 + (C4 * dT) / 128
SENS = C1 * 32768 + (C3 * dT ) / 256
T2 = 0
OFF2 = 0
SENS2 = 0

if TEMP >= 2000 :
T2 = 0
OFF2 = 0
SENS2 = 0
elif TEMP < 2000 :
T2 = (dT * dT) / 2147483648
OFF2 = 5 * ((TEMP – 2000) * (TEMP – 2000)) / 2
SENS2 = 5 * ((TEMP – 2000) * (TEMP – 2000)) / 4
if TEMP < -1500 :
OFF2 = OFF2 + 7 * ((TEMP + 1500) * (TEMP + 1500))
SENS2 = SENS2 + 11 * ((TEMP + 1500) * (TEMP + 1500)) / 2

TEMP = TEMP – T2
OFF = OFF – OFF2
SENS = SENS – SENS2
pressure = ((((D1 * SENS) / 2097152) – OFF) / 32768.0) / 100.0
cTemp = TEMP / 100.0
fTemp = cTemp * 1.8 + 32

# Output data to screen
print “Pressure : %.2f mbar” %pressure
print “Temperature in Celsius : %.2f C” %cTemp
print “Temperature in Fahrenheit : %.2f F” %fTemp

[/codesyntax]

You can download the file – ms5611

Output

Run this by typing in sudo python ms5611.py

ms5611 output

ms5611 output

Link

GY-63 MS5611-01BA03 Precision MS5611 Atmospheric Pressure Sensor Module Height Sensor Module

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More