GY-63_MS5611/libraries/GY521/README.md

160 lines
5.3 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/GY521/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-10-20 12:48:35 -04:00
[![Arduino-lint](https://github.com/RobTillaart/GY521/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/GY521/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/GY521/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/GY521/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/GY521/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/GY521.svg?maxAge=3600)](https://github.com/RobTillaart/GY521/releases)
2021-12-18 12:14:36 -05:00
2021-01-29 06:31:58 -05:00
# GY521
2021-12-18 12:14:36 -05:00
Arduino library for I2C GY521 accelerometer-gyroscope sensor a.k.a. MCU-6050.
2021-01-29 06:31:58 -05:00
## Description
2021-12-18 12:14:36 -05:00
Experimental library for GY521 a.k.a. MCU-6050.
2021-01-29 06:31:58 -05:00
2021-07-05 13:35:46 -04:00
Library is work in progress, in fact it is extracted and extended from an old project.
2021-01-29 06:31:58 -05:00
It needs to be tested a lot more.
2021-07-05 13:35:46 -04:00
#### Examples
2021-01-29 06:31:58 -05:00
- calibration example to determine the offsets needed
- example to read values.
- test sketch to test get / set values.
2021-07-05 13:35:46 -04:00
- example to get pitch roll yaw.
- performance sketch.
2021-01-29 06:31:58 -05:00
2021-02-06 09:52:51 -05:00
## Breakout board
2021-07-05 13:35:46 -04:00
From left to right
2021-02-06 09:52:51 -05:00
2021-07-05 13:35:46 -04:00
| pin | pinName | description |
2021-02-06 09:52:51 -05:00
|:----:|:--------|:----------------|
| 0 | VCC | +5V |
| 1 | GND | ground |
| 2 | SCL | I2C clock |
| 3 | SDA | I2C data |
| 4 | XDA | auxiliary data | see datasheet
| 5 | XCL | auxiliary clock | see datasheet
| 6 | AD0 | address |
| 7 | INT | interrupt |
2021-07-05 13:35:46 -04:00
2021-02-06 09:52:51 -05:00
#### Address
2021-07-05 13:35:46 -04:00
2021-02-06 09:52:51 -05:00
AD0 connected to GND => 0x68
AD0 connected to VCC => 0x69
2021-01-29 06:31:58 -05:00
## Calibration (short version for now)
1. load and run calibration example
it shows a header containing 6 numbers and 10 lines of 8 numbers
1. wait until the middle 6 of the longer lines stabilize (should all be 0)
1. copy the 6 numbers above the axe aye aze as these are the numbers needed.
## Interface
### Constructor
2021-07-05 13:35:46 -04:00
- **GY521(uint8_t address = 0x69, , TwoWire \*wire = &Wire)** Constructor with default address.
0x68 is also a valid address. The wire argument is optional to select Wire1 Wire2 etc. on some boards.
- **bool begin(uint8_t sda, uint8_t scl)** begin for ESP32 et al. Returns true if address can be found on I2C bus.
- **bool begin()** Returns true if address can be found on I2C bus.
- **bool isConnected()** returns true if device can be found on I2C bus.
2021-06-13 10:00:27 -04:00
- **void reset()** set all internal values to 0 and throttle time to 10 ms.
2021-12-18 12:14:36 -05:00
- **bool wakeUp()** idem.
2021-01-29 06:31:58 -05:00
### Throttle
2021-07-05 13:35:46 -04:00
- **void setThrottle(bool throttle = true)** throttle to force "delay" between reads.
- **bool getThrottle()** returns true if throttle mode is set.
- **void setThrottleTime(uint16_t ti )** throttle time in milliseconds, max = 65535 = 1++ minute
- **uint16_t getThrottleTime()** returns throttle time set.
2021-01-29 06:31:58 -05:00
2021-07-05 13:35:46 -04:00
### READ
#### Set before read
2021-01-29 06:31:58 -05:00
- **bool setAccelSensitivity(uint8_t as)** as = 0, 1, 2, 3 ==> 2g 4g 8g 16g
- **uint8_t getAccelSensitivity()** returns 0, 1, 2, 3
- **bool setGyroSensitivity(uint8_t gs)** gs = 0,1,2,3 ==> 250, 500, 1000, 2000 degrees/second
2022-07-27 06:42:05 -04:00
- **uint8_t getGyroSensitivity()** returns 0, 1, 2, 3
2021-01-29 06:31:58 -05:00
#### Actual read
2022-07-27 06:42:05 -04:00
- **int16_t read()** returns status = GY521_OK on success.
- **int16_t readAccel()** read accelerometer only to speed up interaction. This call does update the throttle timer.
returns status = GY521_OK on success.
- **int16_t readGyro()** read gyroscope only to speed up interaction. This call does update the throttle timer.
returns status = GY521_OK on success.
Note: for pitch roll yaw you need to call **read()**.
- **int16_t readTemperature()** read temperature only, does **not** update the throttle timer.
returns status = GY521_OK on success.
- **uint32_t lastTime()** last time sensor is actually read. In milliseconds. Not updated by readTemperature().
2021-01-29 06:31:58 -05:00
2022-10-08 09:41:16 -04:00
Since version 0.3.8 the **read()** and **readGyro()** function is updated to keep the range of **getPitch()**,
**getRoll()** and **getYaw()** in the range 0..360 degrees. (Issue #36).
Problem is that with continuous roatation in a same direction internal variables will overflow and new
movements (angles) will get lost as insignificant digits.
2021-01-29 06:31:58 -05:00
#### Call after read
2021-07-05 13:35:46 -04:00
Note that multiple calls will return the same value. One must explicitly call **read()** to get new values.
2021-01-29 06:31:58 -05:00
- **float getAccelX()** idem
- **float getAccelY()** idem
- **float getAccelZ()** idem
- **float getAngleX()** idem
- **float getAngleY()** idem
- **float getAngleZ()** idem
- **float getTemperature()** idem
- **float getGyroX()** idem
- **float getGyroY()** idem
- **float getGyroZ()** idem
2022-10-08 09:41:16 -04:00
- **float getPitch()** idem. Returns 0.00 - 359.99.
- **float getRoll()** idem. Returns 0.00 - 359.99.
- **float getYaw()** idem. Returns 0.00 - 359.99.
2021-01-29 06:31:58 -05:00
### Register access
2021-07-05 13:35:46 -04:00
Read the register PDF for the specific value and meaning of registers.
2021-01-29 06:31:58 -05:00
- **uint8_t setRegister(uint8_t reg, uint8_t value)**
- **uint8_t getRegister(uint8_t reg)**
2021-12-18 12:14:36 -05:00
## documents
- check details - MPU-6000-Register-Map1.pdf
## Operation
See examples, use with care
2021-01-29 06:31:58 -05:00
## Future
**Should**
- test test and test ...(ESP too)
- improve documentation
2021-07-05 13:35:46 -04:00
- look for maths optimizations (atan, hypot, performance)
2021-01-29 06:31:58 -05:00
**Could**
- calibrate function in the lib ? (think not as lib might grow?)
- calibrate sketch could print code snippet to include...
2022-07-27 06:42:05 -04:00