BMP085 trykmåler
#include <Wire.h>
#include <bmp085.h>
/*
1. call bmp085_init
- parameter pressure at sealevel (in Pascal) or 0
if 0 then 101325 (std pressure at sea level) is used
2. Measurement by
a. call bmp085_measure()
b. now pressure and temperature is in float variables bmp085_temp and bmp085_pres
*/
void setup()
{
Serial.begin(115200);
Wire.begin();
bmp085Init(0x77,101300.0); // ress at sealevel today - contact local met office :-)
// i2c addr is 0x76 or 0x77 use i2cscannermpu6050 to check
}
float temp, atm, alt, pres;
#define LOOPTIME 200
unsigned long t1, t3;
void loop()
{
float tryk, temp, hojde;
bmp085Measure(&temp, &tryk, &hojde);
Serial.print("temp(C) "); Serial.print(temp);
Serial.print("\t tryk(Pa) "); Serial.print(tryk);
Serial.print("\t hojde(m)"); Serial.println(hojde);
delay(100);
}
Dagens luftrykEt plot af dagens luftryk vha serial bmp085staverage.ino Der midles over 20 værdier og der samples hvert 5 msec. Dvs
Koden
#include <Wire.h>
#include <bmp085.h>
// NB NB find atm pressure at sealevel for today and adjust SEALEVEL below
#define SEALEVEL 102320.0
// ---
#define LOOPTIME 5
#define AVERSIZE 20
float ff[AVERSIZE];
void initAverageArray()
{
static float pres, temp, alt;
for (int i = 0; i < AVERSIZE; i++) { // do AVERSIZE start measurements
bmp085Measure(&temp, &pres, &alt);
delay(LOOPTIME);
ff[i] = alt;
}
}
float calcAverage(float ff[])
{
float mean = 0.0;
for (int i = 0; i < AVERSIZE; i++)
mean += ff[i];
return (mean / AVERSIZE);
}
void setup()
{
Serial.begin(115200);
Wire.begin();
delay(10);
bmp085Init(0x77,SEALEVEL); // ress at sealevel today 0x76 or 0x77
delay(10);
initAverageArray();
}
void loop()
{
// placed here with static to guard by use of scoperules
static int index = 0;
static float pres, temp, alt;
static float averageAltitude;
bmp085Measure(&temp, &pres, &alt);
// overwrite oldest value
ff[index] = alt;
index++;
if (AVERSIZE <= index) // wrap around
index = 0;
averageAltitude = calcAverage(ff);
Serial.print(alt); Serial.print(" ");
Serial.println(averageAltitude);
delay(LOOPTIME);
}
/* ende */
Jens |