Hi
I have hooked up this cool sensor and used calculation as suggested by the datasheet. But the result is way off . I suppose problem has to be in type of the variables , but cannot find the cause... pls help
readout of the calibration values dec/hex:
ac5 = 25186 / 0x6262
ac6 = 17528 / 0x4478
mc = -11075 / 0xD4BD
md = 9 / 0x0009
long x1, x2, b5;
unsigned int ac5, ac6;
int mc, md, temperature;
Perhaps you have seen the Adafruit BMP085 Unified driver? It's a really solid driver, I've been using it for a while and always get readings within +/-3*C. I posted the link to the github repo below. You might want to look over the code and compare it with your implementation, although I recommend not reinventing the wheel (it's an anti-pattern).
Just put it in your sketches folder. If you need anyhelp understanding the code, I'd be more than willing to help :).
i was going once again through the code, taking special attention to the variables type, with no success though. I must have been missing something obvious
The only difference that I see between your code and the driver posted by Adafruit is that you have declared the variable temperature to be an int, whereas Adafruit declared the t variable (analogous to your temperature variable) a float. Those arithmetic operations won't always produce an integer value, so I would recommend changing that variable to a float. More than likely you are truncating the decimal value, which is why it is rounding down by one.
Not sure if you realise, you have to read those calibration constants from the device that YOU have. Don't use the ones which appear in any example code.
The reason why your value for "md" is no good, is because in your ridiculous code, you read the calibration bytes 0 through 19, and then byte 21. You don't read byte 20 at all.