Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
![]() |
| × | 1 | |||
Software apps and online services | ||||||
![]() |
|
I've found many Arduino-based weather station projects on the web, most of them employing low cost sensors. With this project, I would like to make an instrument with an increased accuracy by means of precision pressure, temperature and humidity sensors. The one I've chosen are:
- MS5611 for pressure
- SHT21 for humidity and temperature
Using these primary readings I've calculated absolute humidity, dew point, air density, saturation vapor pressure, water vapor pressure, mixing ratio, enthalpy and density altitude.
Furthermore I've implemented an altimeter with baro adjustment allowing to set the reference pressure. The user interface is very simple and implements three windows:
- The first one is shown during the start-up and is used to display the self test result for the I2C sensors.
- The second window shows the main atmospheric parameters and the third one is for the altimeter. Is possible to switch between the weather station and the altimeter by pressing the arrow in the title bar.
It is also possible to select QNE, QFE and QNH baro setting by pressing the on screen button.
BOMComing soon.
#include <Average.h>
#include <EasyScheduler.h>
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Geometry.h>
#include <SPI.h>
#include <Wire.h>
#include <SHT2x.h>
#include <MS5611.h>
#include <math.h>
#include "I2Cdev.h"
#include "MPU6050.h"
#include "HMC5883L.h"
Average<float> ave1(50);
Average<float> ave2(10);
Average<float> ave3(10);
Average<float> ave4(10);
Average<float> ave5(10);
Average<float> ave6(10);
Average<float> ave7(10);
Average<float> ave8(10);
Average<float> ave9(10);
Average<float> ave10(10);
MS5611 ms5611;
MPU6050 accelgyro;
HMC5883L mag;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
//extern uint8_t BigFont[];
extern uint8_t DotMatrix_M[];
extern uint8_t DotMatrix_XL_Num[];
//extern uint8_t DotMatrix_M_Slash[];
//extern uint8_t arial_bold[];
extern uint8_t hallfetica_normal[];
//extern uint8_t franklingothic_normal[];
//extern uint8_t nadianne[];
//extern uint8_t swiss721_outline[];
extern uint8_t various_symbols[];
extern uint8_t SevenSegNumFont[];
extern uint8_t SixteenSegment[];
extern uint8_t segment18_XXL[];
UTFT myGLCD(ITDB32S,38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch( 6, 5, 4, 3, 2);
UTFT_Geometry geo(&myGLCD);
float temp = 0;
float tempavg = 0;
float tempK = 0;
float tempF = 0;
float press = 0;
float pressavg = 0;
float hum = 0;
float humavg = 0;
float vp = 0;
float mr = 0;
float heat = 0;
float ah = 0;
float dp = 0;
float vpe = 0;
float ad = 0;
float svh = 0;
float addry = 0;
float adwet = 0;
float dalt = 0;
float altr = 0;
float he = 0;
float referencePressure = 1013.25;
float hdg = 0;
float hdgavg = 0;
int page = 0;
float axu = 0;
float axuavg = 0;
float ayu = 0;
float ayuavg = 0;
float azu = 0;
float azuavg = 0;
float gxu = 0;
float gxuavg = 0;
float gyu = 0;
float gyuavg = 0;
float gzu = 0;
float gzuavg = 0;
float mxu = 0;
float myu = 0;
float mzu = 0;
float declinationAngle = 0; //0.0457
char tempf[8];
char pressf[9];
char rhf[8];
char vpf[8];
char mrf[8];
char heatf[8];
char ahf[8];
char dpf[8];
char vpef[8];
char adf[8];
char svhf[8];
char daltf[8];
char altrf[8];
char hef[8];
char referencePressuref[8];
char hdgf[8];
char axf[10];
char ayf[10];
char azf[10];
char gxf[10];
char gyf[10];
char gzf[10];
char mxf[10];
char myf[10];
char mzf[10];
// VARIABLES FOR GRAPH PLOTTING
int gxt = 3;
int gxp = 3;
int gxh = 3;
int gyt;
int gyp;
int gyh;
// VARIABLES FOR TEMPERATURE PLOTTING
int gyt0 = 230;
int gyt1 = 30;
int gxt0 = 20;
int gxt1 = 35;
// VARIABLES FOR PRESSURE PLOTTING
int gyp0 = 230;
int gyp1 = 30;
int gxp0 = 985;
int gxp1 = 1015;
// VARIABLES FOR HUMIDITY PLOTTING
int gyh0 = 230;
int gyh1 = 30;
int gxh0 = 20;
int gxh1 = 90;
int l;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
// CONSTANTS FOR SATURATED VAPOR PRESSURE CALCULATION
float a0 = 6.107799961;
float a1 = 0.4436518521;
float a2 = 0.01428945805;
float a3 = 0.0002650648471;
float a4 = 0.000003031240396;
float a5 = 0.00000002034080948;
float a6 = 0.00000000006136820929;
// CONSTANTS FOR HEAT INDEX CALCULATION
float c1 = -42.379;
float c2 = 2.04901523;
float c3 = 10.14333127;
float c4 = -0.22475541;
float c5 = -0.00683783;
float c6 = -0.05481717;
float c7 = 0.00122874;
float c8 = 0.00085282;
float c9 = -0.00000199;
int x, y;
int xn, yn;
Schedular Task1;
Schedular Task2;
Schedular Task3;
Schedular Task4;
Schedular Task5;
Schedular Task6;
void setup()
{
Task1.start();
Task2.start();
Task3.start();
Task4.start();
Task5.start();
Task6.start();
Wire.begin();
accelgyro.setI2CMasterModeEnabled(false);
accelgyro.setI2CBypassEnabled(true);
accelgyro.setSleepEnabled(false);
accelgyro.initialize();
mag.initialize();
// mag.SetScale(1.3);
// mag.SetMeasurementMode(Measurement_Continuous);
myGLCD.InitLCD();
myGLCD.clrScr();
mainframe();
title0();
myGLCD.setFont(hallfetica_normal);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print(" by mAnU 2015", 42, 37);
myGLCD.setColor(200, 200, 200);
myGLCD.print("SELF TEST", 66, 77);
// SELF TEST FOR MPU6050
myGLCD.setColor(200, 200, 200);
myGLCD.print("MPU6050:", 22, 113);
delay(500);
if(! accelgyro.testConnection())
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("FAIL", 200, 113);
while (1);
}
delay(500);
myGLCD.setColor(0, 255, 0);
myGLCD.print("PASSED", 200, 113);
// SELF TEST FOR MS5611
myGLCD.setColor(200, 200, 200);
myGLCD.print("MS5611:", 22, 131);
delay(500);
if(! ms5611.begin(MS5611_ULTRA_HIGH_RES))
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("FAIL", 200, 131);
while (1);
}
delay(500);
myGLCD.setColor(0, 255, 0);
myGLCD.print("PASSED", 200, 131);
// SELF TEST FOR HMC5883L
myGLCD.setColor(200, 200, 200);
myGLCD.print("HMC5883L:", 19, 149);
delay(500);
if(! mag.testConnection())
{
myGLCD.setColor(255, 0, 0);
myGLCD.print("FAIL", 200, 149);
while (1);
}
delay(500);
myGLCD.setColor(0, 255, 0);
myGLCD.print("PASSED", 200, 149);
delay(3000);
myTouch.InitTouch();
myTouch.setPrecision(PREC_LOW);
myGLCD.clrScr();
mainframe();
title2();
page = 1;
tempavg = 1;
humavg = 1;
}
void loop(){
// TASK TIMING SCHEDULE
Task1.check(funct1,100);
Task2.check(funct2,50);
Task3.check(acq1,10000);
Task4.check(acq2,10);
Task5.check(acq3,20);
Task6.check(graph,32000);
}
void funct1(){
// VARIABLE FORMATTING
dtostrf(tempavg,7, 3, tempf);
dtostrf(pressavg,8, 3, pressf);
dtostrf(humavg,7, 2, rhf);
dtostrf(vp,7, 2, vpf);
dtostrf(mr,7, 2, mrf);
dtostrf(heat,7, 0, heatf);
dtostrf(ah,7, 2, ahf);
dtostrf(dp,7, 2, dpf);
dtostrf(vpe,7, 2, vpef);
dtostrf(ad,7, 4, adf);
dtostrf(svh,7, 2, svhf);
dtostrf(dalt,7, 1, daltf);
dtostrf(altr,6, 1, altrf);
dtostrf(he,7, 3, hef);
dtostrf(referencePressure,7, 2, referencePressuref);
dtostrf(hdgavg,3, 0, hdgf);
dtostrf(axuavg,9, 2, axf);
dtostrf(ayuavg,9, 2, ayf);
dtostrf(azuavg,9, 2, azf);
dtostrf(gxuavg,9, 1, gxf);
dtostrf(gyuavg,9, 1, gyf);
dtostrf(gzuavg,9, 1, gzf);
dtostrf(mxu,9, 3, mxf);
dtostrf(myu,9, 3, myf);
dtostrf(mzu,9, 3, mzf);
if ((myTouch.dataAvailable()))
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=70)) // Button: Down
{
--page;
}
if ((x>=250) && (x<=320)) // Button: Up
{
++page;
}
if (page < 0)
{
page = 0;
}
if (page > 4)
{
page = 4;
}
}
}
if ((page == 0) && (myTouch.dataAvailable())){
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=320)) // Button: Down
{
mainframe();
title1();
}
}
}
if ((page == 1) && (myTouch.dataAvailable())){
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=320)) // Button: Down
{
mainframe();
title2();
gxt=3;
gxp=3;
gxh=3;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1,29,318,238);
}
}
}
if ((page == 2) && (myTouch.dataAvailable())){
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=320)) // Button: Down
{
mainframe();
title3();
}
}
}
if ((page == 3) && (myTouch.dataAvailable())){
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=320)) // Button: Down
{
mainframe();
title4();
}
}
}
if ((page == 4) && (myTouch.dataAvailable())){
if ((y>=0) && (y<=60)) // Upper row
{
if ((x>=0) && (x<=320)) // Button: Down
{
mainframe();
title5();
}
}
}
if (page == 0){
update0();
}
if (page == 1){
update1();
}
if (page == 2){
update2();
}
if (page == 3){
update3();
}
if (page == 4){
update4();
}
}
void funct2(){
if ((myTouch.dataAvailable()) && (page == 2))
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=186) && (y<=226)) //
{
if ((x>=135) && (x<=175)) // Button: "-"
{
referencePressure = referencePressure - 0.01;
myGLCD.setColor(255, 153, 51);
myGLCD.drawRect(68,35,120,53);
myGLCD.print("QNH", 69, 36);
}
if ((x>=185) && (x<=225)) // Button: "+"
{
referencePressure = referencePressure + 0.01;
myGLCD.setColor(255, 153, 51);
myGLCD.drawRect(68,35,120,53);
myGLCD.print("QNH", 69, 36);
}
if ((x>=235) && (x<=285)) // Button: "QFE"
{
referencePressure = pressavg;
myGLCD.setColor(255, 153, 51);
myGLCD.drawRect(68,35,120,53);
myGLCD.print("QFE", 69, 36);
}
if ((x>=75) && (x<=125)) // Button: "QNE"
{
referencePressure = 1013.25;
myGLCD.setColor(255, 153, 51);
myGLCD.drawRect(68,35,120,53);
myGLCD.print("QNE", 69, 36);
}
}
}
}
// UPDATE MAIN DATA PAGE
void update0(){
myGLCD.setColor(0, 225, 120);
myGLCD.print(tempf,119, 36);
myGLCD.print(pressf,103,54);
myGLCD.print(rhf,119, 72);
myGLCD.print(ahf,119, 90);
myGLCD.print(dpf,119, 108);
myGLCD.print(adf,119, 126);
myGLCD.print(vpf,119, 144);
myGLCD.print(vpef,119, 162);
// myGLCD.print(mrf,119, 180);
myGLCD.print(heatf,119, 180);
myGLCD.print(hef,119, 198);
// myGLCD.print(daltf,119, 216);
// DRAW HUMIDEX INDICATOR
if (heat <= 29){
myGLCD.setColor(0, 128, 255);
myGLCD.fillCircle(245,188,6);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(245,188,6);
}
if ((heat >29) && (heat <= 39)){
myGLCD.setColor(0, 255, 128);
myGLCD.fillCircle(245,188,6);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(245,188,6);
}
if ((heat >39) && (heat <= 45)){
myGLCD.setColor(255, 255, 0);
myGLCD.fillCircle(245,188,6);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(245,188,6);
}
if ((heat >45) && (heat <= 54)){
myGLCD.setColor(255, 128, 0);
myGLCD.fillCircle(245,188,6);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(245,188,6);
}
if (heat > 54){
myGLCD.setColor(255, 0, 0);
myGLCD.fillCircle(245,188,6);
myGLCD.setColor(255, 255, 255);
myGLCD.drawCircle(245,188,6);
}
}
void update1(){
myGLCD.setFont(SmallFont);
myGLCD.setColor(255, 128, 0);
myGLCD.print("T", 5, 225);
myGLCD.setColor(255, 255, 255);
myGLCD.print(tempf, 15, 225);
myGLCD.print("C", 75, 225);
myGLCD.setColor(0, 255, 128);
myGLCD.print("P", 105, 225);
myGLCD.setColor(255, 255, 255);
myGLCD.print(pressf, 120, 225);
myGLCD.print("hPa", 190, 225);
myGLCD.setColor(0, 128, 255);
myGLCD.print("H", 240, 225);
myGLCD.setColor(255, 255, 255);
myGLCD.print(rhf, 245, 225);
myGLCD.print("%", 305, 225);
myGLCD.setColor(255, 128, 0);
myGLCD.drawPixel(gxt,gyt);
myGLCD.setColor(0, 255, 128);
myGLCD.drawPixel(gxp,gyp);
myGLCD.setColor(0, 128, 255);
myGLCD.drawPixel(gxh,gyh);
}
void update2(){
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(0, 225, 120);
myGLCD.print(referencePressuref,119, 144);
myGLCD.print(daltf,119, 72);
myGLCD.print(altrf,137, 36);
}
void update3(){
// myGLCD.setFont(hallfetica_normal);
myGLCD.setFont(segment18_XXL);
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(0, 225, 120);
// myGLCD.print(hdgf,135, 125);
myGLCD.print(hdgf,113, 108);
// myGLCD.print("N", xn, yn);
// DRAW COMPASS NEEDLE
myGLCD.setColor(VGA_BLACK);
geo.drawArc(159, 134, 80, l, l, 20);
myGLCD.setColor(0, 225, 120);
geo.drawArc(159, 134, 80, hdgavg, hdgavg, 20);
l = hdgavg;
}
void update4(){
// myGLCD.setFont(hallfetica_normal);
myGLCD.setFont(hallfetica_normal);
myGLCD.setBackColor(0,0,0);
myGLCD.setColor(0, 225, 120);
myGLCD.print(axf,85, 36);
myGLCD.print(ayf,85,54);
myGLCD.print(azf,85, 72);
myGLCD.print(gxf,85, 90);
myGLCD.print(gyf,85, 108);
myGLCD.print(gzf,85, 126);
myGLCD.print(mxf,85, 144);
myGLCD.print(myf,85, 162);
myGLCD.print(mzf,85, 180);
}
void mainframe(){
myGLCD.fillScr(0, 0, 0);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRect(0,0,319,28);
myGLCD.setColor(200, 200, 200);
myGLCD.drawRect(0,0,319,239);
myGLCD.drawLine(0, 28, 319, 28);
}
void title0(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print("AIR DATA COMPUTER", 24, 6);
}
void title1(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(" AIR DATA ", 25, 6);
myGLCD.setFont(various_symbols);
myGLCD.print("R", 297, 6);
myGLCD.setColor(200, 200, 200);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(hallfetica_normal);
myGLCD.print("Temp", 13, 36);
myGLCD.print("C", 243, 36);
myGLCD.drawCircle(238,41,2);
myGLCD.print("Press", 13, 54);
myGLCD.print("hPa", 235, 54);
myGLCD.print("RH", 13, 72);
myGLCD.print("%", 235, 72);
myGLCD.print("AH", 13, 90);
myGLCD.print("g/m3", 235, 90);
myGLCD.print("DP", 13, 108);
myGLCD.print("C", 243, 108);
myGLCD.drawCircle(238,113,2);
myGLCD.print("AD", 13, 126);
myGLCD.print("kg/m3", 235, 126);
myGLCD.print("SVP", 13, 144);
myGLCD.print("hPa", 235, 144);
myGLCD.print("WVP", 13, 162);
myGLCD.print("hPa", 235, 162);
// myGLCD.print("MR", 13, 180);
myGLCD.print("H.idx", 13, 180);
// myGLCD.print("g/kg", 235, 180);
myGLCD.print("H", 13, 198);
myGLCD.print("kJ/kg", 235, 198);
// myGLCD.print("DA", 13, 216);
// myGLCD.print("m", 235, 216);
}
void title2(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(" METEO GRAPH ", 25, 6);
myGLCD.setFont(various_symbols);
myGLCD.print("R", 297, 6);
myGLCD.print("Q", 8, 6);
myGLCD.setColor(200, 200, 200);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(hallfetica_normal);
}
void title3(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(" ALTIMETER ", 25, 6);
myGLCD.setFont(various_symbols);
myGLCD.print("R", 297, 6);
myGLCD.print("Q", 8, 6);
myGLCD.setColor(200, 200, 200);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(hallfetica_normal);
myGLCD.print("ALT", 13, 36);
myGLCD.print("m", 235, 36);
myGLCD.print("DA", 13, 72);
myGLCD.print("m", 235, 72);
myGLCD.print("Baro", 13, 144);
myGLCD.print("hPa", 235, 144);
myGLCD.print("Set", 13, 198);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(135,186,175,226);
myGLCD.setColor(200, 200, 200);
myGLCD.drawRoundRect(135,186,175,226);
myGLCD.setBackColor(0,0,255);
myGLCD.print("-", 148, 198);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(185,186,225,226);
myGLCD.setColor(200, 200, 200);
myGLCD.drawRoundRect(185,186,225,226);
myGLCD.setBackColor(0,0,255);
myGLCD.print("+", 198, 198);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(235,186,285,226);
myGLCD.setColor(200, 200, 200);
myGLCD.drawRoundRect(235,186,285,226);
myGLCD.setBackColor(0,0,255);
myGLCD.print("QFE", 236, 198);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect(75,186,125,226);
myGLCD.setColor(200, 200, 200);
myGLCD.drawRoundRect(75,186,125,226);
myGLCD.setBackColor(0,0,255);
myGLCD.print("QNE", 76, 198);
}
void title4(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(" COMPASS ", 25, 6);
myGLCD.setFont(various_symbols);
myGLCD.print("R", 297, 6);
myGLCD.print("Q", 8, 6);
myGLCD.drawCircle(159,134,95);
myGLCD.drawCircle(159,134,65);
}
void title5(){
myGLCD.setFont(hallfetica_normal);
myGLCD.setColor(200, 200,200);
myGLCD.setBackColor(0, 0, 255);
myGLCD.print(" DIAGNOSTIC ", 25, 6);
myGLCD.setFont(various_symbols);
myGLCD.print("Q", 8, 6);
myGLCD.setColor(200, 200, 200);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(hallfetica_normal);
myGLCD.print("Ax", 13, 36);
myGLCD.print("g", 235, 36);
myGLCD.print("Ay", 13, 54);
myGLCD.print("g", 235, 54);
myGLCD.print("Az", 13, 72);
myGLCD.print("g", 235, 72);
myGLCD.print("Gx", 13, 90);
myGLCD.print("deg/s", 235, 90);
myGLCD.print("Gy", 13, 108);
myGLCD.print("deg/s", 235, 108);
myGLCD.print("Gz", 13, 126);
myGLCD.print("deg/s", 235, 126);
myGLCD.print("Mx", 13, 144);
myGLCD.print("Ga", 235, 144);
myGLCD.print("My", 13, 162);
myGLCD.print("Ga", 235, 162);
myGLCD.print("Mz", 13, 180);
myGLCD.print("Ga", 235, 180);
}
void acq1(){
// MESUREMENT ACQUISITION
// temp = ms5611.readTemperature();
temp = SHT2x.GetTemperature();
hum = SHT2x.GetHumidity();
ave2.push(temp);
tempavg = ave2.mean();
ave3.push(hum);
humavg = ave3.mean();
}
void acq2(){
// MESUREMENT ACQUISITION
press = ms5611.readPressure() / 100.000;
ave1.push(press);
pressavg = ave1.mean();
altr = ms5611.getAltitude(pressavg, referencePressure);
// CALCULATIONS
tempK = tempavg + 273.15; // °C to K conversion
tempF = tempavg / 5 * 9 +32.000;
// vp = 6.1078 * pow(10, ((7.500 * temp) / (237.300 + temp))); // Saturation vapor pressure [hPa]
vp = a0 + tempavg * (a1 + tempavg * ( a2 + tempavg * (a3 + tempavg * ( a4 + tempavg * (a5 + a6 * tempavg)))));
vpe = (humavg * vp) / 100.00; // Water vapor pressure
mr = 621.9907 * vpe / (pressavg - vpe); // Mixing ratio
ah = 2.16679 * vpe * 100 / tempK; // Asolute humidity
dp = (-430.22 + 237.70 * log(vpe)) / (-log(vpe) + 19.08) ; // Dew point
addry = (((pressavg * 100) - (vpe * 100)) / (287.04597 * (tempK))); // Dry air fraction density
adwet = (vpe * 100) / (461.495 * (tempK)); // Water fraction density
ad = addry + adwet; // Actual air density
dalt = (44.3308 - 42.2665 * pow(ad, 0.234969)) * 1000; // Density altitude
he = tempavg * (1.01 + 0.00189 * mr) + 2.500 * mr;
// heat = tempavg + 0.5555 * (vpe - 10.0000);
heat = ((c1 + c2 * tempF+ c3 * humavg + c4 * tempF * humavg + c5 * square(tempF) + c6 * square(humavg) + c7 * square(tempF) * humavg + c8 * tempF * square(humavg) + c9 * square(tempF) * square(humavg))-32) / 9 * 5;
}
void acq3(){
// MESUREMENT ACQUISITION
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
mag.getHeading(&mx, &my, &mz);
// MagnetometerRaw raw = mag.ReadRawAxis();
// MagnetometerScaled scaled = mag.ReadScaledAxis();
// mx = scaled.XAxis;
// my = scaled.YAxis;
// mz = scaled.ZAxis;
float heading = atan2(my, mz);
heading += declinationAngle;
if(heading < 0)
heading += 2 * M_PI;
if(heading > 2* M_PI)
heading -= 2* M_PI;
hdg = heading * 180 / M_PI; // Convert radians to degrees
ave4.push(hdg);
hdgavg = ave4.mean();
// xn = 151 - 80 * (cos(heading - M_PI / 2));
// yn = 125 + 80 * (sin(heading - M_PI / 2));
axu = ax / (-16384.000);
ave5.push(axu);
axuavg = ave5.mean();
ayu = ay / 16384.000;
ave6.push(ayu);
ayuavg = ave6.mean();
azu = az / 16384.000;
ave7.push(azu);
azuavg = ave7.mean();
gxu = gx / 250.000 + 1.375;
ave8.push(gxu);
gxuavg = ave8.mean();
gyu = gy / 250.000 - 0.475;
ave9.push(gyu);
gyuavg = ave9.mean();
gzu = gz / 250.000 - 0.475;
ave10.push(gzu);
gzuavg = ave10.mean();
mxu = mx / 1090.000;
myu = my / 1090.000;
mzu = mz / 1090.000;
}
void graph(){
gxt = gxt++;
gxp = gxp++;
gxh = gxh++;
gyt = ((gyt1-gyt0)/(gxt1-gxt0)) * (tempavg - gxt1) + gyt1;
gyp = ((gyp1-gyp0)/(gxp1-gxp0)) * (pressavg - gxp1) + gyp1;
gyh = ((gyh1-gyh0)/(gxh1-gxh0)) * (humavg - gxh1) + gyh1;
if (((gxt > 317) || (gxp > 317) ||(gxh > 317)) && (page == 1)){
gxt=3;
gxp=3;
gxh=3;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(1,29,318,238);
}
if (gyt < 30) {
gyt=30;
}
if (gyp < 30) {
gyp=30;
}
if (gyh < 30) {
gyh=30;
}
}
Comments
Please log in or sign up to comment.