Sensor workshopSELFSTUDY TODAY will be designing and coding A little bit more advanced code examples is given in bottom of this page for inspiration Today we will work with I2C an advanceed I2C device - a Gy80/87/88/91 IMU board It consists of a number of snesor chips all connected to an I2C bus which you will connect to you Arduino or equiv You can use 5V (Vin) as there is a voltage regulator on the board. DONT feed 5V to the 3.3V PIN !!!! You can see it described in detail here I will supply each group with an IMU NB
To get them up and running you need:
See about sensors here Exercises
CodeSome code examples around I2C MoviesTutorialsBMP085Example code with some kind of filtering (lowpass) Exercise II
#include <Wire.h>
#include <bmp085.h>
#define LOOPTIME 100
float temp, pres, atm, alt;
void setup()
{
Serial.begin(115200);
bmp085_init();
}
int i=0;
#define ALFA 0.2
float alt1=0;
#define LOOPTIME 200
unsigned long t1,t3;
void loop()
{
t1 = millis();
temp = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first for every measurements
pres = bmp085GetPressure(bmp085ReadUP());
atm = pres / 101325; // "standard atmosphere"
alt = calcAltitude(pres); //Uncompensated caculation - in Meters
goto xxx; // bypass filtet
alt = ALFA *alt + (1.0-ALFA)*alt1;
alt1 = alt;
xxx:
i++;
Serial.print(i);
Serial.print(" , ");
Serial.print(t1);
Serial.print(" , msek , ");
Serial.print("Temp/pres/atm/alt/tid , ");
Serial.print(temp, 2); //display 2 decimal places
Serial.print(" , C , ");
Serial.print(pres, 0); //whole number only.
Serial.print(" , Pa , ");
Serial.print(atm, 4); //display 4 decimal places
Serial.print(" , ");
Serial.print(alt, 2); //display 2 decimal places
Serial.println(" , m");
t3 = millis();
delay(LOOPTIME - (t3-t1));
}
|