From 9658f64ee548495326d79ab9925bcd7351331303 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 5 Dec 2023 18:02:00 +0100 Subject: [PATCH] 0.5.0 GY521 --- libraries/GY521/CHANGELOG.md | 7 ++++++- libraries/GY521/GY521.cpp | 16 +--------------- libraries/GY521/GY521.h | 4 ++-- libraries/GY521/README.md | 10 +++++++++- .../GY521/examples/GY521_angle/GY521_angle.ino | 1 - .../GY521_performance/GY521_performance.ino | 3 +-- .../GY521_pitch_roll_yaw.ino | 9 ++++----- .../GY521_readCalibration_1.ino | 11 +++++------ .../GY521_readCalibration_2.ino | 1 - .../GY521/examples/GY521_test_1/GY521_test_1.ino | 1 - .../GY521/examples/GY521_test_2/GY521_test_2.ino | 1 - libraries/GY521/library.json | 2 +- libraries/GY521/library.properties | 2 +- libraries/GY521/test/unit_test_001.cpp | 10 ++++++++++ 14 files changed, 40 insertions(+), 38 deletions(-) diff --git a/libraries/GY521/CHANGELOG.md b/libraries/GY521/CHANGELOG.md index 1b75f8c3..94aec136 100644 --- a/libraries/GY521/CHANGELOG.md +++ b/libraries/GY521/CHANGELOG.md @@ -6,11 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.0] - 2023-12-05 +- refactor API, begin() +- update readme.md + +---- + ## [0.4.1] - 2023-11-02 - update readme.md - minor edits - ## [0.4.0] - 2023-06-11 - fix #42 roll + pitch "jumps" after full rotation. - fixed normalization code. diff --git a/libraries/GY521/GY521.cpp b/libraries/GY521/GY521.cpp index bc361ec0..28f6e9d6 100644 --- a/libraries/GY521/GY521.cpp +++ b/libraries/GY521/GY521.cpp @@ -1,7 +1,7 @@ // // FILE: GY521.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.4.1 +// VERSION: 0.5.0 // PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor // URL: https://github.com/RobTillaart/GY521 @@ -29,22 +29,8 @@ GY521::GY521(uint8_t address, TwoWire *wire) } -#if defined (ESP8266) || defined(ESP32) -bool GY521::begin(uint8_t sda, uint8_t scl) -{ - _wire->begin(sda, scl); - if (isConnected()) - { - return wakeup(); - } - return false; -} -#endif - - bool GY521::begin() { - _wire->begin(); if (isConnected()) { return wakeup(); diff --git a/libraries/GY521/GY521.h b/libraries/GY521/GY521.h index 1a442c6f..b3a4c158 100644 --- a/libraries/GY521/GY521.h +++ b/libraries/GY521/GY521.h @@ -2,7 +2,7 @@ // // FILE: GY521.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.1 +// VERSION: 0.5.0 // PURPOSE: Arduino library for I2C GY521 accelerometer-gyroscope sensor // URL: https://github.com/RobTillaart/GY521 @@ -11,7 +11,7 @@ #include "Wire.h" -#define GY521_LIB_VERSION (F("0.4.1")) +#define GY521_LIB_VERSION (F("0.5.0")) // THROTTLE TIMING diff --git a/libraries/GY521/README.md b/libraries/GY521/README.md index 2a947258..29de0e62 100644 --- a/libraries/GY521/README.md +++ b/libraries/GY521/README.md @@ -23,6 +23,14 @@ It needs to be tested a lot more. See changelog.md for latest updates. +#### 0.5.0 Breaking change + +Version 0.5.0 introduced a breaking change. +You cannot set the pins in **begin()** any more. +This reduces the dependency of processor dependent Wire implementations. +The user has to call **Wire.begin()** and can optionally set the Wire pins +before calling **begin()**. + #### Examples @@ -75,8 +83,8 @@ AD0 connected to VCC => 0x69 - **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. +Note call **Wire.begin()** before **begin()**. - **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. diff --git a/libraries/GY521/examples/GY521_angle/GY521_angle.ino b/libraries/GY521/examples/GY521_angle/GY521_angle.ino index 34b1daf2..e6121dca 100644 --- a/libraries/GY521/examples/GY521_angle/GY521_angle.ino +++ b/libraries/GY521/examples/GY521_angle/GY521_angle.ino @@ -2,7 +2,6 @@ // FILE: GY521_angle.ino // AUTHOR: Rob Tillaart // PURPOSE: read angleX, angleY, angleZ -// DATE: 2022-06-06 #include "GY521.h" diff --git a/libraries/GY521/examples/GY521_performance/GY521_performance.ino b/libraries/GY521/examples/GY521_performance/GY521_performance.ino index 99665bc4..69886528 100644 --- a/libraries/GY521/examples/GY521_performance/GY521_performance.ino +++ b/libraries/GY521/examples/GY521_performance/GY521_performance.ino @@ -2,7 +2,6 @@ // FILE: GY521_performance.ino // AUTHOR: Rob Tillaart // PURPOSE: minimal demo -// DATE: 2021-06-13 #include "GY521.h" @@ -47,5 +46,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/GY521/examples/GY521_pitch_roll_yaw/GY521_pitch_roll_yaw.ino b/libraries/GY521/examples/GY521_pitch_roll_yaw/GY521_pitch_roll_yaw.ino index 9dd669b0..255593bc 100644 --- a/libraries/GY521/examples/GY521_pitch_roll_yaw/GY521_pitch_roll_yaw.ino +++ b/libraries/GY521/examples/GY521_pitch_roll_yaw/GY521_pitch_roll_yaw.ino @@ -2,7 +2,6 @@ // FILE: GY521_pitch_roll_yaw.ino // AUTHOR: Rob Tillaart // PURPOSE: demo pitch roll yaw -// DATE: 2020-08-06 #include "GY521.h" @@ -29,13 +28,13 @@ void setup() Serial.println("\tCould not connect to GY521"); delay(1000); } - sensor.setAccelSensitivity(2); // 8g - sensor.setGyroSensitivity(1); // 500 degrees/s + sensor.setAccelSensitivity(2); // 8g + sensor.setGyroSensitivity(1); // 500 degrees/s sensor.setThrottle(); Serial.println("start..."); - // set calibration values from calibration sketch. + // set calibration values from calibration sketch. sensor.axe = 0.574; sensor.aye = -0.002; sensor.aze = -1.043; @@ -70,5 +69,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/GY521/examples/GY521_readCalibration_1/GY521_readCalibration_1.ino b/libraries/GY521/examples/GY521_readCalibration_1/GY521_readCalibration_1.ino index 86d8d3e2..e5ab4ec6 100644 --- a/libraries/GY521/examples/GY521_readCalibration_1/GY521_readCalibration_1.ino +++ b/libraries/GY521/examples/GY521_readCalibration_1/GY521_readCalibration_1.ino @@ -2,7 +2,6 @@ // FILE: GY521_readCalibration_1.ino // AUTHOR: Rob Tillaart // PURPOSE: read the calibration values / errors for a flat sensor. -// DATE: 2020-07-14 #include "GY521.h" @@ -31,11 +30,11 @@ void setup() Serial.println("Could not connect to GY521"); } // adjust when needed. - sensor.setAccelSensitivity(0); // 2g - sensor.setGyroSensitivity(0); // 250 degrees/s + sensor.setAccelSensitivity(0); // 2g + sensor.setGyroSensitivity(0); // 250 degrees/s sensor.setThrottle(false); - // set all calibration errors to zero + // set all calibration errors to zero sensor.axe = 0; sensor.aye = 0; sensor.aze = 0; @@ -100,7 +99,7 @@ void loop() Serial.print(t * 0.05, 2); Serial.println(); - // adjust calibration errors so table should get all zero's. + // adjust calibration errors so table should get all zero's. sensor.axe += ax * 0.05; sensor.aye += ay * 0.05; sensor.aze += az * 0.05; @@ -113,5 +112,5 @@ void loop() } -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/GY521/examples/GY521_readCalibration_2/GY521_readCalibration_2.ino b/libraries/GY521/examples/GY521_readCalibration_2/GY521_readCalibration_2.ino index 7c44487e..a4694de8 100644 --- a/libraries/GY521/examples/GY521_readCalibration_2/GY521_readCalibration_2.ino +++ b/libraries/GY521/examples/GY521_readCalibration_2/GY521_readCalibration_2.ino @@ -2,7 +2,6 @@ // FILE: readCalibration_2.ino // AUTHOR: Rob Tillaart // PURPOSE: read the calibration values / errors for a flat sensor. -// DATE: 2022-06-07 #include "GY521.h" diff --git a/libraries/GY521/examples/GY521_test_1/GY521_test_1.ino b/libraries/GY521/examples/GY521_test_1/GY521_test_1.ino index 7bfd68ee..4d44ce71 100644 --- a/libraries/GY521/examples/GY521_test_1/GY521_test_1.ino +++ b/libraries/GY521/examples/GY521_test_1/GY521_test_1.ino @@ -2,7 +2,6 @@ // FILE: GY521_test_1.ino // AUTHOR: Rob Tillaart // PURPOSE: minimal demo to test working of the sensor. -// DATE: 2020-07-01 #include "GY521.h" diff --git a/libraries/GY521/examples/GY521_test_2/GY521_test_2.ino b/libraries/GY521/examples/GY521_test_2/GY521_test_2.ino index 52ceca95..e5758310 100644 --- a/libraries/GY521/examples/GY521_test_2/GY521_test_2.ino +++ b/libraries/GY521/examples/GY521_test_2/GY521_test_2.ino @@ -2,7 +2,6 @@ // FILE: GY521_test_2.ino // AUTHOR: Rob Tillaart // PURPOSE: test set/get functions -// DATE: 2020-08-06 #include "GY521.h" diff --git a/libraries/GY521/library.json b/libraries/GY521/library.json index 5861414d..62811cd1 100644 --- a/libraries/GY521/library.json +++ b/libraries/GY521/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/GY521.git" }, - "version": "0.4.1", + "version": "0.5.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/GY521/library.properties b/libraries/GY521/library.properties index a5afeb79..b5801f4e 100644 --- a/libraries/GY521/library.properties +++ b/libraries/GY521/library.properties @@ -1,5 +1,5 @@ name=GY521 -version=0.4.1 +version=0.5.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for GY521 angle measurement diff --git a/libraries/GY521/test/unit_test_001.cpp b/libraries/GY521/test/unit_test_001.cpp index 3a804023..4a51110b 100644 --- a/libraries/GY521/test/unit_test_001.cpp +++ b/libraries/GY521/test/unit_test_001.cpp @@ -44,6 +44,7 @@ unittest(test_constructor) { GY521 sensor(0x69); + Wire.begin(); sensor.begin(); assertEqual(GY521_OK, sensor.getError()); @@ -54,6 +55,8 @@ unittest(test_constructor) unittest(test_get_set_throttle) { GY521 sensor(0x69); + + Wire.begin(); sensor.begin(); assertEqual(GY521_OK, sensor.getError()); @@ -76,6 +79,8 @@ unittest(test_get_set_throttle) unittest(test_get_set_sensitivity) { GY521 sensor(0x69); + + Wire.begin(); sensor.begin(); fprintf(stderr, "setAccelSensitivity() - fails \n"); @@ -116,6 +121,8 @@ unittest(test_initial_values) { GY521 sensor(0x69); + Wire.begin(); + assertEqualFloat(0, sensor.getAccelX(), 0.0001); assertEqualFloat(0, sensor.getAccelY(), 0.0001); assertEqualFloat(0, sensor.getAccelZ(), 0.0001); @@ -143,6 +150,8 @@ unittest(test_initial_calibration_errors) { GY521 sensor(0x69); + Wire.begin(); + assertEqualFloat(0, sensor.axe, 0.0001); assertEqualFloat(0, sensor.aye, 0.0001); assertEqualFloat(0, sensor.aze, 0.0001); @@ -155,5 +164,6 @@ unittest(test_initial_calibration_errors) unittest_main() + // -- END OF FILE --