Giter Club home page Giter Club logo

gy521's Introduction

Arduino CI Arduino-lint JSON check License: MIT GitHub release

GY521

Arduino library for I2C GY521 accelerometer-gyroscope sensor a.k.a. MCU-6050.

Description

Experimental library for GY521 a.k.a. MCU-6050.

Library is work in progress, in fact it is extracted and extended from an old project. It needs to be tested a lot more.

Examples

  • GY521_angle read angleX, angleY, angleZ.
  • GY521_performance measure performance.
  • GY521_pitch_roll_yaw to get pitch roll yaw.
  • GY521_readCalibration_1 read calibration values / errors for a flat sensor.
  • GY521_readCalibration_2 generate calibration code snippet.
  • GY521_test_1 test working of the sensor.
  • GY521_test_2 test set/get functions.

Breakout board

From left to right

pin pinName description notes
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

Address

AD0 connected to GND => 0x68 AD0 connected to VCC => 0x69

Calibration (short version for now)

  1. load and run calibration example
    it shows a header containing 6 numbers and 10 lines of 8 numbers
  2. wait until the middle 6 of the longer lines stabilize (should all be 0)
  3. copy the 6 numbers above the axe aye aze as these are the numbers needed.

Interface

#include "GY521.h"

Constructor

  • 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.
  • void reset() set all internal values to 0 and throttle time to 10 ms.
  • bool wakeUp() idem.

Throttle

  • 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.

Read

Set before read

  • 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
  • uint8_t getGyroSensitivity() returns 0, 1, 2, 3

Actual read

  • 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().

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 rotation in a same direction internal variables will overflow and new movements (angles) will get lost as insignificant digits.

Call after read

Note that multiple calls will return the same value. One must explicitly call read() to get new values.

  • 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
  • float getPitch() idem. Returns 0.00 - 359.99.
  • float getRoll() idem. Returns 0.00 - 359.99.
  • float getYaw() idem. Returns 0.00 - 359.99.

Register access

Read the register PDF for the specific value and meaning of registers.

  • uint8_t setRegister(uint8_t reg, uint8_t value)
  • uint8_t getRegister(uint8_t reg)

documents

  • check details - MPU-6000-Register-Map1.pdf

Operation

See examples, use with care

Future

Must

  • improve documentation

Should

  • test test and test ...(ESP too)

Could

  • calibrate sketch could print code snippet to include...

Wont

  • look for maths optimizations (atan, hypot, performance)
    • ==> hypot optimized.
    • other ideas affect accuracy, so unless new ideas arise.
  • calibrate function in the lib
    • not as lib will grow too large.

gy521's People

Contributors

robtillaart avatar exoskye avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.