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 31 16:53:01 2012 +0000
Revision:
17:e096e85f6c36
Parent:
11:9bf69bc6df45
Child:
18:c8c09a3913ba
alle Sensoren mit i2c auf I2C_Sensor umgestellt (nicht getestet), noch keine calibration save per I2C_Sensor

Who changed what in which revision?

UserRevisionLine numberNew 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 17:e096e85f6c36 7 #include "I2C_Sensor.h"
maetugr 17:e096e85f6c36 8
maetugr 17:e096e85f6c36 9 #define ADXL345_I2C_ADDRESS 0
maetugr 17:e096e85f6c36 10 // read or write bytes
maetugr 17:e096e85f6c36 11 //#define ADXL345_READ 0xA7
maetugr 17:e096e85f6c36 12 //#define ADXL345_WRITE 0xA6
maetugr 17:e096e85f6c36 13 //#define ADXL345_ADDRESS 0x53
maetugr 2:93f703d2c4d7 14
maetugr 2:93f703d2c4d7 15 // register addresses
maetugr 17:e096e85f6c36 16 #define ADXL345_DEVID_REG 0x00
maetugr 17:e096e85f6c36 17 #define ADXL345_THRESH_TAP_REG 0x1D
maetugr 17:e096e85f6c36 18 #define ADXL345_OFSX_REG 0x1E
maetugr 17:e096e85f6c36 19 #define ADXL345_OFSY_REG 0x1F
maetugr 17:e096e85f6c36 20 #define ADXL345_OFSZ_REG 0x20
maetugr 17:e096e85f6c36 21 #define ADXL345_DUR_REG 0x21
maetugr 17:e096e85f6c36 22 #define ADXL345_LATENT_REG 0x22
maetugr 17:e096e85f6c36 23 #define ADXL345_WINDOW_REG 0x23
maetugr 17:e096e85f6c36 24 #define ADXL345_THRESH_ACT_REG 0x24
maetugr 17:e096e85f6c36 25 #define ADXL345_THRESH_INACT_REG 0x25
maetugr 17:e096e85f6c36 26 #define ADXL345_TIME_INACT_REG 0x26
maetugr 17:e096e85f6c36 27 #define ADXL345_ACT_INACT_CTL_REG 0x27
maetugr 17:e096e85f6c36 28 #define ADXL345_THRESH_FF_REG 0x28
maetugr 17:e096e85f6c36 29 #define ADXL345_TIME_FF_REG 0x29
maetugr 17:e096e85f6c36 30 #define ADXL345_TAP_AXES_REG 0x2A
maetugr 17:e096e85f6c36 31 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
maetugr 17:e096e85f6c36 32 #define ADXL345_BW_RATE_REG 0x2C
maetugr 17:e096e85f6c36 33 #define ADXL345_POWER_CTL_REG 0x2D
maetugr 17:e096e85f6c36 34 #define ADXL345_INT_ENABLE_REG 0x2E
maetugr 17:e096e85f6c36 35 #define ADXL345_INT_MAP_REG 0x2F
maetugr 17:e096e85f6c36 36 #define ADXL345_INT_SOURCE_REG 0x30
maetugr 17:e096e85f6c36 37 #define ADXL345_DATA_FORMAT_REG 0x31
maetugr 17:e096e85f6c36 38 #define ADXL345_DATAX0_REG 0x32
maetugr 17:e096e85f6c36 39 #define ADXL345_DATAX1_REG 0x33
maetugr 17:e096e85f6c36 40 #define ADXL345_DATAY0_REG 0x34
maetugr 17:e096e85f6c36 41 #define ADXL345_DATAY1_REG 0x35
maetugr 17:e096e85f6c36 42 #define ADXL345_DATAZ0_REG 0x36
maetugr 17:e096e85f6c36 43 #define ADXL345_DATAZ1_REG 0x37
maetugr 17:e096e85f6c36 44 #define ADXL345_FIFO_CTL 0x38
maetugr 17:e096e85f6c36 45 #define ADXL345_FIFO_STATUS 0x39
maetugr 2:93f703d2c4d7 46
maetugr 2:93f703d2c4d7 47 // data rate codes
maetugr 2:93f703d2c4d7 48 #define ADXL345_3200HZ 0x0F
maetugr 2:93f703d2c4d7 49 #define ADXL345_1600HZ 0x0E
maetugr 2:93f703d2c4d7 50 #define ADXL345_800HZ 0x0D
maetugr 2:93f703d2c4d7 51 #define ADXL345_400HZ 0x0C
maetugr 2:93f703d2c4d7 52 #define ADXL345_200HZ 0x0B
maetugr 2:93f703d2c4d7 53 #define ADXL345_100HZ 0x0A
maetugr 2:93f703d2c4d7 54 #define ADXL345_50HZ 0x09
maetugr 2:93f703d2c4d7 55 #define ADXL345_25HZ 0x08
maetugr 2:93f703d2c4d7 56 #define ADXL345_12HZ5 0x07
maetugr 2:93f703d2c4d7 57 #define ADXL345_6HZ25 0x06
maetugr 2:93f703d2c4d7 58
maetugr 2:93f703d2c4d7 59 //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 2:93f703d2c4d7 60 //when ALT ADDRESS pin is high:
maetugr 2:93f703d2c4d7 61 //#define ADXL345_READ 0x3B
maetugr 2:93f703d2c4d7 62 //#define ADXL345_WRITE 0x3A
maetugr 2:93f703d2c4d7 63 //#define ADXL345_ADDRESS 0x1D
maetugr 2:93f703d2c4d7 64
maetugr 2:93f703d2c4d7 65 #define ADXL345_X 0x00
maetugr 2:93f703d2c4d7 66 #define ADXL345_Y 0x01
maetugr 2:93f703d2c4d7 67 #define ADXL345_Z 0x02
maetugr 2:93f703d2c4d7 68
maetugr 17:e096e85f6c36 69 #define RAD2DEG 57.295779513082320876798154814105
maetugr 10:953afcbcebfc 70
maetugr 17:e096e85f6c36 71 class ADXL345 : public I2C_Sensor
maetugr 2:93f703d2c4d7 72 {
maetugr 2:93f703d2c4d7 73 public:
maetugr 17:e096e85f6c36 74 ADXL345(PinName sda, PinName scl); // constructor, uses I2C_Sensor
maetugr 17:e096e85f6c36 75 void read(); // reads all axis to array
maetugr 17:e096e85f6c36 76 int data[3]; // where the measured data is saved
maetugr 17:e096e85f6c36 77 float angle[3]; // where the calculated angles are stored
maetugr 2:93f703d2c4d7 78
maetugr 2:93f703d2c4d7 79 private:
maetugr 17:e096e85f6c36 80 void setDataRate(char rate); // data rate configuration (not only a reg to write)
maetugr 2:93f703d2c4d7 81 };
maetugr 2:93f703d2c4d7 82
maetugr 2:93f703d2c4d7 83 #endif