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.
Sensors/Gyro/L3G4200D.h@0:0c4fafa398b4, 2012-09-26 (annotated)
- Committer:
- maetugr
- Date:
- Wed Sep 26 12:15:00 2012 +0000
- Revision:
- 0:0c4fafa398b4
- Child:
- 1:5a64632b1eb9
Sensor Test; Acc, Gyro working, result on LCD (servo lib included)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 0:0c4fafa398b4 | 1 | // based on http://mbed.org/users/shimniok/code/L3G4200D/ |
maetugr | 0:0c4fafa398b4 | 2 | |
maetugr | 0:0c4fafa398b4 | 3 | #ifndef __L3G4200D_H |
maetugr | 0:0c4fafa398b4 | 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 | 0:0c4fafa398b4 | 42 | class Gyro |
maetugr | 0:0c4fafa398b4 | 43 | { |
maetugr | 0:0c4fafa398b4 | 44 | public: |
maetugr | 0:0c4fafa398b4 | 45 | Gyro(PinName sda, PinName scl); // constructor, uses i2c |
maetugr | 0:0c4fafa398b4 | 46 | void read(int g[3]); // read all axis to array |
maetugr | 0:0c4fafa398b4 | 47 | int readTemp(); // read temperature from sensor |
maetugr | 0:0c4fafa398b4 | 48 | |
maetugr | 0:0c4fafa398b4 | 49 | private: |
maetugr | 0:0c4fafa398b4 | 50 | byte data[6]; // 8-Bit pieces of axis data |
maetugr | 0:0c4fafa398b4 | 51 | I2C i2c; // i2c object to communicate |
maetugr | 0:0c4fafa398b4 | 52 | void writeReg(byte reg, byte value); // write one single register to sensor |
maetugr | 0:0c4fafa398b4 | 53 | byte readReg(byte reg); // read one single register from sensor |
maetugr | 0:0c4fafa398b4 | 54 | }; |
maetugr | 0:0c4fafa398b4 | 55 | |
maetugr | 0:0c4fafa398b4 | 56 | #endif |