I2C interface for LG1300L IMU
Dependents: LG1300L_Hello_World LG1300L_Hello_World_LCD
LG1300L.h@0:896f1d7a0503, 2013-03-05 (annotated)
- Committer:
- mjenkins11
- Date:
- Tue Mar 05 00:50:17 2013 +0000
- Revision:
- 0:896f1d7a0503
- Child:
- 1:c40e8dead9be
revision 0.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mjenkins11 | 0:896f1d7a0503 | 1 | #include "mbed.h" |
mjenkins11 | 0:896f1d7a0503 | 2 | #ifndef MBED_LG1300L_H |
mjenkins11 | 0:896f1d7a0503 | 3 | #define MBED_LG1300L_H |
mjenkins11 | 0:896f1d7a0503 | 4 | /*! CruizCore XG1300L IMU interface |
mjenkins11 | 0:896f1d7a0503 | 5 | * Used for communicating with an XG1300L IMU over I2C |
mjenkins11 | 0:896f1d7a0503 | 6 | * @code |
mjenkins11 | 0:896f1d7a0503 | 7 | *#include "mbed.h" |
mjenkins11 | 0:896f1d7a0503 | 8 | *#include "TextLCD.h" |
mjenkins11 | 0:896f1d7a0503 | 9 | *#include "LG1300L.h" |
mjenkins11 | 0:896f1d7a0503 | 10 | * |
mjenkins11 | 0:896f1d7a0503 | 11 | *TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 |
mjenkins11 | 0:896f1d7a0503 | 12 | * |
mjenkins11 | 0:896f1d7a0503 | 13 | *Serial pc(USBTX, USBRX); // tx, rx |
mjenkins11 | 0:896f1d7a0503 | 14 | * |
mjenkins11 | 0:896f1d7a0503 | 15 | *I2C i2c(p28,p27); |
mjenkins11 | 0:896f1d7a0503 | 16 | *DigitalOut LED (LED1); |
mjenkins11 | 0:896f1d7a0503 | 17 | * |
mjenkins11 | 0:896f1d7a0503 | 18 | *int main() { |
mjenkins11 | 0:896f1d7a0503 | 19 | * LG1300L IMU(i2c, 2); |
mjenkins11 | 0:896f1d7a0503 | 20 | * |
mjenkins11 | 0:896f1d7a0503 | 21 | * while(1) { |
mjenkins11 | 0:896f1d7a0503 | 22 | * float angle = IMU.GetAngle(); |
mjenkins11 | 0:896f1d7a0503 | 23 | * float ROT= IMU.GetROT(); |
mjenkins11 | 0:896f1d7a0503 | 24 | * float X_ACC = IMU.GetACC_X(); |
mjenkins11 | 0:896f1d7a0503 | 25 | * float Y_ACC = IMU. GetACC_Y(); |
mjenkins11 | 0:896f1d7a0503 | 26 | * float Z_ACC = IMU. GetACC_Z(); |
mjenkins11 | 0:896f1d7a0503 | 27 | * pc.printf("///////////////////////////////////\n"); |
mjenkins11 | 0:896f1d7a0503 | 28 | * pc.printf("//ANGLE: %f\n", angle); |
mjenkins11 | 0:896f1d7a0503 | 29 | * pc.printf("//ROT: %f\n", ROT); |
mjenkins11 | 0:896f1d7a0503 | 30 | * pc.printf("//X-Axis: %f\n", X_ACC ); |
mjenkins11 | 0:896f1d7a0503 | 31 | * pc.printf("//Y-Axis: %f\n", Y_ACC ); |
mjenkins11 | 0:896f1d7a0503 | 32 | * pc.printf("//Z-axis: %f\n", Z_ACC ); |
mjenkins11 | 0:896f1d7a0503 | 33 | * pc.printf("///////////////////////////////////\n"); |
mjenkins11 | 0:896f1d7a0503 | 34 | * wait(1); |
mjenkins11 | 0:896f1d7a0503 | 35 | * } |
mjenkins11 | 0:896f1d7a0503 | 36 | *} |
mjenkins11 | 0:896f1d7a0503 | 37 | * @endcode |
mjenkins11 | 0:896f1d7a0503 | 38 | */ |
mjenkins11 | 0:896f1d7a0503 | 39 | |
mjenkins11 | 0:896f1d7a0503 | 40 | |
mjenkins11 | 0:896f1d7a0503 | 41 | |
mjenkins11 | 0:896f1d7a0503 | 42 | |
mjenkins11 | 0:896f1d7a0503 | 43 | class LG1300L{ |
mjenkins11 | 0:896f1d7a0503 | 44 | public: |
mjenkins11 | 0:896f1d7a0503 | 45 | |
mjenkins11 | 0:896f1d7a0503 | 46 | /*! Create an IMU readout interface |
mjenkins11 | 0:896f1d7a0503 | 47 | * |
mjenkins11 | 0:896f1d7a0503 | 48 | * @param i2c The instantiated I2C bus to be used |
mjenkins11 | 0:896f1d7a0503 | 49 | * @param ACC_SETTING the desired initialization range for the |
mjenkins11 | 0:896f1d7a0503 | 50 | accelerometers, choices are +-2G, +-4G, or +-8G |
mjenkins11 | 0:896f1d7a0503 | 51 | */ |
mjenkins11 | 0:896f1d7a0503 | 52 | LG1300L(I2C& i2c, int ACC_SETTING); |
mjenkins11 | 0:896f1d7a0503 | 53 | |
mjenkins11 | 0:896f1d7a0503 | 54 | /*! Returns a float containing the current Accumulated Angle |
mjenkins11 | 0:896f1d7a0503 | 55 | * @returns float |
mjenkins11 | 0:896f1d7a0503 | 56 | */ |
mjenkins11 | 0:896f1d7a0503 | 57 | float GetAngle(); |
mjenkins11 | 0:896f1d7a0503 | 58 | /*! Returns a float containing the current ROT |
mjenkins11 | 0:896f1d7a0503 | 59 | * @returns float |
mjenkins11 | 0:896f1d7a0503 | 60 | */ |
mjenkins11 | 0:896f1d7a0503 | 61 | float GetROT(); |
mjenkins11 | 0:896f1d7a0503 | 62 | /*! Returns a float containing the current acceleration on |
mjenkins11 | 0:896f1d7a0503 | 63 | * the X axis. |
mjenkins11 | 0:896f1d7a0503 | 64 | * @returns float |
mjenkins11 | 0:896f1d7a0503 | 65 | * |
mjenkins11 | 0:896f1d7a0503 | 66 | */ |
mjenkins11 | 0:896f1d7a0503 | 67 | float GetACC_X(); |
mjenkins11 | 0:896f1d7a0503 | 68 | /*! Returns a float containing the current acceleration on |
mjenkins11 | 0:896f1d7a0503 | 69 | *the Y axis. |
mjenkins11 | 0:896f1d7a0503 | 70 | * @returns float |
mjenkins11 | 0:896f1d7a0503 | 71 | */ |
mjenkins11 | 0:896f1d7a0503 | 72 | float GetACC_Y(); |
mjenkins11 | 0:896f1d7a0503 | 73 | /*! Returns a float containing the current acceleration on |
mjenkins11 | 0:896f1d7a0503 | 74 | *the Z axis. |
mjenkins11 | 0:896f1d7a0503 | 75 | * @returns float |
mjenkins11 | 0:896f1d7a0503 | 76 | */ |
mjenkins11 | 0:896f1d7a0503 | 77 | float GetACC_Z(); |
mjenkins11 | 0:896f1d7a0503 | 78 | private: |
mjenkins11 | 0:896f1d7a0503 | 79 | |
mjenkins11 | 0:896f1d7a0503 | 80 | void init(); |
mjenkins11 | 0:896f1d7a0503 | 81 | |
mjenkins11 | 0:896f1d7a0503 | 82 | char ANGLE_LSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 83 | char ANGLE_MSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 84 | char ROT_LSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 85 | char ROT_MSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 86 | char X_ACC_LSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 87 | char X_ACC_MSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 88 | char Y_ACC_LSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 89 | char Y_ACC_MSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 90 | char Z_ACC_LSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 91 | char Z_ACC_MSB_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 92 | |
mjenkins11 | 0:896f1d7a0503 | 93 | |
mjenkins11 | 0:896f1d7a0503 | 94 | char RESET_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 95 | char SELECT_2G_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 96 | char SELECT_4G_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 97 | char SELECT_8G_REG[1]; |
mjenkins11 | 0:896f1d7a0503 | 98 | |
mjenkins11 | 0:896f1d7a0503 | 99 | float CALC_ANG, CALC_ROT, CALC_X, CALC_Y, CALC_Z; |
mjenkins11 | 0:896f1d7a0503 | 100 | int ACC_RANGE; |
mjenkins11 | 0:896f1d7a0503 | 101 | signed short ANGLE_MSB; |
mjenkins11 | 0:896f1d7a0503 | 102 | signed short ANGLE_LSB; |
mjenkins11 | 0:896f1d7a0503 | 103 | signed short ROT_MSB; |
mjenkins11 | 0:896f1d7a0503 | 104 | signed short ROT_LSB; |
mjenkins11 | 0:896f1d7a0503 | 105 | signed short ACC_X_MSB; |
mjenkins11 | 0:896f1d7a0503 | 106 | signed short ACC_X_LSB; |
mjenkins11 | 0:896f1d7a0503 | 107 | signed short ACC_Y_MSB; |
mjenkins11 | 0:896f1d7a0503 | 108 | signed short ACC_Y_LSB; |
mjenkins11 | 0:896f1d7a0503 | 109 | signed short ACC_Z_MSB; |
mjenkins11 | 0:896f1d7a0503 | 110 | signed short ACC_Z_LSB; |
mjenkins11 | 0:896f1d7a0503 | 111 | protected: |
mjenkins11 | 0:896f1d7a0503 | 112 | |
mjenkins11 | 0:896f1d7a0503 | 113 | I2C& IMU; |
mjenkins11 | 0:896f1d7a0503 | 114 | char data[2]; |
mjenkins11 | 0:896f1d7a0503 | 115 | const int IMU_ADDR; |
mjenkins11 | 0:896f1d7a0503 | 116 | }; |
mjenkins11 | 0:896f1d7a0503 | 117 | |
mjenkins11 | 0:896f1d7a0503 | 118 | #endif |