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/Acc/ADXL345.h@40:2ca410923691, 2014-02-14 (annotated)
- Committer:
- maetugr
- Date:
- Fri Feb 14 14:17:32 2014 +0000
- Revision:
- 40:2ca410923691
- Parent:
- 33:fd98776b6cc7
now with MPU6050 before taking it too FlyBed2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 2:93f703d2c4d7 | 1 | // based on http://mbed.org/users/Digixx/code/ADXL345/ |
maetugr | 2:93f703d2c4d7 | 2 | |
maetugr | 2:93f703d2c4d7 | 3 | #ifndef ADXL345_H |
maetugr | 2:93f703d2c4d7 | 4 | #define ADXL345_H |
maetugr | 2:93f703d2c4d7 | 5 | |
maetugr | 2:93f703d2c4d7 | 6 | #include "mbed.h" |
maetugr | 33:fd98776b6cc7 | 7 | #include "I2C_Sensor.h" |
maetugr | 33:fd98776b6cc7 | 8 | |
maetugr | 33:fd98776b6cc7 | 9 | #define ADXL345_I2C_ADDRESS 0xA6 |
maetugr | 33:fd98776b6cc7 | 10 | //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D |
maetugr | 33:fd98776b6cc7 | 11 | //when ALT ADDRESS pin is high: |
maetugr | 33:fd98776b6cc7 | 12 | //#define ADXL345_I2C_ADDRESS 0x3A |
maetugr | 2:93f703d2c4d7 | 13 | |
maetugr | 2:93f703d2c4d7 | 14 | // register addresses |
maetugr | 20:e116e596e540 | 15 | #define ADXL345_DEVID_REG 0x00 |
maetugr | 20:e116e596e540 | 16 | #define ADXL345_THRESH_TAP_REG 0x1D |
maetugr | 20:e116e596e540 | 17 | #define ADXL345_OFSX_REG 0x1E |
maetugr | 20:e116e596e540 | 18 | #define ADXL345_OFSY_REG 0x1F |
maetugr | 20:e116e596e540 | 19 | #define ADXL345_OFSZ_REG 0x20 |
maetugr | 20:e116e596e540 | 20 | #define ADXL345_DUR_REG 0x21 |
maetugr | 20:e116e596e540 | 21 | #define ADXL345_LATENT_REG 0x22 |
maetugr | 20:e116e596e540 | 22 | #define ADXL345_WINDOW_REG 0x23 |
maetugr | 20:e116e596e540 | 23 | #define ADXL345_THRESH_ACT_REG 0x24 |
maetugr | 20:e116e596e540 | 24 | #define ADXL345_THRESH_INACT_REG 0x25 |
maetugr | 20:e116e596e540 | 25 | #define ADXL345_TIME_INACT_REG 0x26 |
maetugr | 20:e116e596e540 | 26 | #define ADXL345_ACT_INACT_CTL_REG 0x27 |
maetugr | 20:e116e596e540 | 27 | #define ADXL345_THRESH_FF_REG 0x28 |
maetugr | 20:e116e596e540 | 28 | #define ADXL345_TIME_FF_REG 0x29 |
maetugr | 20:e116e596e540 | 29 | #define ADXL345_TAP_AXES_REG 0x2A |
maetugr | 20:e116e596e540 | 30 | #define ADXL345_ACT_TAP_STATUS_REG 0x2B |
maetugr | 20:e116e596e540 | 31 | #define ADXL345_BW_RATE_REG 0x2C |
maetugr | 20:e116e596e540 | 32 | #define ADXL345_POWER_CTL_REG 0x2D |
maetugr | 20:e116e596e540 | 33 | #define ADXL345_INT_ENABLE_REG 0x2E |
maetugr | 20:e116e596e540 | 34 | #define ADXL345_INT_MAP_REG 0x2F |
maetugr | 20:e116e596e540 | 35 | #define ADXL345_INT_SOURCE_REG 0x30 |
maetugr | 20:e116e596e540 | 36 | #define ADXL345_DATA_FORMAT_REG 0x31 |
maetugr | 20:e116e596e540 | 37 | #define ADXL345_DATAX0_REG 0x32 |
maetugr | 20:e116e596e540 | 38 | #define ADXL345_DATAX1_REG 0x33 |
maetugr | 20:e116e596e540 | 39 | #define ADXL345_DATAY0_REG 0x34 |
maetugr | 20:e116e596e540 | 40 | #define ADXL345_DATAY1_REG 0x35 |
maetugr | 20:e116e596e540 | 41 | #define ADXL345_DATAZ0_REG 0x36 |
maetugr | 20:e116e596e540 | 42 | #define ADXL345_DATAZ1_REG 0x37 |
maetugr | 20:e116e596e540 | 43 | #define ADXL345_FIFO_CTL 0x38 |
maetugr | 20:e116e596e540 | 44 | #define ADXL345_FIFO_STATUS 0x39 |
maetugr | 2:93f703d2c4d7 | 45 | |
maetugr | 2:93f703d2c4d7 | 46 | #define ADXL345_X 0x00 |
maetugr | 2:93f703d2c4d7 | 47 | #define ADXL345_Y 0x01 |
maetugr | 2:93f703d2c4d7 | 48 | #define ADXL345_Z 0x02 |
maetugr | 2:93f703d2c4d7 | 49 | |
maetugr | 20:e116e596e540 | 50 | typedef char byte; |
maetugr | 20:e116e596e540 | 51 | |
maetugr | 33:fd98776b6cc7 | 52 | class ADXL345 : public I2C_Sensor |
maetugr | 2:93f703d2c4d7 | 53 | { |
maetugr | 2:93f703d2c4d7 | 54 | public: |
maetugr | 33:fd98776b6cc7 | 55 | ADXL345(PinName sda, PinName scl); // constructor, uses I2C_Sensor class |
maetugr | 40:2ca410923691 | 56 | float data[3]; // where the measured data is saved |
maetugr | 40:2ca410923691 | 57 | void read(); // read all axis to array |
maetugr | 33:fd98776b6cc7 | 58 | |
maetugr | 33:fd98776b6cc7 | 59 | float offset[3]; // offset that's subtracted from every measurement |
maetugr | 33:fd98776b6cc7 | 60 | void calibrate(int times, float separation_time); // calibration from 'times' measurements with 'separation_time' time between (get an offset while not moving) |
maetugr | 2:93f703d2c4d7 | 61 | |
maetugr | 2:93f703d2c4d7 | 62 | private: |
maetugr | 40:2ca410923691 | 63 | int raw[3]; |
maetugr | 40:2ca410923691 | 64 | void readraw(); |
maetugr | 2:93f703d2c4d7 | 65 | }; |
maetugr | 2:93f703d2c4d7 | 66 | |
maetugr | 2:93f703d2c4d7 | 67 | #endif |