Sensor workshop

SELFSTUDY

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

  • Gy87 and GY88 has the same sensors buth a slightly different pinout

  • GY91 has another IMU chip

  • should be handled by drivers :-)

To get them up and running you need:

  1. supply print with 5V and GND

  2. Connect SDA and SDL lines to SDA and SDL lines on your Arduino

    1. Look in your documentation :-)

    2. more at lecture

See about sensors here

Exercises

  1. Get BMP085 up and running

  2. Measure pressure and convert to relative altitude

    1. Use air pressure form DMI or Aalborg Airport

  1. Do 3000 measurements at 10 Hz and write SW for average and deviation calculation

    1. how do you deal with thsi when you onaly have 2-8 kByte RAM

    2. hint: going floats

  2. Implement a moving average filter

    1. last 10 measurements at 10 Hz

  3. Walk the dog a ground floor and first floor and estimate height difference

  1. Implement averaging of your signal for

    1. reducing noise

    2. evaluation of quality (variance)

  1. Get 3 axis Accelerometer up and running

  2. How to calibrate ?

    1. hint you have -1G, 0G and 1G at your fingertips

  3. Assuming the component is linear then you shall implement compensation library:

    1. y = a * x + b yo can find a and b from teh -1G,0G and 1 G measurements

  4. Get gyro up and running

    1. Can you integrate it on your Ccrawler

    2. Drift on Gyro - measure and give an estimate in rad/sec

    3. Accelerometer up and running

    4. Evaluate noise - is averaing needed ?

    5. Compare averaged with raw signal

      1. delay ?

      2. variance

Code

Some code examples around I2C

Movies

Tutorials

BMP085

Example code with some kind of filtering (lowpass)

Exercise II

  1. Is filtering better than averaging

  2. how many pins do you need to average before getting a variance loweer than the lowpass filtered signal

#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));
}