I can read and convert the data, temperature looks accurate however the pressure is completely off, raw data is around 6450000
instead of around 9000000 necessary to calculate real atmospheric pressure around 1000 mbar.
I wrote an Arduino code and verified the math with Excel. I tried a few libraries found on the net. I tried many combination of pullups for I2C which did not make any changes, adjusted I2C speed, and tried a Mega and a Pro Mini 3.3v. Also I have 2 sensors, they give roughly the same result.
Today my BMP058 says 1003 millibar, my real altitude is 53 meter.
Anybody has experienced this with those sensors? Is there a calibration I missed?
But that's not guaranteed to work for another reason: the order of evaluation of subexpressions is not guaranteed, so that you can't be sure which byte gets used where, so you should be doing something like:
ret = Wire.read () ;
ret = (ret << 8) | Wire.read () ;
ret = (ret << 8) | Wire.read () ;
Which forces the order of evaluation (and is also clearer to read, and can be converted into a loop in an obvious fashion:)
ret = 0L ;
for (byte i = 0 ; i < 3 ; i++)
ret = (ret << 8) | Wire.read () ;
Also I'd be more defensive and check the value returned by available and rewrite
I once got sent £50 worth of magnetometer breakouts when I was ordering £10 of a cheaper accelerometer chips - dutifully sent them back though. You got a barometer at least.
Hi,
I have made the changes suggested and it appears to give better values.
However there is some behaviour I don't understand: If you make repeated calls to get the raw temperature you get consistent values. But if you request raw temperature, then request raw pressure and then further requests to get the raw temp the temperature values are different compared to the initial reading by roughly:
912 for the 1st call after the pressure reading;
578 for the 2nd call after the pressure reading;
284 for the 3rd call after the pressure reading.
Which is perhaps roughly 4256, 2256, 1*256 in each case.
I have checked this behaviour with Fabio Varesano's library with the same result. (his code seems to generally return a raw temp that is different by 3*256)
The code follows and I have attached an Excel spreadsheet with results.
Any thoughts welcome.
/*
Example code for using the MS5611 directly.
Copyright (C) 2011 Stephen Bishop
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
SDA (data line) is on analog input pin 4
SCL (clock line) is on analog input pin 5
*/
//#define DEBUG_V
#define ADDRESS 0x76 //Embedded adventures module CSB is VCC so HIGH i.e. 0x76
#include <Wire.h>
uint32_t D1 = 0;
uint32_t D2 = 0;
void setup() {
Wire.begin();
Serial.begin(115200);
delay(1000);
// Embedded adventures module CSB is VCC so HIGH
}
void loop() {
Serial.print(" Direct rawtemp: "); // get raw T
Serial.print(getVal(ADDRESS, 0x58));
Serial.print(" Direct rawpress: "); // remove this line to test effect of pressure reading
Serial.println(getVal(ADDRESS, 0x48)); // remove this line to test effect of pressure reading
Serial.print(" Direct rawtemp: "); // get raw T
Serial.print(getVal(ADDRESS, 0x58));
Serial.print(" Direct rawtemp: "); // get raw T
Serial.print(getVal(ADDRESS, 0x58));
Serial.print(" Direct rawtemp: ");
Serial.println(getVal(ADDRESS, 0x58));
}
uint32_t getVal(int address, byte code)
{
uint32_t ret = 0;
byte b = 0;
Wire.beginTransmission(address);
Wire.send(code); // changed write to send
// Serial.print(code, BIN); // for debuging
//Serial.print(" "); // for debuging
Wire.endTransmission();
delay(10);
// start read sequence
Wire.beginTransmission(address);
// Wire.send((byte) 0x00);
Wire.send(0);
Wire.endTransmission();
Wire.beginTransmission(address);
// Serial.print((uint8_t) 3, BIN); // for debuging
Wire.requestFrom((uint8_t)address, (uint8_t)3);// requestFrom MS5611
if (Wire.available() >= 3)
{
ret = 0L ;
b = 0;
/* // for debuging
Serial.print(b,DEC);
Serial.print(" ");
ret = (ret << 8) | b ;
b = Wire.receive();
Serial.print(b,DEC);
Serial.print(" ");
ret = (ret << 8) | b ;
b = Wire.receive();
Serial.print(b,DEC);
Serial.print(" ");
ret = (ret << 8) | b ;
*/
for (byte i = 0 ; i < 3 ; i++)
{
b = Wire.receive();
// Serial.print(b,DEC); // for debuging
// Serial.print(" "); // for debuging
ret = (ret << 8) | b ;
}
}
else {
ret = -1;
}
Wire.endTransmission();
// Serial.println(ret); // for debuging
return ret;
}