Skip to content

Commit e23401c

Browse files
authored
fix #54, calibrate() (#55)
- fix #54, calibrate() function, Kudos to jens-kuerten and MArimont3 - minor edits
1 parent 3b08088 commit e23401c

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.6.0] - 2024-06-22
10+
- fix #54, calibrate() function, Kudos to jens-kuerten and MArimont3
11+
- minor edits
12+
13+
----
14+
915
## [0.5.3] - 2024-05-08
1016
- fix #52, add **uint8_t getAddrress()**
1117
- fix #51, add **bool setDLPFMode(uint8_t mode)** and **uint8_t getDLPFMode()**
1218
- add const float GRAVITY=9.80655;
1319
- minor edits
1420

15-
1621
## [0.5.2] - 2024-01-16
1722
- fix #48, use float variables in example GY521_test_1.ino
1823
- add **void calibrate(uint16_t times)** to API
@@ -72,7 +77,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7277
- update library.json, license, minor edits
7378

7479
## [0.3.5] - 2021-10-20
75-
- update build-CI, badges
80+
- update build-CI, badges
7681
- fix #28 add wakeup to begin().
7782

7883
## [0.3.4] - 2021-07-12
@@ -85,7 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8590
- fix #20 support multiWire
8691

8792
## [0.3.1] - 2021-06-13
88-
- added more unit test
93+
- added more unit test
8994
- some initialization
9095

9196
## [0.3.0] - 2021-04-07

GY521.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: GY521.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.5.3
4+
// VERSION: 0.6.0
55
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
66
// URL: https://github.com/RobTillaart/GY521
77

@@ -78,31 +78,39 @@ void GY521::calibrate(uint16_t times)
7878
bool oldThrottle = _throttle;
7979
_throttle = false;
8080

81-
// set errors to zero
81+
// set all errors to zero, to get the raw reads.
8282
axe = aye = aze = 0;
8383
gxe = gye = gze = 0;
8484

85+
// use local error sums, to calculate the average error.
86+
float _axe = 0, _aye = 0, _aze = 0;
87+
float _gxe = 0, _gye = 0, _gze = 0;
88+
89+
// adjust times if zero.
90+
if (times == 0) times = 1;
91+
92+
// summarize (6x) the measurements.
8593
for (uint16_t i = 0; i < times; i++)
8694
{
8795
read();
88-
axe -= getAccelX();
89-
aye -= getAccelY();
90-
aze -= getAccelZ();
91-
gxe -= getGyroX();
92-
gye -= getGyroY();
93-
gze -= getGyroZ();
96+
_axe -= getAccelX();
97+
_aye -= getAccelY();
98+
_aze -= getAccelZ();
99+
_gxe -= getGyroX();
100+
_gye -= getGyroY();
101+
_gze -= getGyroZ();
94102
}
95103

96-
// adjust calibration errors so table should get all zero's.
104+
// adjust calibration errors so read() should get all zero's on average.
97105
float factor = 1.0 / times;
98-
axe *= factor;
99-
aye *= factor;
100-
aze *= factor;
101-
gxe *= factor;
102-
gye *= factor;
103-
gze *= factor;
104-
105-
// restore throttle state
106+
axe = _axe * factor;
107+
aye = _aye * factor;
108+
aze = _aze * factor;
109+
gxe = _gxe * factor;
110+
gye = _gye * factor;
111+
gze = _gze * factor;
112+
113+
// restore throttle state.
106114
_throttle = oldThrottle;
107115
}
108116

GY521.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: GY521.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.5.3
5+
// VERSION: 0.6.0
66
// PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor
77
// URL: https://github.com/RobTillaart/GY521
88

@@ -11,7 +11,7 @@
1111
#include "Wire.h"
1212

1313

14-
#define GY521_LIB_VERSION (F("0.5.3"))
14+
#define GY521_LIB_VERSION (F("0.6.0"))
1515

1616
const float GRAVITY = 9.80655;
1717

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ It needs to be tested a lot more.
2424
See changelog.md for latest updates.
2525

2626

27+
#### 0.6.0
28+
29+
Fixed a bug in calibration function, making previous versions obsolete.
30+
31+
2732
#### 0.5.0 Breaking change
2833

2934
Version 0.5.0 introduced a breaking change.

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/GY521.git"
1717
},
18-
"version": "0.5.3",
18+
"version": "0.6.0",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=GY521
2-
version=0.5.3
2+
version=0.6.0
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for GY521 angle measurement

0 commit comments

Comments
 (0)