0.3.4 GY521

This commit is contained in:
rob tillaart 2021-07-12 20:19:59 +02:00
parent 0c3d354743
commit 4399f8ea45
5 changed files with 16 additions and 11 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: GY521.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.3
// VERSION: 0.3.4
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
// URL: https://github.com/RobTillaart/GY521
//
@ -21,6 +21,7 @@
// 0.3.1 2021-06-13 added more unit test + some initialization
// 0.3.2 2021-07-05 fix #20 support multiWire
// 0.3.3 2021-07-05 fix #22 improve maths
// 0.3.4 2021-07-12 fix #24 improve precision
#include "GY521.h"
@ -93,14 +94,16 @@ bool GY521::wakeup()
int16_t GY521::read()
{
uint32_t now = millis();
if (_throttle)
{
if ((millis() - _lastTime) < _throttleTime)
if ((now - _lastTime) < _throttleTime)
{
// not an error.
return GY521_THROTTLED;
}
}
_lastTime = now;
// Connected ?
_wire->beginTransmission(_address);
@ -129,10 +132,11 @@ int16_t GY521::read()
_gy = _WireRead2(); // GYRO_YOUT_H GYRO_YOUT_L
_gz = _WireRead2(); // GYRO_ZOUT_H GYRO_ZOUT_L
// time interval
uint32_t now = millis();
float duration = (now - _lastTime) * 0.001; // time in seconds.
_lastTime = now;
// duration interval
now = micros();
float duration = (now - _lastMicros) * 1e-6; // duration in seconds.
_lastMicros = now;
// next lines might be merged per axis.

View File

@ -2,7 +2,7 @@
//
// FILE: GY521.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.3
// VERSION: 0.3.4
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
// URL: https://github.com/RobTillaart/GY521
//
@ -15,7 +15,7 @@
#include "Wire.h"
#define GY521_LIB_VERSION (F("0.3.3"))
#define GY521_LIB_VERSION (F("0.3.4"))
#ifndef GY521_THROTTLE_TIME
@ -104,6 +104,7 @@ private:
bool _throttle = true; // to prevent reading too fast
uint16_t _throttleTime = GY521_THROTTLE_TIME;
uint32_t _lastTime = 0; // to measure duration for math & throttle
uint32_t _lastMicros = 0; // to measure duration for math & throttle
int16_t _error = GY521_OK; // initially everything is OK
uint8_t _afs = 0; // sensitivity factor

View File

@ -1,7 +1,7 @@
//
// FILE: GY521_registers.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.3
// VERSION: see GY521.cpp
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
// URL: https://github.com/RobTillaart/GY521
//

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/GY521.git"
},
"version": "0.3.3",
"version": "0.3.4",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"

View File

@ -1,5 +1,5 @@
name=GY521
version=0.3.3
version=0.3.4
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for GY521 angle measurement