Go Down

Topic: Execution freezes using BMP280 (Read 67 times) previous topic - next topic

QuantumJump

Hi,
I wanted to quickly make an airflow velocity measuring device / altimeter (kinda like a pitot tube but in really bad) for fun using 2 BMP280 pressure sensors that I had.

I know these sensors aren't build for that but I just wanted to see what I could do with them as they're the only pressure sensors I have right now : I'm not expecting any accuracy.
Though, suggestions for a better total pressure sensor are always welcome :)



This is my main issue :

The program I have yields believable results : the sensors are working, the wiring should be correct.
During tests to see if it can detect any differences in pressure, which consist of blowing towards the sensor through a straw (yeah...), sometimes the program freezes and stop working for seconds up to minutes.
It stays like that, no matter if I unplug/restart everything or not, and then start working again.

I'm guessing it has either to do with the sensor's maximum range of 1100 hPa, as it happens only if I'm blowing or my wiring/soldering as I'm touching the sensor when testing.

But to reach that total pressure from 1013,25 hPa, I would need to blow faster than the speed of sound (about 380m/s) and I doubt even help from a pressure build-up in the straw could make me reach that...

I also can manipulate the sensor much more roughly without issues when I'm not testing and nothing happens...

The only way I found to reproduce that behavior ould be to unplug the VCC / Ground wires but keep the SCL/SDA wires. I tried to resolder the VCC/Ground pins as well as I could, but the issue remains.
I also tried to resolder everything now thrice and moving the wires to other breadboards.

I'm making sure it's not something in the program ; I still suspect the wiring/soldering but I'm getting a bit unsure about everything :/




A lot secondary, I'd love some suggestions on how I could better correct the "bias" there is from the static and total sensor when the device isn't moving to get a velocity as close to 0 as possible. The average I use kinda works (I went from 16m/s when static to about 0 to 4) but there's probably a better way ?




Here's the full code ; thx a lot for any help/advice :)
Code: [Select]
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK  (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS   (10)

Adafruit_BMP280 static_sensor;
Adafruit_BMP280 total_sensor;

float sensor_bias;
float ground_level_static_pressure;

float static_pressure;
float total_pressure;
float dynamic_pressure;

float air_temperature;
float air_density;

float airspeed;
float altitude;

void setup() {
  Serial.begin(9600);
  Serial.println(F("Checking sensors connection..."));

  if (!static_sensor.begin(0x76)) {
    Serial.println(F("Could not find the static sensor at address 0x76, check wiring!"));
    while (1);
  }
  else Serial.println(F("Detected static sensor at adress 0x76."));
  
  if (!total_sensor.begin(0x77)) {
    Serial.println(F("Could not find the static sensor at address 0x77, check wiring!"));
    while (1);
  }
  else Serial.println(F("Detected dynamic sensor at adress 0x77."));
  
  Serial.println(F("All sensors connected."));

  Serial.println(F("Setting up sensors..."));

  /* Default settings from datasheet. */
  /* Total pressure sensor setup */
  static_sensor.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X1,               /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X1,              /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_OFF,                /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_1);             /* Standby time, (0.5ms → MS_1 ; 62.5ms → MS_63) */

  /* Static pressure sensor setup */
  total_sensor.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X1,              /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X1,             /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_OFF,               /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_1);            /* Standby time, (0.5ms → MS_1 ; 62.5ms → MS_63) */
  
  Serial.println(F("Calculating sensor bias..."));
  
  /* Sensors static bias correction */
  int f_sensor_bias = total_sensor.readPressure() - static_sensor.readPressure(); /* Unused value : sensors will yield 0 when reading for the first time. */
  
  for (int i = 0; 1000 > i; i++)
  {
    sensor_bias += total_sensor.readPressure() - static_sensor.readPressure();
  }
  sensor_bias /= (float) 1000;

  /* Ground level static pressure reading */
  ground_level_static_pressure = static_sensor.readPressure();

}

void loop() {
  /* Reading sensor data */
  static_pressure = static_sensor.readPressure();
  total_pressure = total_sensor.readPressure();
  air_temperature = static_sensor.readTemperature();

  /* Airspeed indicator : Airspeed approximation */
  air_density = static_pressure / (287.05 * (air_temperature + 273.15));
  dynamic_pressure = total_pressure - static_pressure;
  airspeed = sqrt((2 * abs(dynamic_pressure - sensor_bias)) / air_density);
  Serial.print(F("Airspeed = "));
  Serial.print(airspeed);
  Serial.println(F(" m/s"));

  /* Altimeter : Altitude reading. */
  altitude = static_sensor.readAltitude(ground_level_static_pressure  / 100);
  Serial.print(F("Approx altitude = "));
  Serial.print(altitude);
  Serial.println(F(" m"));

  /* Debugging : All variables printing. */
/*
  Serial.print(F("Static pressure = "));
  Serial.print(static_pressure);
  Serial.println(F(" Pa"));

  Serial.print(F("Total pressure = "));
  Serial.print(total_pressure);
  Serial.println(F(" Pa"));

  Serial.print(F("Dynamic pressure = "));
  Serial.print(dynamic_pressure);
  Serial.println(F(" Pa"));

  Serial.print(F("Corrected dynamic pressure = "));
  Serial.print(dynamic_pressure - sensor_bias);
  Serial.println(F(" Pa"));

  Serial.print(F("Air temperature = "));
  Serial.print(air_temperature);
  Serial.println(F(" °C"));

  Serial.print(F("Air density = "));
  Serial.print(air_density);
  Serial.println(F(" kg/m^3"));

  Serial.print(F("Sensor pressure bias = "));
  Serial.print(sensor_bias);
  Serial.println(F(" Pa"));
*/
  
  Serial.println();
}


Here are some pictures of the wiring/soldering, due to file size restrictions I can't directly post any of them : https://drive.google.com/open?id=1T6lGBI0ACPEkvj-c2ajoYK7-i5xAfpx4

Go Up