Hi guys!
I think im in the right thread. I am relatively new to arduino and programming in general although i have had a class in c++.
I am trying to write a code that sets the altitude of a bmp2805 sensor to zero and then will give the altitude based on how high the sensor is.
Here is my code:
#include <Wire.h> //adding libraries that are needed
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; //Initialized BMP280 Sensor
void setup() {
Serial.begin(9600); //Checking the BMP280 Sensor to see if it is connect and operational
Serial.println(F("*****************"));
Serial.println(F("Checking BMP280 Sensor..."));
if (!bmp.begin()) { //Sensor cannot befound or not operating, check the wiring
Serial.println(F("SENSOR NOT FOUND"));
while(1);
}
if (bmp.begin()) { //Sensor is found and sending signal
Serial.println(F("SENSOR FOUND"));
Serial.println(F("*****************"));
Serial.println();
}
}
void loop() {
float ground;
float locAlt;
for(ground=0; ground=0 ; ) { //setting ground to the initial Altitude Above Sea-Level
ground = bmp.readAltitude(1025.0);
}
locAlt=bmp.readAltitude(1025.0)-ground;
Serial.print(F("Temperature= ")); //displays temp in C
Serial.print(bmp.readTemperature());
Serial.println(F("C"));
Serial.print(F("Pressure= ")); //displays pressure in Pa
Serial.print(bmp.readPressure());
Serial.println(F("Pa"));
Serial.print(F("Approx. Altitude ASL= ")); //displays Altitude ASL in m
Serial.print(bmp.readAltitude(1025.0));
Serial.println(F("m"));
Serial.print(F("Approx. local Altitude= ")); //displays the altitude of the sensor to the ground and not sea-level
Serial.print(bmp.readAltitude(1025.0)-ground);
Serial.println("m");
Serial.println();
delay(1000);
}
it complies but in the serial monitor it does not the correct altitude. Im not sure what im am doing wrong. I would like for the program to take the initial altitude (ASL) and set it to the ground variable and then every time it takes a measurement it will subtract ground from it. this in theory should give me the altitude of the sensor from the ground and not sea level. I am thinking that i am running into problems in my for loop.
I was thinking if there is a way to only take the ground measurement once from setup and then set it to ground and send that data to the void loop.