Jump to content

Simple arduino altimeter


Recommended Posts

With the revision of restrictions around airports changed recently, our club, previously inside the FRZ now thankfully finds its self outside ! In theory we can now fly models greater than 7kg but we need to change the club rule. The limit of 400 ft is the sticking point for the club committee.

I decided to look for a simple altitude recording device and found this simple arduino project  Standalone-Arduino-Altimeter. Only three components & around 10 quid to build.

I decided to build one but decided the software need tweaking to suit. I wanted an altitude above launch. As it stood, it indicated pressure temperature and altitude with altitude min and altitude max. The altitude was dependent on both baro pressure and locality height. It could be possible to calibrate it but this would vary with weather. Also 2 decimal places was too much.

My software simply sets a zero altitude on power up/reset and a maximum in relation to this datum . Ive also set it to feet rather than meters!  The bmp280 chip is apparently good for around +/- 3ft 

20190524_195615.jpg

My device mounted in a small plastic box 50mm X 35mm and weighs less than 20g. The plastic screw is mounted above the arduino reset button to act as a button to reset the altimeter to zero before flight.

If anyones interested i could post my revised software!

 

Edited By dave windymiller on 24/05/2019 20:32:01

Link to comment
Share on other sites

Advert


Here it is, not the best written code im sure but it works!

 

 #include "U8glib.h"
#include "BMP280.h"
#include "Wire.h"
#define P0 1013.25 
BMP280 bmp;

// OLED Type
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);

char sT[20];
char sP[9];
char sA[9];
char sA_MIN[9];
char sA_MAX[9];
char sA_DIFF[9];
char sA_NOW[9];

double A_MIN = 0;
double A_MAX = -1000;
double A_DIFF = 0;
double A_NOW = 0;
double cal = 5.0;
double count = 0;


void draw2( double A_DIFF, double A_NOW) {
  u8g.setFont(u8g_font_unifont);


  dtostrf(A_DIFF, 4, 0, sA_DIFF);
  dtostrf(A_NOW, 4, 0, sA_NOW);
  

  u8g.drawStr( 5, 10, "Alt NOW: " ) ;
  u8g.drawStr( 70, 10, sA_NOW);
  
  u8g.drawStr( 5, 40, "Max" ) ;
  u8g.drawStr( 5, 60, "Alt Ft:" ) ;
  u8g.drawStr( 70, 60, sA_DIFF) ;
}

void setup() {
 
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println("BMP init failed!" ) ;
    while (1);
  }
  else Serial.println("BMP init success!" ) ;

  bmp.setOversampling(4);

  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_unifont);
}


void loop(void) {
  double T, P;
  
  char result = bmp.startMeasurment() ;

  if (result != 0) {
    delay(result);
    result = bmp.getTemperatureAndPressure(T, P);

    P = P + cal;
 
    if (result != 0) {
      double A = bmp.altitude(P, P0);
      A = A * 3.28084;

      if ( A > A_MAX) {
        A_MAX = A;
      }

      if ( count == 0 ) {
        A_MIN = A;
        count = count + 1 ;
        
      }
    A_DIFF = A_MAX - A_MIN;
    A_NOW = A - A_MIN;

      do {
        draw2( A_DIFF, A_NOW);
      } while ( u8g.nextPage() ) ;
      u8g.firstPage();
      delay(500);
      
    }
    else {
      Serial.println("Error. " ) ;
    }
  }
  else {
    Serial.println("Error. " ) ;
  }

  delay(100);

}

Edited By dave windymiller on 24/05/2019 21:01:20

Edited By dave windymiller on 24/05/2019 21:02:12

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...