Hello! I have been trying to get the Bar30 sensor running and have been encountering a strange issue.
Hardware setup:
- A Raspberry Pi with the Navigator board plugged in, and with BlueOS installed and running.
- Brand new Bar30 sensor which has never gone underwater before (being tested in air).
- The Bar30 sensor is plugged into an “I2C 6” port on the Navigator
- The only things connected to the Raspberry Pi / Navigator are the Bar 30 sensor, power cable to the Pi, and an ethernet cable to my PC (which runs through an Ethernet switch)
Software setup:
- I am running test code from the Raspberry Pi’s shell
- The test code is a modified version of the code in the Guide to Using the Bar30 with a Raspberry Pi.
- The ms5837.py library file is unchanged.
The test code:
#!/usr/bin/python
import ms5837
import time
sensor = ms5837.MS5837_30BA(6) # Specify I2C bus
if __name__ == "__main__":
while True:
try:
if sensor.init():
break
print("Sensor could not be initialized (No error)")
except:
print("Sensor could not be initialized (Error!)")
sensor.setFluidDensity(ms5837.DENSITY_SALTWATER)
saltwaterDepth = sensor.depth() # No nead to read() again
time.sleep(5)
while True:
try:
if not sensor.read():
raise Exception
print(f"P: {sensor.pressure()}, T: {sensor.temperature()}")
except Exception as e:
print("Sensor read failed! Error received: ")
print(e)
print("")
time.sleep(1)
The result is inconsistent. Sometimes, the sensor works completely fine and sensor.read() always results in a measurement. Other times, every message results in an error. The following is the most common result I’ve seen - 2 errors, followed by 2 packets, one of which may have glitched values:
I have tried
- Making sure the Bar 30’s I2C is at 3.3 V logic (tested with multimeter)
- Checking the device’s I2C address- (0x76 is present)
- Making sure there are no other devices with the same address (
i2cdetect -y 6
) - Running the sensor for several hours. Its behaviour does not seem to change during runtime - if it returns 2 errors followed by 2 messages right after start up, it does so the whole time.
- Replacing the time.sleep() statements with a while loop that checks time.time(), to avoid stopping execution.
What may be the cause behind this? I would appreciate any help. Thank you!