after using this, it appears that the absolute altitude is the nan value and the relative value is at 0.00 meters
The absolute altitude is the nan and the relative altitude is at 0.00 meters
Hi,
Have you looked at the link I left in post #18?
The link even gives you code for getting all the available info out of the sensor.
Also it does the display without Strings.
Copy and paste it into a fresh code page and see what it does...
Tom...
![]()
Where did you get the MS5611 library from ?
Hi,
Its available in the IDE Library manager, Rob Tillaard.
Tom...
![]()
PS. I'm off to bed, way too late here.
I don't think that is the library that @rocketsrocketsrockets is using because the code will not compile with that library
Thats what i did and thats what happened when I put it in. Ill try putting it into a fresh code later
I got it from the place I got the code. It was in an instructables project
Please post a link to the project
The altitude just stays at 0.0 meters for relative altitude, and for absolute altitude there is no value
I am not clear what version of the code that comment relates to. Please clarify or post it in a reply
#include <Wire.h>
#include <MS5611.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include <SPI.h>
#include <SD.h>
#include <Servo.h>
Servo myServo;
int state = 0;
unsigned long time;
const int chipSelect = 4;
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
MPU6050 accelgyro;
//MPU6050 accelgyro(0x69); // <-- use for AD0 high
#define OUTPUT_READABLE_ACCELGYRO
int16_t ax, ay, az;
int16_t gx, gy, gz;
MS5611 ms5611;
double referencePressure;
#define LED_PIN 13
bool blinkState = false;
void setup()
{
myServo.attach(9);
myServo.write(0);
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Serial.begin(9600);
// Initialize MS5611 sensor
Serial.println("Initialize MS5611 Sensor");
while (!ms5611.begin())
{
Serial.println("Could not find a valid MS5611 sensor, check wiring!");
delay(500);
}
// Get reference pressure for relative altitude
referencePressure = ms5611.readPressure();
// Check settings
checkSettings();
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
pinMode(LED_PIN, OUTPUT);
Serial.print("Initializing SD card...");
if (!SD.begin(chipSelect)) {// see if the card is present and can be initialized:
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}
void checkSettings()
{
Serial.print("Oversampling: ");
Serial.println(ms5611.getOversampling());
}
void loop()
{
// read raw accel measurements from device
accelgyro.getAcceleration(&ax, &ay, &az);
// Read raw values
uint32_t rawTemp = ms5611.readRawTemperature();
uint32_t rawPressure = ms5611.readRawPressure();
// Read true temperature & Pressure
double realTemperature = ms5611.readTemperature();
long realPressure = ms5611.readPressure();
// Calculate altitude
float absoluteAltitude = ms5611.getAltitude(realPressure);
float relativeAltitude = ms5611.getAltitude(realPressure, referencePressure);
Serial.println("--");
Serial.print(" rawTemp = ");
Serial.print(rawTemp);
Serial.print(", realTemp = ");
Serial.print(realTemperature);
Serial.println(" *C");
Serial.print(" rawPressure = ");
Serial.print(rawPressure);
Serial.print(", realPressure = ");
Serial.print(realPressure);
Serial.println(" Pa");
Serial.print(" absoluteAltitude = ");
Serial.print(absoluteAltitude);
Serial.print(" m, relativeAltitude = ");
Serial.print(relativeAltitude);
Serial.println(" m");
//change variables to strings
String comma = String (',');
String absol = String (relativeAltitude); //absoloute altitude in meters.
String temp = String ( ms5611.readTemperature()); //real temp in degrees, may over read initially, will take time for sensor to stabilize.
String realpressure = String (ms5611.readPressure()); // pressure in pascals
String accelXraw = String (ax); // raw accel in X. Divide by 2048 to get a "G" reading.
String timer = String (millis()); //puts a millis time stamp on each string.
//make a big string containing above strings
String Baro_data = String (absol + comma + temp + comma + realpressure + comma + accelXraw + comma + timer) ;
Serial.println (Baro_data);
//delay(500);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(Baro_data);//put Baro_data on the SD card
dataFile.close();
if (millis() > 10000) //change this number to change alarm delay (1s = 1000ms)
{ tone (8, 1000); // change the second number to alter the tone of the peizo alarm
}
else {
noTone(8);
}
}
if(ms5611.getAltitude(realPressure) >= 1){
myServo.write(90);
}
else{
myServo.write(0);
}
}
You still have 2 different variables named realPressure, one a String and another a long
What does the printout from this section of code look like ?
Serial.println("--");
Serial.print(" rawTemp = ");
Serial.print(rawTemp);
Serial.print(", realTemp = ");
Serial.print(realTemperature);
Serial.println(" *C");
Serial.print(" rawPressure = ");
Serial.print(rawPressure);
Serial.print(", realPressure = ");
Serial.print(realPressure);
Serial.println(" Pa");
Serial.print(" absoluteAltitude = ");
Serial.print(absoluteAltitude);
Serial.print(" m, relativeAltitude = ");
Serial.print(relativeAltitude);
Serial.println(" m");
which part should I replace with this?
That all came from your sketch. I was enquiring that was printed from it
It printed out basically the same stuff that I had gotten earlier.
Please humour me and post the output again
Initialize MS5611 Sensor
10:13:55.238 -> Oversampling: 6
10:13:55.238 -> Initializing I2C devices...
10:13:55.272 -> Testing device connections...
10:13:55.306 -> MPU6050 connection successful
10:13:55.339 -> Initializing SD card...Card failed, or not present
10:13:57.339 -> --
10:13:57.339 -> rawTemp = 0, realTemp = -134.24 *C
10:13:57.373 -> rawPressure = 0, realPressure = -10968 Pa
10:13:57.405 -> absoluteAltitude = nan m, relativeAltitude = 0.00 m
10:13:57.473 -> 0.00,-134.24,-10968,-114,2317
Thanks
My conclusion from seeing those figures is that that there is a problem with either the sensor or with your wiring
For instance, the pressures look way off. Is the pressure really likely to be 0 or -10968 and the same with the temperatures ? In turn, the pressure is used in the calculation of altitude and we know that if you substitute say 1000 for realPressure you get a number for altitude rather than NaN