Guide to Using the Bar02 with a Raspberry Pi
Introduction
The Bar02 pressure sensor is a pressure sensor designed to be used underwater at pressures up to 2 bar, or around 10 meters depth in water. It communicates via I2C and comes with a 4-pin DF-13 connector that is compatible with the Pixhawk autopilot, the Level Converter and other microcontrollers.
Example Code
This example uses the BlueRobotics MS5837 Python Library with the sensor connected to a Raspberry Pi. The Raspberry Pi uses 3.3V logic levels on the I2C pins, so a logic level shifter is not required.import ms5837 import time sensor = ms5837.MS5837_02BA() # Default I2C bus is 1 (Raspberry Pi 3) # We must initialize the sensor before reading it if not sensor.init(): print("Sensor could not be initialized") exit(1) # Print readings while True: if sensor.read(): print(("P: %0.1f mbar %0.3f psi\tT: %0.2f C %0.2f F") % ( sensor.pressure(), # Default is mbar (no arguments) sensor.pressure(ms5837.UNITS_psi), # Request psi sensor.temperature(), # Default is degrees C (no arguments) sensor.temperature(ms5837.UNITS_Farenheit))) # Request Farenheit else: print("Sensor read failed!") exit(1)