Skip to content

Commit

Permalink
refactor API, begin() (#45)
Browse files Browse the repository at this point in the history
- refactor API, begin()
- update readme.md
  • Loading branch information
RobTillaart authored Dec 5, 2023
1 parent fd40f46 commit f764535
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 38 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 1 addition & 15 deletions GY521.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions GY521.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion examples/GY521_angle/GY521_angle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: GY521_angle.ino
// AUTHOR: Rob Tillaart
// PURPOSE: read angleX, angleY, angleZ
// DATE: 2022-06-06


#include "GY521.h"
Expand Down
3 changes: 1 addition & 2 deletions examples/GY521_performance/GY521_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: GY521_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: minimal demo
// DATE: 2021-06-13


#include "GY521.h"
Expand Down Expand Up @@ -47,5 +46,5 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --

9 changes: 4 additions & 5 deletions examples/GY521_pitch_roll_yaw/GY521_pitch_roll_yaw.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -70,5 +69,5 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --

11 changes: 5 additions & 6 deletions examples/GY521_readCalibration_1/GY521_readCalibration_1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -113,5 +112,5 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/GY521_test_1/GY521_test_1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion examples/GY521_test_2/GY521_test_2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: GY521_test_2.ino
// AUTHOR: Rob Tillaart
// PURPOSE: test set/get functions
// DATE: 2020-08-06


#include "GY521.h"
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GY521
version=0.4.1
version=0.5.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for GY521 angle measurement
Expand Down
10 changes: 10 additions & 0 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ unittest(test_constructor)
{
GY521 sensor(0x69);

Wire.begin();
sensor.begin();
assertEqual(GY521_OK, sensor.getError());

Expand All @@ -54,6 +55,8 @@ unittest(test_constructor)
unittest(test_get_set_throttle)
{
GY521 sensor(0x69);

Wire.begin();
sensor.begin();
assertEqual(GY521_OK, sensor.getError());

Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -155,5 +164,6 @@ unittest(test_initial_calibration_errors)

unittest_main()


// -- END OF FILE --

0 comments on commit f764535

Please sign in to comment.