I can't figure how to change settings for top OSR?
According to the datasheet it must be 4096 for better precision.
I can't make this settings work.
Could anyone help?
#include <Wire.h>
#include "U8glib.h"
const byte sock_SCL = 7;
const byte mosi_SI = 6;
const byte cs_CS = 5;
const byte a0_A0 = 4;
const byte reset_RESET = 3;
U8GLIB_NHD_C12864_2X u8g(sock_SCL, mosi_SI, cs_CS, a0_A0, reset_RESET); // LCD WIRES
boolean vreset_hist = false;
const float sea_press = 1013.25;
float temperatura;
float press;
long pressao_int;
long vtempo_tela_historico = millis();
unsigned int calibrationData[7];
unsigned long time = 0;
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
setupSensor();
Serial.begin(9600);
Wire.begin();
}
void loop() {
long D1, D2, dT, P;
float TEMP;
int64_t OFF, SENS;
D1 = getData(0x48, 10);
D2 = getData(0x50, 1);
dT = D2 - ((long)calibrationData[5] << 8);
TEMP = (2000 + (((int64_t)dT * (int64_t)calibrationData[6]) >> 23)) / (float)100;
OFF = ((unsigned long)calibrationData[2] << 16) + (((int64_t)calibrationData[4] * dT) >> 7);
SENS = ((unsigned long)calibrationData[1] << 15) + (((int64_t)calibrationData[3] * dT) >> 8);
P = (((D1 * SENS) >> 21) - OFF) >> 15;
pressao_int = P;
press = pressao_int * 0.01;
temperatura = TEMP;
Serial.println(temperatura);
Serial.println(press);
delay(100);
return;
}
void setupSensor()
{
twiSendCommand(0x77, 0x1e);
delay(100);
for (byte i = 1; i <= 6; i++)
{
unsigned int low, high;
twiSendCommand(0x77, 0xa0 + i * 2);
Wire.requestFrom(0x77, 2);
if (Wire.available() != 2)
delay(8);
////////Serial.println("Error: calibration data not available");
high = Wire.read();
low = Wire.read();
calibrationData[i] = high << 8 | low;
}
}
void getPressure()
{
long D1, D2, dT, P;
float TEMP;
int64_t OFF, SENS;
D1 = getData(0x48, 10);
D2 = getData(0x50, 1);
dT = D2 - ((long)calibrationData[5] << 8);
TEMP = (2000 + (((int64_t)dT * (int64_t)calibrationData[6]) >> 23)) / (float)100;
OFF = ((unsigned long)calibrationData[2] << 16) + (((int64_t)calibrationData[4] * dT) >> 7);
SENS = ((unsigned long)calibrationData[1] << 15) + (((int64_t)calibrationData[3] * dT) >> 8);
P = (((D1 * SENS) >> 21) - OFF) >> 15;
pressao_int = P;
press = pressao_int * 0.01;
temperatura = TEMP;
}
long getData(byte command, byte del)
{
long result = 0;
twiSendCommand(0x77, command);
delay(del);
twiSendCommand(0x77, 0x00);
Wire.requestFrom(0x77, 3);
if (Wire.available() != 3) delay(8);////////Serial.println("Error: raw data not available");
for (int i = 0; i <= 2; i++)
{
result = (result << 8) | Wire.read();
}
return result;
}
void twiSendCommand(byte address, byte command)
{
Wire.beginTransmission(address);
if (!Wire.write(command)) delay(10);// //////Serial.println("Error: write()");
if (Wire.endTransmission())
{
}
}
float getAltitude(float press, float temp) {
return ((pow((sea_press / press), 1 / 5.257) - 1.0) * (temp + 273.15)) / 0.0065;
}
ENG_DS_MS5611-01BA03_B3.pdf (583 KB)