NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Committer:
maetugr
Date:
Wed Oct 17 08:37:08 2012 +0000
Revision:
10:953afcbcebfc
Parent:
2:93f703d2c4d7
Child:
16:74a6531350b5
neue Acc_Winkelberechnung, vor Kompassklassenrevision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 0:0c4fafa398b4 1 // based on http://mbed.org/users/shimniok/code/L3G4200D/
maetugr 0:0c4fafa398b4 2
maetugr 2:93f703d2c4d7 3 #ifndef L3G4200D_H
maetugr 2:93f703d2c4d7 4 #define L3G4200D_H
maetugr 0:0c4fafa398b4 5
maetugr 0:0c4fafa398b4 6 #include "mbed.h"
maetugr 0:0c4fafa398b4 7
maetugr 0:0c4fafa398b4 8 // register addresses
maetugr 0:0c4fafa398b4 9 #define L3G4200D_WHO_AM_I 0x0F
maetugr 0:0c4fafa398b4 10
maetugr 0:0c4fafa398b4 11 #define L3G4200D_CTRL_REG1 0x20
maetugr 0:0c4fafa398b4 12 #define L3G4200D_CTRL_REG2 0x21
maetugr 0:0c4fafa398b4 13 #define L3G4200D_CTRL_REG3 0x22
maetugr 0:0c4fafa398b4 14 #define L3G4200D_CTRL_REG4 0x23
maetugr 0:0c4fafa398b4 15 #define L3G4200D_CTRL_REG5 0x24
maetugr 0:0c4fafa398b4 16 #define L3G4200D_REFERENCE 0x25
maetugr 0:0c4fafa398b4 17 #define L3G4200D_OUT_TEMP 0x26
maetugr 0:0c4fafa398b4 18 #define L3G4200D_STATUS_REG 0x27
maetugr 0:0c4fafa398b4 19
maetugr 0:0c4fafa398b4 20 #define L3G4200D_OUT_X_L 0x28
maetugr 0:0c4fafa398b4 21 #define L3G4200D_OUT_X_H 0x29
maetugr 0:0c4fafa398b4 22 #define L3G4200D_OUT_Y_L 0x2A
maetugr 0:0c4fafa398b4 23 #define L3G4200D_OUT_Y_H 0x2B
maetugr 0:0c4fafa398b4 24 #define L3G4200D_OUT_Z_L 0x2C
maetugr 0:0c4fafa398b4 25 #define L3G4200D_OUT_Z_H 0x2D
maetugr 0:0c4fafa398b4 26
maetugr 0:0c4fafa398b4 27 #define L3G4200D_FIFO_CTRL_REG 0x2E
maetugr 0:0c4fafa398b4 28 #define L3G4200D_FIFO_SRC_REG 0x2F
maetugr 0:0c4fafa398b4 29
maetugr 0:0c4fafa398b4 30 #define L3G4200D_INT1_CFG 0x30
maetugr 0:0c4fafa398b4 31 #define L3G4200D_INT1_SRC 0x31
maetugr 0:0c4fafa398b4 32 #define L3G4200D_INT1_THS_XH 0x32
maetugr 0:0c4fafa398b4 33 #define L3G4200D_INT1_THS_XL 0x33
maetugr 0:0c4fafa398b4 34 #define L3G4200D_INT1_THS_YH 0x34
maetugr 0:0c4fafa398b4 35 #define L3G4200D_INT1_THS_YL 0x35
maetugr 0:0c4fafa398b4 36 #define L3G4200D_INT1_THS_ZH 0x36
maetugr 0:0c4fafa398b4 37 #define L3G4200D_INT1_THS_ZL 0x37
maetugr 0:0c4fafa398b4 38 #define L3G4200D_INT1_DURATION 0x38
maetugr 0:0c4fafa398b4 39
maetugr 0:0c4fafa398b4 40 typedef char byte;
maetugr 0:0c4fafa398b4 41
maetugr 1:5a64632b1eb9 42 class L3G4200D
maetugr 0:0c4fafa398b4 43 {
maetugr 0:0c4fafa398b4 44 public:
maetugr 1:5a64632b1eb9 45 L3G4200D(PinName sda, PinName scl); // constructor, uses i2c
maetugr 10:953afcbcebfc 46 void read(); // read all axis to array
maetugr 0:0c4fafa398b4 47 int readTemp(); // read temperature from sensor
maetugr 10:953afcbcebfc 48 float data[3]; // where the measured data is saved
maetugr 0:0c4fafa398b4 49
maetugr 0:0c4fafa398b4 50 private:
maetugr 2:93f703d2c4d7 51 float offset[3]; // offset that's subtracted from every measurement
maetugr 0:0c4fafa398b4 52 I2C i2c; // i2c object to communicate
maetugr 0:0c4fafa398b4 53 void writeReg(byte reg, byte value); // write one single register to sensor
maetugr 0:0c4fafa398b4 54 byte readReg(byte reg); // read one single register from sensor
maetugr 0:0c4fafa398b4 55 };
maetugr 0:0c4fafa398b4 56
maetugr 0:0c4fafa398b4 57 #endif