Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor API, begin() #47

Merged
merged 6 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 1 addition & 52 deletions AS5600.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: AS56000.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.1
// VERSION: 0.5.0
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand Down Expand Up @@ -55,56 +55,6 @@ AS5600::AS5600(TwoWire *wire)
}


#if defined (ESP8266) || defined(ESP32)

bool AS5600::begin(int dataPin, int clockPin, uint8_t directionPin)
{
_directionPin = directionPin;
if (_directionPin != AS5600_SW_DIRECTION_PIN)
{
pinMode(_directionPin, OUTPUT);
}
setDirection(AS5600_CLOCK_WISE);

if ((dataPin < 255) && (clockPin < 255))
{
_wire->begin(dataPin, clockPin);
} else {
_wire->begin();
}
if (! isConnected()) return false;
return true;
}

#endif


#if defined (ARDUINO_ARCH_STM32)

bool AS5600::begin(int dataPin, int clockPin, uint8_t directionPin)
{
_directionPin = directionPin;
if (_directionPin != AS5600_SW_DIRECTION_PIN)
{
pinMode(_directionPin, OUTPUT);
}
setDirection(AS5600_CLOCK_WISE);

if ((dataPin < 255) && (clockPin < 255))
{
_wire->setSDA(dataPin);
_wire->setSCL(clockPin);
_wire->begin();
} else {
_wire->begin();
}
if (! isConnected()) return false;
return true;
}

#endif


bool AS5600::begin(uint8_t directionPin)
{
_directionPin = directionPin;
Expand All @@ -114,7 +64,6 @@ bool AS5600::begin(uint8_t directionPin)
}
setDirection(AS5600_CLOCK_WISE);

_wire->begin();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for #53
This line when I have restored its work for teensy 4.1

if (! isConnected()) return false;
return true;
}
Expand Down
12 changes: 4 additions & 8 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AS5600.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.1
// VERSION: 0.5.0
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand All @@ -12,7 +12,7 @@
#include "Wire.h"


#define AS5600_LIB_VERSION (F("0.4.1"))
#define AS5600_LIB_VERSION (F("0.5.0"))

// default addresses
const uint8_t AS5600_DEFAULT_ADDRESS = 0x36;
Expand Down Expand Up @@ -89,15 +89,11 @@ class AS5600
public:
AS5600(TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_STM32)
// AS5600_SW_DIRECTION_PIN is software controlled direction pin
bool begin(int dataPin, int clockPin, uint8_t directionPin = AS5600_SW_DIRECTION_PIN);
#endif

bool begin(uint8_t directionPin = AS5600_SW_DIRECTION_PIN);
bool isConnected();

// address = 0x36 for AS5600, 0x40 for AS5600L
// address = fixed 0x36 for AS5600,
// = default 0x40 for AS5600L
uint8_t getAddress();


Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ 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-07
- refactor API, begin()
- update readme.md
- update examples
- add examples
- patch library.properties => category=Sensors

----

## [0.4.1] - 2023-09-16
- fix #45 support STM32 set I2C pins ARDUINO_ARCH_STM32
- update readme badges
- minor edits


## [0.4.0] - 2023-06-27
- fix #39 support for Wire2 on ESP32
- update readme.md
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ or fluctuating power supply.
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.
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()**.


#### Related libraries

- https://github.com/RobTillaart/Angle
Expand Down Expand Up @@ -159,11 +168,17 @@ When polling the AS5600 with an ESP32 to measure RPM an issue has been reported.
See https://github.com/RobTillaart/AS5600/issues/28

The problem is that the ESP32 can be blocking for up to one second if there is a
problem in the connection with the sensor. Using **setWireTimeout()** does not seem
to solve the problem (2023-01-31). In the issue the goal was to measure the turns
of a rotating device at around 3800 RPM. To do this one need roughly 1 angle measurement
per 5 milliseconds.
which
problem in the connection with the sensor.
Using **setWireTimeout()** does not seem to solve the problem (2023-01-31).
In the issue the goal was to measure the turns of a rotating device at around 3800 RPM.

3800 RPM == 64 rounds / second.

To measure speed one need at least 3 angle measurements per rotation.
This results in at least 192 measurements per second which is about 1 per 5 milliseconds.

Given that the ESP32 can block for a second, it can not be guaranteed to be up to date.
Not for speed, but also not for total number of rotations.


## Interface
Expand Down
5 changes: 2 additions & 3 deletions examples/AS5600L_set_address/AS5600L_set_address.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: AS5600L_set_address.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2022-08-30


#include "AS5600.h"
Expand All @@ -21,7 +20,7 @@ void setup()
Wire.begin();

