diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e8d9d5..baaa7cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.1.4] - 2023-09-22 +- add Wire1 support for ESP32 +- moved code from .h to .cpp +- update readme.md +- minor edits + + ## [0.1.3] - 2022-11-23 - add changelog.md - add RP2040 to build-CI - fix version number .cpp - minor edits - ## [0.1.2] - 2021-12-27 - update library.json - update readme.md diff --git a/README.md b/README.md index 80616b8..95d6f18 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,11 @@ [![Arduino CI](https://github.com/RobTillaart/rotaryDecoder/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) [![Arduino-lint](https://github.com/RobTillaart/rotaryDecoder/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/rotaryDecoder/actions/workflows/arduino-lint.yml) [![JSON check](https://github.com/RobTillaart/rotaryDecoder/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/rotaryDecoder/actions/workflows/jsoncheck.yml) +[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/rotaryDecoder.svg)](https://github.com/RobTillaart/rotaryDecoder/issues) + [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/rotaryDecoder/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/rotaryDecoder.svg?maxAge=3600)](https://github.com/RobTillaart/rotaryDecoder/releases) +[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/rotaryDecoder.svg)](https://registry.platformio.org/libraries/robtillaart/rotaryDecoder) # rotaryDecoder @@ -24,6 +27,12 @@ pins to GND so you will not get unintended interrupts. ## Interface +```cpp +#include "rotaryEncoder.h" +``` + +#### Constructor + - **rotaryDecoder(const int8_t address, TwoWire \*wire = Wire);** - **bool begin(uint8_t sda, uint8_t scl, uint8_t count = 4)** ESP32 ea initializes the class by setting the I2C sda and scl pins. @@ -35,23 +44,27 @@ Returns true if the PCF8574 is on the I2C bus. - **bool isConnected()** returns true if the PCF8574 is on the I2C bus. -## Core functions +#### Core functions - **void readInitialState()** read the initial state of the 4 rotary encoders. Typically called in setup only, or after a sleep e.g. in combination with **setValue()** -- **bool checkChange()** polling to see if one or more RE have changed, without updating the counters. -- **void update()** update the internal counters of the RE. These will add +1 or -1 depending on direction. -- **void updateSingle()** update the internal counters of the RE. This will add +1 +2 or +3 - as it assumes that the rotary encoder only goes into a single direction. +- **bool checkChange()** polling to see if one or more RE have changed, +without updating the counters. +- **void update()** update the internal counters of the RE. +These will add +1 or -1 depending on direction. +- **void updateSingle()** update the internal counters of the RE. +This will add +1 +2 or +3 as it assumes that the rotary encoder +only goes into a single direction. -## Counters +#### Counters - **uint32_t getValue(uint8_r re)** returns the RE counter. -- **void setValue(uint8_r re, uint32_t value = 0)** (re)set the internal counter to value, default 0 +- **void setValue(uint8_r re, uint32_t value = 0)** (re)set the internal counter to value, +default 0 -## Debugging +#### Debugging - **int8_t getLastPosition(uint8_r re)** returns last position. @@ -63,20 +76,21 @@ clock speed of the I2C bus. All four core functions have one call to **\_read8() is the most expensive part. Early tests gave the following indicative times (Arduino UNO) for the **update()** -function (with no updates it is ~8 us faster). Note that above 500KHz the gain becomes less -while reliability of signal decreases. (500KHz is about ~3x faster than 100 KHz) +function (with no updates it is ~8 us faster). +Note that above 500 KHz the gain becomes less while reliability of signal decreases. +(500 KHz is about ~3x faster than 100 KHz in practice.) As 400 KHz is a standard I2C clock speed it is the preferred one. -| I2C speed | time (us) | delta | %% | -|:---------:|:---------:|:-----:|:-----:| -| 100 KHz | 247 | | | -| 200 KHz | 146 | 99 | 40% | -| 300 KHz | 110 | 36 | 24% | -| 400 KHz | 95 | 15 | 14% | preferred max -| 500 KHz | 84 | 11 | 12% | -| 600 KHz | 79 | 5 | 6% | -| 700 KHz | 73 | 6 | 8% | +| I2C speed | time (us) | delta | %% | Notes | +|:-----------:|:-----------:|:-------:|:-----:|:--------| +| 100 KHz | 247 | | | +| 200 KHz | 146 | 99 | 40% | +| 300 KHz | 110 | 36 | 24% | +| 400 KHz | 95 | 15 | 14% | preferred max +| 500 KHz | 84 | 11 | 12% | +| 600 KHz | 79 | 5 | 6% | +| 700 KHz | 73 | 6 | 8% | At @400KHz it can update 4 rotary encoders in ~100us. @@ -95,14 +109,33 @@ See examples.. ## Future -#### must +#### Must + - update documentation -- picture how to connect e.g 2 RE's which pins to used +- picture how to connect e.g two rotary encoders which pins to used + + +#### Should -#### should - test with a high speed drill like a Dremel-tool. -#### could + +#### Could + - invert flag to adjust to RE that give their pulse just the other way around? - setInvert(bool); getInvert(); - - per channel / all? \ No newline at end of file + - per channel / all? + + +#### Wont + + + +## Support + +If you appreciate my libraries, you can support the development and maintenance. +Improve the quality of the libraries by providing issues and Pull Requests, or +donate through PayPal or GitHub sponsors. + +Thank you, + diff --git a/library.json b/library.json index 1965089..8ee044b 100644 --- a/library.json +++ b/library.json @@ -15,9 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/rotaryDecoder.git" }, - "version": "0.1.3", + "version": "0.1.4", "license": "MIT", - "frameworks": "arduino", + "frameworks": "*", "platforms": "*", "headers": "rotaryDecoder.h" } diff --git a/library.properties b/library.properties index 748240a..d90cb24 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=rotaryDecoder -version=0.1.3 +version=0.1.4 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library to rotary decoder with a PCF8574 diff --git a/rotaryDecoder.cpp b/rotaryDecoder.cpp index 65a2c5c..01b707a 100644 --- a/rotaryDecoder.cpp +++ b/rotaryDecoder.cpp @@ -1,7 +1,7 @@ // // FILE: rotaryDecoder.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 +// VERSION: 0.1.4 // DATE: 2021-05-08 // PURPOSE: rotary decoder library for Arduino // URL: https://github.com/RobTillaart/rotaryDecoder @@ -26,7 +26,6 @@ bool rotaryDecoder::begin(uint8_t sda, uint8_t scl, uint8_t count) { _count = count; if (_count > 4) _count = 4; - _wire = &Wire; _wire->begin(sda, scl); if (! isConnected()) return false; return true; @@ -144,6 +143,23 @@ bool rotaryDecoder::updateSingle() } +int32_t rotaryDecoder::getValue(uint8_t re) +{ + return _encoder[re]; +} + + +void rotaryDecoder::setValue(uint8_t re, int32_t value) +{ + _encoder[re] = value; +} + + +uint8_t rotaryDecoder::getLastPosition(uint8_t re) +{ + return _lastPos[re]; +}; + ///////////////////////////////////////////////////// // // PRIVATE diff --git a/rotaryDecoder.h b/rotaryDecoder.h index 476e145..d46a4dc 100644 --- a/rotaryDecoder.h +++ b/rotaryDecoder.h @@ -2,7 +2,7 @@ // // FILE: rotaryDecoder.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.3 +// VERSION: 0.1.4 // DATE: 2021-05-08 // PURPOSE: rotary decoder library for Arduino // URL: https://github.com/RobTillaart/rotaryDecoder @@ -11,7 +11,7 @@ #include "Arduino.h" #include "Wire.h" -#define ROTARY_DECODER_LIB_VERSION (F("0.1.3")) +#define ROTARY_DECODER_LIB_VERSION (F("0.1.4")) class rotaryDecoder @@ -38,18 +38,18 @@ class rotaryDecoder bool updateSingle(); // assumes single direction => + ++ +++ // re = rotary encoder - int32_t getValue(uint8_t re) { return _encoder[re]; }; - void setValue(uint8_t re, int32_t value = 0) { _encoder[re] = value; }; + int32_t getValue(uint8_t re); + void setValue(uint8_t re, int32_t value = 0); // DEBUG - uint8_t getLastPosition(uint8_t re) { return _lastPos[re]; }; + uint8_t getLastPosition(uint8_t re); private: uint8_t _count = 0; uint8_t _lastValue = 0; - uint8_t _lastPos[4] = { 0,0,0,0 }; - int32_t _encoder[4] = { 0,0,0,0 }; + uint8_t _lastPos[4] = { 0, 0, 0, 0 }; + int32_t _encoder[4] = { 0, 0, 0, 0 }; uint8_t _read8(); uint8_t _address;