working with R and 0's when no sensor present

pull/58/head
alanbjohnston 5 years ago committed by GitHub
parent 0f3fe767c2
commit 107553e855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,6 +12,7 @@ MPU6050 mpu6050(Wire);
int counter = 0; int counter = 0;
long timer = 0; long timer = 0;
int bmePresent;
void setup() { void setup() {
@ -26,9 +27,11 @@ void setup() {
delay(50); // wait for a second delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off digitalWrite(PC13, HIGH); // turn the LED off
if (!bme.begin(0x76)) { if (bme.begin(0x76)) {
bmePresent = 1;
} else {
Serial.println("Could not find a valid BME280 sensor, check wiring!"); Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1); bmePresent = 0;
} }
mpu6050.begin(); mpu6050.begin();
@ -39,22 +42,30 @@ void loop() {
#ifdef TESTING #ifdef TESTING
if (Serial.available() > 0) { if (Serial.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial.read(); char result = Serial.read();
// Serial1.println(result); // Serial.println(result);
Serial.print("OK BME280 ");
Serial.print(bme.readTemperature()); if (result == 'R') {
Serial.print(" "); Serial.println("OK");
Serial.print(bme.readPressure() / 100.0F); delay(500);
Serial.print(" "); setup();
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); }
Serial.print(" "); if (bmePresent) {
Serial.print(bme.readHumidity()); Serial.print("OK BME280 ");
Serial.print(bme.readTemperature());
Serial.print(" ");
Serial.print(bme.readPressure() / 100.0F);
Serial.print(" ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.print(" ");
Serial.print(bme.readHumidity());
} else
{
Serial.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update(); mpu6050.update();
Serial.print(" MPU6050 "); Serial.print(" MPU6050 ");
@ -68,24 +79,30 @@ void loop() {
} }
#else #else
if (Serial1.available() > 0) { if (Serial1.available() > 0) {
digitalWrite(PC13, LOW); // turn the LED on digitalWrite(PC13, LOW); // turn the LED on
delay(50); // wait for a second delay(50); // wait for a second
digitalWrite(PC13, HIGH); // turn the LED off digitalWrite(PC13, HIGH); // turn the LED off
char result = Serial1.read(); char result = Serial1.read();
// Serial1.println(result); // Serial1.println(result);
// Serial1.println("OK ");
Serial1.print("OK BME280 ");
Serial1.print(bme.readTemperature());
Serial1.print(" ");
Serial1.print(bme.readPressure() / 100.0F);
Serial1.print(" ");
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial1.print(" ");
Serial1.print(bme.readHumidity());
if (result == 'R') {
Serial1.println("OK");
delay(500);
setup();
}
if (bmePresent) {
Serial1.print("OK BME280 ");
Serial1.print(bme.readTemperature());
Serial1.print(" ");
Serial1.print(bme.readPressure() / 100.0F);
Serial1.print(" ");
Serial1.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial1.print(" ");
Serial1.print(bme.readHumidity());
} else
{
Serial1.print("OK BME280 0.0 0.0 0.0 0.0");
}
mpu6050.update(); mpu6050.update();
Serial1.print(" MPU6050 "); Serial1.print(" MPU6050 ");

Loading…
Cancel
Save

Powered by TurnKey Linux.