ASL.begin(4); // set direction pin.
ASL.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
ASL.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
int b = ASL.isConnected();
Serial.print("Connect: ");
Serial.println(b);
Expand All @@ -48,4 +47,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
9 changes: 3 additions & 6 deletions examples/AS5600_I2C_frequency/AS5600_I2C_frequency.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// FILE: AS5600_I2C_frequency.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2022-05-28


#include "AS5600.h"
#include "Wire.h"

AS5600 as5600; // use default Wire
AS5600L as5600; // use default Wire

uint32_t clk = 0;

uint32_t start, stop;


void setup()
{
Serial.begin(115200);
Expand All @@ -23,13 +23,10 @@ void setup()

Wire.begin();

// UNO
as5600.begin(4); // set direction pin.
// ESP32
// as5600.begin(14, 15); // no direction pin.
// as5600.setAddress(0x40); // AS5600L only

as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
int b = as5600.isConnected();
Serial.print("Connect: ");
Serial.println(b);
Expand Down
11 changes: 5 additions & 6 deletions examples/AS5600_angular_speed/AS5600_angular_speed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// FILE: AS5600_angular_speed.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2022-06-02


#include "AS5600.h"
#include "Wire.h"

AS5600 as5600; // use default Wire
AS5600L as5600; // use default Wire


void setup()
Expand All @@ -21,7 +20,7 @@ void setup()
Wire.begin();

as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.

Serial.println(as5600.getAddress());

Expand All @@ -39,10 +38,10 @@ void loop()
{
// Serial.print("\ta = ");
// Serial.print(as5600.readAngle());
Serial.print("\tω = ");
// Serial.print("\tω = ");
Serial.println(as5600.getAngularSpeed());
delay(100);
delay(25);
}


// -- END OF FILE --
// -- END OF FILE --
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: AS5600_angular_speed_RPM.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2022-06-02


#include "AS5600.h"
Expand All @@ -19,13 +18,13 @@ void setup()
Serial.println(AS5600_LIB_VERSION);

Wire.begin();
// as5600.begin(14,15);

as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.

Serial.println(as5600.getAddress());

// as5600.setAddress(0x40); // AS5600L only
// as5600.setAddress(0x40); // AS5600L only

int b = as5600.isConnected();
Serial.print("Connect: ");
Expand All @@ -45,4 +44,4 @@ void loop()
}


// -- END OF FILE --
// -- END OF FILE --
10 changes: 4 additions & 6 deletions examples/AS5600_burn_conf_mang/AS5600_burn_conf_mang.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: AS5600_burn_conf_mang.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo (not tested yet - see issue #38)
// DATE: 2023-06-18


// WARNING
Expand Down Expand Up @@ -31,11 +30,10 @@ void setup()
Serial.print("AS5600_LIB_VERSION: ");
Serial.println(AS5600_LIB_VERSION);

// ESP32
// as5600.begin(14, 15);
// AVR
Wire.begin();

as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.

if (as5600.isConnected())
{
Expand Down Expand Up @@ -172,4 +170,4 @@ void burn_mang()
}


// -- END OF FILE --
// -- END OF FILE --
10 changes: 4 additions & 6 deletions examples/AS5600_burn_zpos/AS5600_burn_zpos.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// FILE: AS5600_burn_zpos.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo (not tested yet - see issue #38)
// DATE: 2023-06-18


// WARNING
Expand Down Expand Up @@ -31,11 +30,10 @@ void setup()
Serial.print("AS5600_LIB_VERSION: ");
Serial.println(AS5600_LIB_VERSION);

// ESP32
// as5600.begin(14, 15);
// AVR
Wire.begin();

as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.

if (as5600.isConnected())
{
Expand Down Expand Up @@ -111,4 +109,4 @@ void burn_zpos()



// -- END OF FILE --
// -- END OF FILE --
12 changes: 5 additions & 7 deletions examples/AS5600_demo/AS5600_demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// FILE: AS5600_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2022-05-28


#include "AS5600.h"
#include "Wire.h"

AS5600 as5600; // use default Wire
AS5600L as5600; // use default Wire


void setup()
Expand All @@ -17,12 +16,11 @@ void setup()
Serial.println(__FILE__);
Serial.print("AS5600_LIB_VERSION: ");
Serial.println(AS5600_LIB_VERSION);

Wire.begin();

// ESP32
// as5600.begin(14,15);
// AVR
as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
int b = as5600.isConnected();
Serial.print("Connect: ");
Serial.println(b);
Expand All @@ -43,4 +41,4 @@ void loop()
}


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