From b400a6baa38687c5a5216f36be1f11cfaa88399f Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Tue, 2 Apr 2024 15:07:44 +0200 Subject: [PATCH] improve getCumulativePosition() (#63) - improve **getCumulativePosition()**, catch I2C error, see #62 - update readme.md (incl reorder future work). - update GitHub actions - minor edits --- .github/FUNDING.yml | 3 +- .github/workflows/arduino-lint.yml | 3 +- .github/workflows/arduino_test_runner.yml | 4 +- .github/workflows/jsoncheck.yml | 5 ++- AS5600.cpp | 3 +- AS5600.h | 4 +- CHANGELOG.md | 7 ++++ README.md | 38 +++++++++---------- .../AS5600_burn_conf_mang.ino | 2 +- examples/AS5600_demo/AS5600_demo.ino | 2 +- .../AS5600_demo_ESP32/AS5600_demo_ESP32.ino | 2 +- .../AS5600_demo_software_direction.ino | 4 +- .../AS5600_demo_two_I2C.ino | 2 +- .../AS5600_resetCumulativeCounter.ino | 4 +- library.json | 2 +- library.properties | 2 +- 16 files changed, 50 insertions(+), 37 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 90d9ab4..2859c15 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,5 @@ # These are supported funding model platforms -github: RobTillaart +github: RobTillaart +custom: "https://www.paypal.me/robtillaart" diff --git a/.github/workflows/arduino-lint.yml b/.github/workflows/arduino-lint.yml index 8a26f14..70d8d1c 100644 --- a/.github/workflows/arduino-lint.yml +++ b/.github/workflows/arduino-lint.yml @@ -5,8 +5,9 @@ on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: arduino/arduino-lint-action@v1 with: library-manager: update diff --git a/.github/workflows/arduino_test_runner.yml b/.github/workflows/arduino_test_runner.yml index fadfa90..be74547 100644 --- a/.github/workflows/arduino_test_runner.yml +++ b/.github/workflows/arduino_test_runner.yml @@ -6,12 +6,14 @@ on: [push, pull_request] jobs: runTest: runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: 2.6 - run: | + # sudo sysctl vm.mmap_rnd_bits=28 gem install arduino_ci arduino_ci.rb diff --git a/.github/workflows/jsoncheck.yml b/.github/workflows/jsoncheck.yml index 37a1129..fd05f5f 100644 --- a/.github/workflows/jsoncheck.yml +++ b/.github/workflows/jsoncheck.yml @@ -9,10 +9,11 @@ on: jobs: test: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: json-syntax-check - uses: limitusus/json-syntax-check@v1 + uses: limitusus/json-syntax-check@v2 with: pattern: "\\.json$" diff --git a/AS5600.cpp b/AS5600.cpp index ad9f86d..23ddbb0 100644 --- a/AS5600.cpp +++ b/AS5600.cpp @@ -1,7 +1,7 @@ // // FILE: AS56000.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.6.0 +// VERSION: 0.6.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -463,6 +463,7 @@ float AS5600::getAngularSpeed(uint8_t mode) int32_t AS5600::getCumulativePosition() { int16_t value = readReg2(AS5600_ANGLE) & 0x0FFF; + if (_error != AS5600_OK) return _position; // whole rotation CW? // less than half a circle diff --git a/AS5600.h b/AS5600.h index f0323ee..d0941a1 100644 --- a/AS5600.h +++ b/AS5600.h @@ -2,7 +2,7 @@ // // FILE: AS5600.h // AUTHOR: Rob Tillaart -// VERSION: 0.6.0 +// VERSION: 0.6.1 // PURPOSE: Arduino library for AS5600 magnetic rotation meter // DATE: 2022-05-28 // URL: https://github.com/RobTillaart/AS5600 @@ -12,7 +12,7 @@ #include "Wire.h" -#define AS5600_LIB_VERSION (F("0.6.0")) +#define AS5600_LIB_VERSION (F("0.6.1")) // default addresses diff --git a/CHANGELOG.md b/CHANGELOG.md index c92a7a5..352901d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.6.1] - 2024-03-31 +- improve **getCumulativePosition()**, catch I2C error, see #62 +- update readme.md (incl reorder future work). +- update GitHub actions +- minor edits + + ## [0.6.0] - 2024-01-25 - add experimental error handling - add **int lastError()** so user can check the status of last I2C actions. diff --git a/README.md b/README.md index 3c0f744..42bcbe2 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ Arduino library for AS5600 and AS5600L magnetic rotation meter. **AS5600** is a library for an AS5600 / AS5600L based magnetic **rotation** meter. More exact, it measures the angle (rotation w.r.t. reference) and not RPM. -Multiple angle measurements allows one to calculate / estimate the RPM. +Multiple angle measurements allows one to calculate or estimate the RPM. -The AS5600 and AS5600L sensors are pin compatible (always check datasheet). +The AS5600 and AS5600L sensors are pin compatible (always check your model's datasheet). **Warning: experimental** @@ -39,10 +39,10 @@ Please share your experiences. #### 0.5.0 Breaking change Version 0.5.0 introduced a breaking change. -You cannot set the pins in **begin()** any more. +You cannot set the SDA and SCL 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()**. +The user has to call **Wire.begin()** and can optionally set the I2C pins +before calling **AS5600.begin()**. #### Related libraries @@ -64,6 +64,7 @@ Do not forget to add the pull up resistors to improve the I2C signals. The AS5600 datasheet states it supports Fast-Mode == 400 KHz and Fast-Mode-Plus == 1000 KHz. + #### Pull ups I2C performance tests with an AS5600L with an UNO failed at 400 KHz. @@ -128,7 +129,7 @@ This resistor needs to be removed to use the **OUT** pin. Not tested. ==> Read the datasheet! -PGO stands for Programming Option, it is used to calibrate / program the sensor. +PGO stands for ProGramming Option, it is used to calibrate and program the sensor. As the sensor can be programmed only a few times one should use this functionality with extreme care. See datasheet for a detailed list of steps to be done. @@ -731,38 +732,37 @@ priority is relative. #### Should +- implement extended error handling in public functions. + - will increase footprint !! how much? + - **call writeReg() only if readReg() is OK** ==> prevent incorrect writes + - ```if (_error != 0) return false;``` + - idem readReg2() + - set AS5600_ERROR_PARAMETER e.g. setZPosition() + - a derived class with extended error handling? - investigate **readMagnitude()** - combination of AGC and MD, ML and MH flags? -- investigate OUT behaviour in practice +- investigate **OUT** behaviour in practice - analogue - PWM - need AS5600 on breakout with support -- write examples: - - as5600_calibration.ino (needs HW and lots of time) - - different configuration options - check / verify Power-up time - 1 minute (need HW) - check Timing Characteristics (datasheet) - is there improvement possible. - #### Could -- investigate PGO programming pin. +- investigate **PGO** programming pin. - check for compatible devices - AS5200 ? - investigate performance - basic performance per function - I2C improvements - software direction -- implement extended error handling in public functions. - - will increase footprint !! how much? - - writeReg() only if readReg() is OK ==> prevent incorrect writes - - ```if (_error != 0) return false;``` - - set AS5600_ERROR_PARAMETER e.g. setZPosition() - - a derived class with extended error handling? - +- write examples: + - as5600_calibration.ino (needs HW and lots of time) + - different configuration options #### Wont (unless) diff --git a/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino b/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino index f58f3bb..551e18d 100644 --- a/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino +++ b/examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino @@ -88,7 +88,7 @@ void burn_mang() const uint16_t FASTFILTER = 0; const uint16_t WATCHDOG = 0; const uint16_t MAXANGLE = 0; - + bool OK = true; OK = OK && as5600.setPowerMode(POWERMODE); OK = OK && (POWERMODE == as5600.getPowerMode()); diff --git a/examples/AS5600_demo/AS5600_demo.ino b/examples/AS5600_demo/AS5600_demo.ino index c080348..0bcd9ae 100644 --- a/examples/AS5600_demo/AS5600_demo.ino +++ b/examples/AS5600_demo/AS5600_demo.ino @@ -21,7 +21,7 @@ void setup() Serial.println(__FILE__); Serial.print("AS5600_LIB_VERSION: "); Serial.println(AS5600_LIB_VERSION); - + Wire.begin(); as5600.begin(4); // set direction pin. diff --git a/examples/AS5600_demo_ESP32/AS5600_demo_ESP32.ino b/examples/AS5600_demo_ESP32/AS5600_demo_ESP32.ino index 25b65ad..7e54711 100644 --- a/examples/AS5600_demo_ESP32/AS5600_demo_ESP32.ino +++ b/examples/AS5600_demo_ESP32/AS5600_demo_ESP32.ino @@ -23,7 +23,7 @@ void setup() Serial.println(AS5600_LIB_VERSION); Wire.begin(14, 15); - + as5600.begin(4); // set direction pin. as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit. int b = as5600.isConnected(); diff --git a/examples/AS5600_demo_software_direction/AS5600_demo_software_direction.ino b/examples/AS5600_demo_software_direction/AS5600_demo_software_direction.ino index e6d2341..c0285ab 100644 --- a/examples/AS5600_demo_software_direction/AS5600_demo_software_direction.ino +++ b/examples/AS5600_demo_software_direction/AS5600_demo_software_direction.ino @@ -27,7 +27,7 @@ void setup() Wire.begin(); - as5600.begin(); // set software direction control. default param = 255 + as5600.begin(); // set software direction control. default parameter == 255 as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit. } @@ -39,7 +39,7 @@ void loop() if (counter < 10) as5600.setDirection(AS5600_CLOCK_WISE); else as5600.setDirection(AS5600_COUNTERCLOCK_WISE); if (counter >= 20) counter = 0; - + Serial.print(millis()); Serial.print("\t"); Serial.print(as5600.getDirection()); diff --git a/examples/AS5600_demo_two_I2C/AS5600_demo_two_I2C.ino b/examples/AS5600_demo_two_I2C/AS5600_demo_two_I2C.ino index 2600aea..a3a165c 100644 --- a/examples/AS5600_demo_two_I2C/AS5600_demo_two_I2C.ino +++ b/examples/AS5600_demo_two_I2C/AS5600_demo_two_I2C.ino @@ -36,7 +36,7 @@ void setup() Serial.print("Connect device 0: "); Serial.println(as5600_0.isConnected() ? "true" : "false"); delay(1000); - + as5600_1.begin(5); // set direction pin. as5600_1.setDirection(AS5600_COUNTERCLOCK_WISE); Serial.print("Connect device 1: "); diff --git a/examples/AS5600_resetCumulativeCounter/AS5600_resetCumulativeCounter.ino b/examples/AS5600_resetCumulativeCounter/AS5600_resetCumulativeCounter.ino index 7d21906..01232aa 100644 --- a/examples/AS5600_resetCumulativeCounter/AS5600_resetCumulativeCounter.ino +++ b/examples/AS5600_resetCumulativeCounter/AS5600_resetCumulativeCounter.ino @@ -1,6 +1,6 @@ // // FILE: AS5600_resetCumulativeCounter.ino -// AUTHOR: Daniel-Frenkel, (slightly by Rob Tillaart) +// AUTHOR: Daniel-Frenkel, (slightly modified by Rob Tillaart) // PURPOSE: demo - see issue #30 // URL: https://github.com/RobTillaart/AS5600 // @@ -21,7 +21,7 @@ void setup() Serial.println(__FILE__); Serial.print("AS5600_LIB_VERSION: "); Serial.println(AS5600_LIB_VERSION); - + Wire.begin(14, 15); // ESP32 as5600.begin(); diff --git a/library.json b/library.json index d8398ef..39fe7d1 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/AS5600.git" }, - "version": "0.6.0", + "version": "0.6.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index 9e8d083..12df09e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=AS5600 -version=0.6.0 +version=0.6.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for AS5600 and AS5600L magnetic rotation meter.