Skip to content

Commit

Permalink
refactor API, begin()
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Dec 7, 2023
1 parent 75cdb95 commit d549470
Show file tree
Hide file tree
Showing 30 changed files with 303 additions and 130 deletions.
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();
if (! isConnected()) return false;
return true;
}
Expand Down
9 changes: 2 additions & 7 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,11 +89,6 @@ 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();

Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ 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
- 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
9 changes: 9 additions & 0 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
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 --
28 changes: 28 additions & 0 deletions examples/AS5600_demo_ESP32/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
- esp32
# - esp8266
# - mega2560
# - rpipico

Loading

0 comments on commit d549470

Please sign in to comment.