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:
Thu Oct 18 20:04:16 2012 +0000
Revision:
11:9bf69bc6df45
Parent:
10:953afcbcebfc
Child:
17:e096e85f6c36
Kompass immernoch nicht gut, vor Kalibrierungsberechnung

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