In this article we look at another sensor – this time its the MS5611 and we will connect it to our Beaglebone and we will have a python example
First lets take a look at the sensor in question
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
Parts Required
Name | Link |
Beaglebone | BeagleBone Black TI AM335x Cortex-A8 development BB-Black Rev.C |
MS5611 | |
Connecting wire | Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire |
Schematic/Connection
Beaglebone | Module |
3.3v – P9.3 | Vcc |
Gnd – P9.1 | Gnd |
SDA – P9.20 | SDA |
SCL – P9.19 | SCL |
Code Example
Save this as MS5611.py. My sensor used I2c address 0x77, you may have to change this to 0x76 if you have a different one
[codesyntax lang=”python”]
# Distributed with a free-will license. # Use it any way you want, profit or free, provided it fits in the licenses of its associated works. # MS5611_01BXXX # This code is designed to work with the MS5611_01BXXX_I2CS I2C Mini Module available from ControlEverything.com. # https://www.controleverything.com/content/Analog-Digital-Converters?sku=MS5611-01BXXX_I2CS_A01#tabs-0-product_tabset-2 import smbus import time # Get I2C bus bus = smbus.SMBus(2) # MS5611_01BXXX address, 0x77(118) # 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, 0x76(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]
Output
Run this example and you should see the following.
debian@beaglebone:/var/lib/cloud9/$ python MS5611.py
Pressure : 992.17 mbar
Temperature in Celsius : 21.62 C
Temperature in Fahrenheit : 70.92 F
debian@beaglebone:/var/lib/cloud9/$ python MS5611.py
Pressure : 992.12 mbar
Temperature in Celsius : 21.55 C
Temperature in Fahrenheit : 70.79 F
Links