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?
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.
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!
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>>1]) & <em><strong>0x00FF0</strong></em>); <em><strong><-- Note this hex value is different from that given in MS5837 Manual</strong></em>
} else {
n_rem ^= (uint16_t)(n_prom[i>>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>>1]) & <em><strong>0x00FF</strong></em>); <em><strong><-- This is the hex value given in the MS5837 manual</strong></em>
} else {
n_rem ^= (uint16_t)(n_prom[i>>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.
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!
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:
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.