Home        Store        Docs        Blog

Bar30 Pressure Sensor with Beaglebone Black


(Corey) #1

Hi,

I am having a problem detecting the Bar30 pressure sensor on my I2C bus on the Beaglebone black. I have the Vin wire connected to the 3.3V supply on the Beaglebone, the GND wire connected to ground, and the SCL and SDA wires connected to the I2C-1 bus on the Beaglebone Black using 4.7k-Ohm pull-up resistors, with the resistors pulled-up to the same 3.3V supply line that is powering the sensor. Using the linux i2cdetect program I am unable to see the addresses of the Bar30 sensor show up. I know the I2C bus is working because when I connect other I2C devices to the bus I am able to see their addresses using i2cdetect. Does anyone have any ideas what might be wrong?



(Corey) #2

The orange wire in the picture is connected to the 5V source on the Beaglebone. Tested the sensor with Vin wire connected to both the 3.3V source and 5v source, both with the same results…no sensor addresses detected using i2cdetect.


(Jacob) #3

For some reason, the ms5837 isn’t detected with i2cdetect on BBB.

i2cdump will show the data in the registers.

 

-Jacob


(Corey) #4

Thanks. I just moved on to my C code for the sensor since i2cdetect doesn’t work and have been relatively successful in getting the code to work. One exception is that I always receive a checksum error after grabbing the calibration data. I using the same crc4() function from the arduino code as it shouldn’t, to my knowledge, need to be modified to work with my Linux C code. I can post the values I’m getting from the calibration registers a bit later today, but I’m thinking they are correct as I’m getting pressure values of around 1015 mbar in air and room temperature values of around 27 C. Right now I’ll just ignore the checksum error, but it would be nice to get it figured out!

 

Thanks again.


(Corey) #5

I discovered the problem. The CRC function provided on GitHub for the Arduino does not work with my setup because of an error in the GitHub code.

The GitHub code is as follows:

uint8_t MS5837::crc4(uint16_t n_prom[]) {
uint16_t n_rem = 0;

n_prom[0] = ((n_prom[0]) & 0x0FFF);
n_prom[7] = 0;

for ( uint8_t i = 0 ; i < 16; i++ ) {
if ( i%2 == 1 ) {
n_rem ^= (uint16_t)((n_prom[i&gt;&gt;1]) & 0x00FF0); <-- Note this hex value is different from that given in MS5837 Manual
} else {
n_rem ^= (uint16_t)(n_prom[i&gt;&gt;1] >> 8);
}
for ( uint8_t n_bit = 8 ; n_bit > 0 ; n_bit-- ) {
if ( n_rem & 0x8000 ) {
n_rem = (n_rem << 1) ^ 0x3000;
} else {
n_rem = (n_rem << 1);
}
}
}

n_rem = ((n_rem >> 12) & 0x000F);

return (n_rem ^ 0x00);
}

The code from the MS5837 manual is as follows:
uint8_t MS5837::crc4(uint16_t n_prom[]) {
uint16_t n_rem = 0;

n_prom[0] = ((n_prom[0]) & 0x0FFF);
n_prom[7] = 0;

for ( uint8_t i = 0 ; i < 16; i++ ) {
if ( i%2 == 1 ) {
n_rem ^= (uint16_t)((n_prom[i&gt;&gt;1]) & 0x00FF); <-- This is the hex value given in the MS5837 manual
} else {
n_rem ^= (uint16_t)(n_prom[i&gt;&gt;1] >> 8);
}
for ( uint8_t n_bit = 8 ; n_bit > 0 ; n_bit-- ) {
if ( n_rem & 0x8000 ) {
n_rem = (n_rem << 1) ^ 0x3000;
} else {
n_rem = (n_rem << 1);
}
}
}

n_rem = ((n_rem >> 12) & 0x000F);

return (n_rem ^ 0x00);
}

 

I don’t know if the GitHub CRC function actually works on Arduino as I have not tested it, but the CRC code from the MS5837 manual is only different in the noted hex value and changing the value fixed my issues. So if anyone else is having the same trouble you might just need to remove the extra 0 from the specified hex value.


(Simone Nascivera) #6

I have the same issue did you simply copy the arduino cod and compiled on the bbb?


(Corey) #7

Hi Simone,

I had to change the Arduino code to be used for the Beaglebone Black linux system so that the i2c port open, read, and write calls would work correctly, since Arduino i2c library is not compatible with the Linux system as far as I know. The code isn’t changed significantly from the Arduino code though. The cpp and header files I made by modifying the Arduino code are attached. I hope they help!

bar30-2 (2.98 KB)


(Corey) #8

Apparently cpp files aren’t allowed to be uploaded. So here is a cpp file given as a .txt extension rename to “Bar30.cpp” if you use it.

bar30-3 (6.84 KB)


(Simone Nascivera) #9

Hi, after some work i finally connected successfully the sensor to the bbb but there is some problems. The strange thing is that the script recognize the sensor and print out the value stored for the calibration, but the pressure value and the other measurement are completely wrong. I havent’t changed the script apart the i2c bus. This is the output I got:

Waiting for PRESSURE SENSOR to initialize…

PRESSURE SENSOR initialized!

Reading and storing calibration data…

C[0] = 36865
C[1] = 34254
C[2] = 32430
C[3] = 20412
C[4] = 20253
C[5] = 26110
C[6] = 26628
Calibration data stored. Checking CRC…

CRC Recv’d: 9, CRC Calc: 9

Calibration Values CRC Check Success!
Setup complete!

0
0
44307.7

The final 3 values are the pressure, temperature and the altitude. I attacch the script I compiled with Bar30.cpp

Could you help me?

Thank you,

Simone

 

 

init_temp.cpp:

 

#include<iostream>
#include "Bar30.h"
using namespace std;

MS5837 sensor;

void reset(){
sensor.init();
sensor.setFluidDensity(1024);
}
int main()
{
reset();
cout << sensor.temperature() << endl;
cout << sensor.pressure(100) << endl;
cout << sensor.altitude() << endl;

return 0;
}


(Corey) #10

Hi,

You need to call the function read_pressure() before querying the pressure, temp, or depth, and it has to be called again each time you want the sensor to update it’s register values with the newest information.

So, in your case, you need to put

sensor.read_pressure ();

before your sensor.temperature () line.

 

Oh, and it its highest resolution you can only query at about 200Hz max. Hope this helps.