![](/media/cache/profiles/4b602c3f2f6b86b43ad406fd438e09a8.jpg.50x50_q85.jpg)
RaheeNew
Fork of Adafruit9-DOf by
Header/Adafruit_L3GD20_U.h@1:c3381056a1c6, 2015-11-28 (annotated)
- Committer:
- jatinsha
- Date:
- Sat Nov 28 10:06:40 2015 +0000
- Revision:
- 1:c3381056a1c6
- Parent:
- 0:772bf4786416
js
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bmanga95 | 0:772bf4786416 | 1 | /*************************************************** |
bmanga95 | 0:772bf4786416 | 2 | This is a library for the L3GD20 GYROSCOPE |
bmanga95 | 0:772bf4786416 | 3 | |
bmanga95 | 0:772bf4786416 | 4 | Designed specifically to work with the Adafruit L3GD20 Breakout |
bmanga95 | 0:772bf4786416 | 5 | ----> https://www.adafruit.com/products/1032 |
bmanga95 | 0:772bf4786416 | 6 | |
bmanga95 | 0:772bf4786416 | 7 | These sensors use I2C or SPI to communicate, 2 pins (I2C) |
bmanga95 | 0:772bf4786416 | 8 | or 4 pins (SPI) are required to interface. |
bmanga95 | 0:772bf4786416 | 9 | |
bmanga95 | 0:772bf4786416 | 10 | Adafruit invests time and resources providing this open source code, |
bmanga95 | 0:772bf4786416 | 11 | please support Adafruit and open-source hardware by purchasing |
bmanga95 | 0:772bf4786416 | 12 | products from Adafruit! |
bmanga95 | 0:772bf4786416 | 13 | |
bmanga95 | 0:772bf4786416 | 14 | Written by Kevin "KTOWN" Townsend for Adafruit Industries. |
bmanga95 | 0:772bf4786416 | 15 | BSD license, all text above must be included in any redistribution |
bmanga95 | 0:772bf4786416 | 16 | ****************************************************/ |
bmanga95 | 0:772bf4786416 | 17 | #ifndef __L3GD20_H__ |
bmanga95 | 0:772bf4786416 | 18 | #define __L3GD20_H__ |
bmanga95 | 0:772bf4786416 | 19 | |
bmanga95 | 0:772bf4786416 | 20 | |
bmanga95 | 0:772bf4786416 | 21 | #include <Adafruit_Sensor.h> |
bmanga95 | 0:772bf4786416 | 22 | #include "I2C_base.h" |
bmanga95 | 0:772bf4786416 | 23 | |
bmanga95 | 0:772bf4786416 | 24 | /*========================================================================= |
bmanga95 | 0:772bf4786416 | 25 | I2C ADDRESS/BITS AND SETTINGS |
bmanga95 | 0:772bf4786416 | 26 | -----------------------------------------------------------------------*/ |
bmanga95 | 0:772bf4786416 | 27 | #define L3GD20_ADDRESS (0x6B) // 1101011 |
bmanga95 | 0:772bf4786416 | 28 | #define L3GD20_POLL_TIMEOUT (100) // Maximum number of read attempts |
bmanga95 | 0:772bf4786416 | 29 | #define L3GD20_ID 0xD4 |
bmanga95 | 0:772bf4786416 | 30 | #define L3GD20H_ID 0xD7 |
bmanga95 | 0:772bf4786416 | 31 | #define GYRO_SENSITIVITY_250DPS (0.00875F) // Roughly 22/256 for fixed point match |
bmanga95 | 0:772bf4786416 | 32 | #define GYRO_SENSITIVITY_500DPS (0.0175F) // Roughly 45/256 |
bmanga95 | 0:772bf4786416 | 33 | #define GYRO_SENSITIVITY_2000DPS (0.070F) // Roughly 18/256 |
bmanga95 | 0:772bf4786416 | 34 | /*=========================================================================*/ |
bmanga95 | 0:772bf4786416 | 35 | |
bmanga95 | 0:772bf4786416 | 36 | /*========================================================================= |
bmanga95 | 0:772bf4786416 | 37 | REGISTERS |
bmanga95 | 0:772bf4786416 | 38 | -----------------------------------------------------------------------*/ |
bmanga95 | 0:772bf4786416 | 39 | typedef enum |
bmanga95 | 0:772bf4786416 | 40 | { // DEFAULT TYPE |
bmanga95 | 0:772bf4786416 | 41 | GYRO_REGISTER_WHO_AM_I = 0x0F, // 11010100 r |
bmanga95 | 0:772bf4786416 | 42 | GYRO_REGISTER_CTRL_REG1 = 0x20, // 00000111 rw |
bmanga95 | 0:772bf4786416 | 43 | GYRO_REGISTER_CTRL_REG2 = 0x21, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 44 | GYRO_REGISTER_CTRL_REG3 = 0x22, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 45 | GYRO_REGISTER_CTRL_REG4 = 0x23, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 46 | GYRO_REGISTER_CTRL_REG5 = 0x24, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 47 | GYRO_REGISTER_REFERENCE = 0x25, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 48 | GYRO_REGISTER_OUT_TEMP = 0x26, // r |
bmanga95 | 0:772bf4786416 | 49 | GYRO_REGISTER_STATUS_REG = 0x27, // r |
bmanga95 | 0:772bf4786416 | 50 | GYRO_REGISTER_OUT_X_L = 0x28, // r |
bmanga95 | 0:772bf4786416 | 51 | GYRO_REGISTER_OUT_X_H = 0x29, // r |
bmanga95 | 0:772bf4786416 | 52 | GYRO_REGISTER_OUT_Y_L = 0x2A, // r |
bmanga95 | 0:772bf4786416 | 53 | GYRO_REGISTER_OUT_Y_H = 0x2B, // r |
bmanga95 | 0:772bf4786416 | 54 | GYRO_REGISTER_OUT_Z_L = 0x2C, // r |
bmanga95 | 0:772bf4786416 | 55 | GYRO_REGISTER_OUT_Z_H = 0x2D, // r |
bmanga95 | 0:772bf4786416 | 56 | GYRO_REGISTER_FIFO_CTRL_REG = 0x2E, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 57 | GYRO_REGISTER_FIFO_SRC_REG = 0x2F, // r |
bmanga95 | 0:772bf4786416 | 58 | GYRO_REGISTER_INT1_CFG = 0x30, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 59 | GYRO_REGISTER_INT1_SRC = 0x31, // r |
bmanga95 | 0:772bf4786416 | 60 | GYRO_REGISTER_TSH_XH = 0x32, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 61 | GYRO_REGISTER_TSH_XL = 0x33, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 62 | GYRO_REGISTER_TSH_YH = 0x34, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 63 | GYRO_REGISTER_TSH_YL = 0x35, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 64 | GYRO_REGISTER_TSH_ZH = 0x36, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 65 | GYRO_REGISTER_TSH_ZL = 0x37, // 00000000 rw |
bmanga95 | 0:772bf4786416 | 66 | GYRO_REGISTER_INT1_DURATION = 0x38 // 00000000 rw |
bmanga95 | 0:772bf4786416 | 67 | } gyroRegisters_t; |
bmanga95 | 0:772bf4786416 | 68 | /*=========================================================================*/ |
bmanga95 | 0:772bf4786416 | 69 | |
bmanga95 | 0:772bf4786416 | 70 | /*========================================================================= |
bmanga95 | 0:772bf4786416 | 71 | OPTIONAL SPEED SETTINGS |
bmanga95 | 0:772bf4786416 | 72 | -----------------------------------------------------------------------*/ |
bmanga95 | 0:772bf4786416 | 73 | typedef enum |
bmanga95 | 0:772bf4786416 | 74 | { |
bmanga95 | 0:772bf4786416 | 75 | GYRO_RANGE_250DPS = 250, |
bmanga95 | 0:772bf4786416 | 76 | GYRO_RANGE_500DPS = 500, |
bmanga95 | 0:772bf4786416 | 77 | GYRO_RANGE_2000DPS = 2000 |
bmanga95 | 0:772bf4786416 | 78 | } gyroRange_t; |
bmanga95 | 0:772bf4786416 | 79 | /*=========================================================================*/ |
bmanga95 | 0:772bf4786416 | 80 | |
bmanga95 | 0:772bf4786416 | 81 | class Adafruit_L3GD20_Unified : public Adafruit_Sensor |
bmanga95 | 0:772bf4786416 | 82 | { |
bmanga95 | 0:772bf4786416 | 83 | public: |
bmanga95 | 0:772bf4786416 | 84 | Adafruit_L3GD20_Unified(int32_t sensorID = -1); |
bmanga95 | 0:772bf4786416 | 85 | |
bmanga95 | 0:772bf4786416 | 86 | bool begin ( gyroRange_t rng = GYRO_RANGE_250DPS ); |
bmanga95 | 0:772bf4786416 | 87 | void enableAutoRange ( bool enabled ); |
bmanga95 | 0:772bf4786416 | 88 | void getEvent ( sensors_event_t* ); |
bmanga95 | 0:772bf4786416 | 89 | void getSensor ( sensor_t* ); |
bmanga95 | 0:772bf4786416 | 90 | |
bmanga95 | 0:772bf4786416 | 91 | private: |
bmanga95 | 0:772bf4786416 | 92 | void write8 ( byte reg, byte value ); |
bmanga95 | 0:772bf4786416 | 93 | byte read8 ( byte reg ); |
bmanga95 | 0:772bf4786416 | 94 | gyroRange_t _range; |
bmanga95 | 0:772bf4786416 | 95 | int32_t _sensorID; |
bmanga95 | 0:772bf4786416 | 96 | bool _autoRangeEnabled; |
bmanga95 | 0:772bf4786416 | 97 | }; |
bmanga95 | 0:772bf4786416 | 98 | |
bmanga95 | 0:772bf4786416 | 99 | #endif |