Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of L3GD20 by
L3GD20.h@0:62dfce144cf7, 2013-02-21 (annotated)
- Committer:
- bclaus
- Date:
- Thu Feb 21 00:21:23 2013 +0000
- Revision:
- 0:62dfce144cf7
Set of code to work with L3GD20 on pololu's minimu-9 v2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bclaus | 0:62dfce144cf7 | 1 | /* Copyright (c) 2011 Pololu Corporation. For more information, see |
bclaus | 0:62dfce144cf7 | 2 | * |
bclaus | 0:62dfce144cf7 | 3 | * http://www.pololu.com/ |
bclaus | 0:62dfce144cf7 | 4 | * http://forum.pololu.com/ |
bclaus | 0:62dfce144cf7 | 5 | * |
bclaus | 0:62dfce144cf7 | 6 | * Permission is hereby granted, free of charge, to any person |
bclaus | 0:62dfce144cf7 | 7 | * obtaining a copy of this software and associated documentation |
bclaus | 0:62dfce144cf7 | 8 | * files (the "Software"), to deal in the Software without |
bclaus | 0:62dfce144cf7 | 9 | * restriction, including without limitation the rights to use, |
bclaus | 0:62dfce144cf7 | 10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell |
bclaus | 0:62dfce144cf7 | 11 | * copies of the Software, and to permit persons to whom the |
bclaus | 0:62dfce144cf7 | 12 | * Software is furnished to do so, subject to the following |
bclaus | 0:62dfce144cf7 | 13 | * conditions: |
bclaus | 0:62dfce144cf7 | 14 | * |
bclaus | 0:62dfce144cf7 | 15 | * The above copyright notice and this permission notice shall be |
bclaus | 0:62dfce144cf7 | 16 | * included in all copies or substantial portions of the Software. |
bclaus | 0:62dfce144cf7 | 17 | * |
bclaus | 0:62dfce144cf7 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
bclaus | 0:62dfce144cf7 | 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
bclaus | 0:62dfce144cf7 | 20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
bclaus | 0:62dfce144cf7 | 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
bclaus | 0:62dfce144cf7 | 22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
bclaus | 0:62dfce144cf7 | 23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
bclaus | 0:62dfce144cf7 | 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
bclaus | 0:62dfce144cf7 | 25 | * OTHER DEALINGS IN THE SOFTWARE. |
bclaus | 0:62dfce144cf7 | 26 | */ |
bclaus | 0:62dfce144cf7 | 27 | |
bclaus | 0:62dfce144cf7 | 28 | #ifndef __L3GD20_H |
bclaus | 0:62dfce144cf7 | 29 | #define __L3GD20_H |
bclaus | 0:62dfce144cf7 | 30 | |
bclaus | 0:62dfce144cf7 | 31 | #include "mbed.h" |
bclaus | 0:62dfce144cf7 | 32 | |
bclaus | 0:62dfce144cf7 | 33 | // register addresses |
bclaus | 0:62dfce144cf7 | 34 | |
bclaus | 0:62dfce144cf7 | 35 | #define L3GD20_WHO_AM_I 0x0F |
bclaus | 0:62dfce144cf7 | 36 | |
bclaus | 0:62dfce144cf7 | 37 | #define L3GD20_CTRL_REG1 0x20 |
bclaus | 0:62dfce144cf7 | 38 | #define L3GD20_CTRL_REG2 0x21 |
bclaus | 0:62dfce144cf7 | 39 | #define L3GD20_CTRL_REG3 0x22 |
bclaus | 0:62dfce144cf7 | 40 | #define L3GD20_CTRL_REG4 0x23 |
bclaus | 0:62dfce144cf7 | 41 | #define L3GD20_CTRL_REG5 0x24 |
bclaus | 0:62dfce144cf7 | 42 | #define L3GD20_REFERENCE 0x25 |
bclaus | 0:62dfce144cf7 | 43 | #define L3GD20_OUT_TEMP 0x26 |
bclaus | 0:62dfce144cf7 | 44 | #define L3GD20_STATUS_REG 0x27 |
bclaus | 0:62dfce144cf7 | 45 | |
bclaus | 0:62dfce144cf7 | 46 | #define L3GD20_OUT_X_L 0x28 |
bclaus | 0:62dfce144cf7 | 47 | #define L3GD20_OUT_X_H 0x29 |
bclaus | 0:62dfce144cf7 | 48 | #define L3GD20_OUT_Y_L 0x2A |
bclaus | 0:62dfce144cf7 | 49 | #define L3GD20_OUT_Y_H 0x2B |
bclaus | 0:62dfce144cf7 | 50 | #define L3GD20_OUT_Z_L 0x2C |
bclaus | 0:62dfce144cf7 | 51 | #define L3GD20_OUT_Z_H 0x2D |
bclaus | 0:62dfce144cf7 | 52 | |
bclaus | 0:62dfce144cf7 | 53 | #define L3GD20_FIFO_CTRL_REG 0x2E |
bclaus | 0:62dfce144cf7 | 54 | #define L3GD20_FIFO_SRC_REG 0x2F |
bclaus | 0:62dfce144cf7 | 55 | |
bclaus | 0:62dfce144cf7 | 56 | #define L3GD20_INT1_CFG 0x30 |
bclaus | 0:62dfce144cf7 | 57 | #define L3GD20_INT1_SRC 0x31 |
bclaus | 0:62dfce144cf7 | 58 | #define L3GD20_INT1_THS_XH 0x32 |
bclaus | 0:62dfce144cf7 | 59 | #define L3GD20_INT1_THS_XL 0x33 |
bclaus | 0:62dfce144cf7 | 60 | #define L3GD20_INT1_THS_YH 0x34 |
bclaus | 0:62dfce144cf7 | 61 | #define L3GD20_INT1_THS_YL 0x35 |
bclaus | 0:62dfce144cf7 | 62 | #define L3GD20_INT1_THS_ZH 0x36 |
bclaus | 0:62dfce144cf7 | 63 | #define L3GD20_INT1_THS_ZL 0x37 |
bclaus | 0:62dfce144cf7 | 64 | #define L3GD20_INT1_DURATION 0x38 |
bclaus | 0:62dfce144cf7 | 65 | |
bclaus | 0:62dfce144cf7 | 66 | /** Interface library for the ST L3GD20 3-axis gyro |
bclaus | 0:62dfce144cf7 | 67 | * |
bclaus | 0:62dfce144cf7 | 68 | * Ported from Pololu L3GD20 library for Arduino by |
bclaus | 0:62dfce144cf7 | 69 | * |
bclaus | 0:62dfce144cf7 | 70 | * @code |
bclaus | 0:62dfce144cf7 | 71 | * #include "mbed.h" |
bclaus | 0:62dfce144cf7 | 72 | * #include "L3GD20.h" |
bclaus | 0:62dfce144cf7 | 73 | * L3GD20 gyro(p28, p27); |
bclaus | 0:62dfce144cf7 | 74 | * ... |
bclaus | 0:62dfce144cf7 | 75 | * int g[3]; |
bclaus | 0:62dfce144cf7 | 76 | * gyro.read(g); |
bclaus | 0:62dfce144cf7 | 77 | * @endcode |
bclaus | 0:62dfce144cf7 | 78 | */ |
bclaus | 0:62dfce144cf7 | 79 | class L3GD20 |
bclaus | 0:62dfce144cf7 | 80 | { |
bclaus | 0:62dfce144cf7 | 81 | public: |
bclaus | 0:62dfce144cf7 | 82 | /** Create a new L3GD20 I2C interface |
bclaus | 0:62dfce144cf7 | 83 | * @param sda is the pin for the I2C SDA line |
bclaus | 0:62dfce144cf7 | 84 | * @param scl is the pin for the I2C SCL line |
bclaus | 0:62dfce144cf7 | 85 | */ |
bclaus | 0:62dfce144cf7 | 86 | L3GD20(PinName sda, PinName scl); |
bclaus | 0:62dfce144cf7 | 87 | |
bclaus | 0:62dfce144cf7 | 88 | /** Read gyro values |
bclaus | 0:62dfce144cf7 | 89 | * @param g Array containing x, y, and z gyro values |
bclaus | 0:62dfce144cf7 | 90 | * @return g Array containing x, y, and z gyro values |
bclaus | 0:62dfce144cf7 | 91 | */ |
bclaus | 0:62dfce144cf7 | 92 | bool read(float *gx, float *gy, float *gz); |
bclaus | 0:62dfce144cf7 | 93 | |
bclaus | 0:62dfce144cf7 | 94 | private: |
bclaus | 0:62dfce144cf7 | 95 | I2C _L3GD20; |
bclaus | 0:62dfce144cf7 | 96 | float gx, gy, gz; |
bclaus | 0:62dfce144cf7 | 97 | |
bclaus | 0:62dfce144cf7 | 98 | bool write_reg(int addr_i2c,int addr_reg, char v); |
bclaus | 0:62dfce144cf7 | 99 | bool read_reg(int addr_i2c,int addr_reg, char *v); |
bclaus | 0:62dfce144cf7 | 100 | bool recv(char sad, char sub, char *buf, int length); |
bclaus | 0:62dfce144cf7 | 101 | }; |
bclaus | 0:62dfce144cf7 | 102 | |
bclaus | 0:62dfce144cf7 | 103 | #endif |