Hi all, I am new to Arduino
I am trying to make an Model Rocket Flight Computer
I Use an Arduino Nano, an BMP280 and MPU6050 to measure Altitude and Speed
It show it on an small I2C OLED Display
It should show the live data on the display for the first 10 minutes
And after 10 minutes it then should show the Max Altitude and the Max Speed.
I can't get the Altitude and Speed to update on the display, it just keep saying 0.00
and of course after the 10 min. it still say 0.00
BMP280, MPU6050, OLED Display
Is conected to:
VCC to 5V on Arduino Nano
GND to GND
SDA to A4
SCL to A5
The LED is on Pin 13
I hope that someone can help me #include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP280.h>
#include <Wire.h>
#include <MPU6050.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
Adafruit_BMP280 bmp;
MPU6050 mpu;
const int ledPin = 13;
float altitude;
float speed;
int maxAltitude = 0;
int maxSpeed = 0;
unsigned long startTime = 0;
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.initialize();
bmp.begin();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, HIGH);
startTime = millis();
}
void loop() {
unsigned long elapsedTime = millis() - startTime;
int secondsElapsed = elapsedTime / 1000;
if (secondsElapsed < 10) { // Display startup message for 10 seconds
display.clearDisplay();
display.setCursor(0, 0);
display.println("0RocketFlightComputer");
display.display();
}
else if (secondsElapsed < 600) { // Display current altitude and speed for first 10 minutes
int16_t accelY = mpu.getAccelerationY();
float accel = accelY / 16384.0 * 9.81; // convert to m/s^2
altitude = bmp.readAltitude(1013.25);
speed = accel * altitude;
if (isnan(altitude) || isinf(altitude)) {
altitude = 0;
}
if (isnan(speed) || isinf(speed)) {
speed = 0;
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("RocketFlightComputer1");
display.setCursor(0,10);
display.print("Altitude: " + String(altitude, 2));
// display.println(altitude, 2);
display.setCursor(0,20);
display.print("Speed: " + String(speed, 2));
// display.println(speed, 2);
display.display();
}
else { // Display maximum altitude and speed after 10 minutes
if (altitude > maxAltitude) {
maxAltitude = altitude;
}
if (speed > maxSpeed) {
maxSpeed = speed;
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("RocketFlightComputer2");
display.setCursor(0,10);
display.println("Max Altitude: " + String(maxAltitude) + " m");
display.setCursor(0,20);
display.println("Max Speed: " + String(maxSpeed) + " m/s");
display.display();
}
delay(100);
}
Test setup