Home        Store        Docs        Blog

Installing Bar30 Sensor Library Python


#1

I recently purchased a Bar30 pressure sensor. I am pretty new to raspberry pi’s so I don’t know how to install libraries off of github. Where should I clone the library to and what else do I have to do to install it?


(Andrew) #2

Hi NIW

The Blue Robotics page is fairly straight forward and the sensor works very well on the Raspberry PI 3.

As per the link (https://github.com/bluerobotics/ms5837-python), you just need issue the following command to download the library:

sudo apt-get install python-smbus

After that a simple Python script can be used as per the example (http://docs.bluerobotics.com/bar30/#python). Mine is below - its probably not as technically elegant as it could be but it does the job:

Import ms5837
import time

sensor = ms5837.MS5837_30BA() # Default I2C bus is 1 (Raspberry Pi 3)

# We must initialize the sensor before reading it
if not sensor.init():
        with open ("/home/pi/deepsouth/logs/waterdepth.txt", "w") as waterdepth:
                                waterdepth.write("Not Available")
                                waterdepth.close
        with open ("/home/pi/deepsouth/logs/watertemp.txt", "w") as watertemp:
                                watertemp.write("Not Available")
                                watertemp.close
        with open ("/home/pi/deepsouth/logs/waterpressure.txt", "w") as waterpressure:
                                waterpressure.write("Not Available")
                                waterpressure.close
        print "Water Depth, Temperature, and Pressure not available"
        exit(1)

# Print readings
while True:
        if sensor.read():
                with open ("/home/pi/deepsouth/logs/waterdepth.txt", "w") as waterdepth:
                                waterdepth.write("%s" % (round(sensor.depth(),1)))
                                waterdepth.close
                with open ("/home/pi/deepsouth/logs/watertemp.txt", "w") as watertemp:
                                watertemp.write("%s" % (round(sensor.temperature(),1)))
                                watertemp.close
                with open ("/home/pi/deepsouth/logs/waterpressure.txt", "w") as waterpressure:
                                waterpressure.write("%s" % (round(sensor.pressure(ms5837.UNITS_psi),3)))
                                waterpressure.close
                print ("External sensor recording to logfiles P: %0.3f psi\tT: %0.2f C D: %0.1f m") % (
                sensor.pressure(ms5837.UNITS_psi), # Request psi
                sensor.temperature(), # Default is degrees C (no arguments)
                sensor.depth()) 
                time.sleep(1)

        else:
                print "External sensor read failed!"
                exit(1)

Good luck!


#3

I probably should have specified which library, sorry my bad. I have python smbus installed, but idk how to install the ms5837 library.
Thanks.


(Jacob) #4

git clone https://github.com/bluerobotics/ms5837-python

I’ll update the README


#5

Is that all I need to do, or do I need to install it some way?

Edit: Just to clarify, in libraries I have installed previously I had to run a setup.py program before it would work. I am wondering if there are any installation files I should run to get the library to work.

Edit 2: I downloaded the library. When I ran example.py it worked great. However when I tried to import the library from another directory (/home/pi) it could not import.


#6

Also one more thing. I have another i2c device attached (adafruit servo controller hat). I am using it to control my speed controllers. Will that cause any problems with the sensor?


(Jacob) #7

Just to clarify, in libraries I have installed previously I had to run a setup.py program before it would work. I am wondering if there are any installation files I should run to get the library to work.

This repository is not set up as a package, so there is no installation with setup.py.

I downloaded the library. When I ran example.py it worked great. However when I tried to import the library from another directory (/home/pi) it could not import.

As above, it cannot be installed, so you will need to put the files where you want them to live and use them that way. You will need to put them in the same folder as your script if you want to import them as a module.

I have another i2c device attached (adafruit servo controller hat). I am using it to control my speed controllers. Will that cause any problems with the sensor?

There should not be any problems if the devices have unique addresses. Your program will need to arbitrate bus access so that only one sensor is communicating at a time.


#8

Ok thanks for the help!