Giter Site home page Giter Site logo

jonas-merkle / as5047p Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 10.0 1.09 MB

An Arduino library for the AS5047P high-resolution rotary position sensor. Supporting also the following sensor types: AS5047D, AS5147, AS5147P, AS5247

Home Page: https://github.com/jonas-merkle/AS5047P

License: GNU General Public License v3.0

C++ 100.00%
arduino-library as5047p spi sensor rotary-encoder high-resolution rotary-position-sensor as5x47 as5047d as5147

as5047p's Introduction

AS5047P - Arduino Library

GitHub Workflow Status (with branch) GitHub Workflow Status (with branch) GitHub release (latest by date) GitHub GitHub issues GitHub pull requests Maintenance

tl;dr

An Arduino library for the AS5047P high-resolution rotary position sensor. Supporting also the following sensor types: AS5047D, AS5147, AS5147P, AS5247

Contents

Supported Sensors

The following sensors of the AS5x47 series of rotary potion sensors are supported by this library:

You can get the AS5047P sensor preinstalled on a breakout board here.

Not supported are the following sensors:

Documentation

Documentation Deployment Status: GitHub deployments

Branch Link
Master Documentation
Develop Documentation

How to install this library

Install the library via the Arduino Library Manager

The easiest way to install this library is to use the build in Arduino Library Manager. Just search for AS5047P an install the latest version available. You can also upgrade the library to the newest release via the Arduino Library Manager. For detailed information please read the section Using the Library Manager of this tutorial. (Pleas keep in mind you need at least version 1.6.2 of the Arduino IDE in order to use the Arduino Library Manager)

Manually install a Arduino library

You can download the latest version of this library here as a zip file and follow the section Importing a .zip Library or Manual installation of this tutorial about How to Install a Library.

Install the library via the PlattformIO Library Manager

You can find this library here in the PlattformIO Library Manager. To add this library to your plattformIO project you can either use the library manager ui and search for this library or you can use the following platform io cli command: pio lib install "jonas-merkle/AS5047P"

How to connect the AS5047P to your Arduino

Connect to an Arduino Uno

AS5047P Pin Arduino Uno Pin Comment
GND GND -
VDD 5V -
VDD3V NC -
MOSI MOSI (Pin: 11) -
MISO MISO (Pin: 12) -
CLK SCK (Pin: 13) -
CSn 9 Can be any unused digital pin on the arduino as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Connect to an Arduino Mega

AS5047P Pin Arduino Mega Pin Comment
GND GND -
VDD 5V -
VDD3V NC -
MOSI MOSI (Pin: 51) -
MISO MISO (Pin: 50) -
CLK SCK (Pin: 52) -
CSn 9 Can be any unused digital pin on the arduino as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Connect to an Adafruit Feather M0

AS5047P Pin Adafruit Feather M0 Pin Comment
GND GND -
VDD 3V -
VDD3V 3V -
MOSI MOSI -
MISO MISO -
CLK SCK -
CSn 9 Can be any unused digital pin on the arduino as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Adafruit Feather M0 board!

Connect to Teensy Board

Connect to a Teensy 3.5

AS5047P Pin Teensy Pin Comment
GND GND -
VDD 3V -
VDD3V 3V -
MOSI MOSI0 (Pin: 11) -
MISO MISO0 (Pin: 12) -
CLK SCK0 (Pin: 13) -
CSn CS0 (Pin: 10) Can be any unused digital pin on the teensy as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Teensy board!

Connect to a Teensy 3.6

AS5047P Pin Teensy Pin Comment
GND GND -
VDD 3V -
VDD3V 3V -
MOSI MOSI0 (Pin: 11) -
MISO MISO0 (Pin: 12) -
CLK SCK0 (Pin: 13) -
CSn CS0 (Pin: 10) Can be any unused digital pin on the teensy as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Teensy board!

Connect to a Teensy 4.0

AS5047P Pin Teensy Pin Comment
GND GND -
VDD 3V -
VDD3V 3V -
MOSI MOSI (Pin: 11) -
MISO MISO (Pin: 12) -
CLK SCK (Pin: 13) -
CSn CS (Pin: 10) Can be any unused digital pin on the teensy as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Teensy board!

Connect to a Teensy 4.1

AS5047P Pin Teensy Pin Comment
GND GND -
VDD 3V -
VDD3V 3V -
MOSI MOSI (Pin: 11) -
MISO MISO (Pin: 12) -
CLK SCK (Pin: 13) -
CSn CS (Pin: 10) Can be any unused digital pin on the teensy as long as it's configured here AS5047P as5047p(<ChipSelectPort>);

Please note that the sensor can no longer be operated with 5V, but must be operated with 3.3V, otherwise there is a risk of damaging the Teensy board!

Project Status & ToDo's

Status Task / ToDo
Read functions for all registers implemented.
Doxygen comments added.
BasicReadAngle.ino successfully tested on an Arduino Mega & Adafruit Feather M0
BasicReadAngleAndDebugInfo.ino successfully tested on an Arduino Mega & Adafruit Feather M0
PrintAllSettings.ino successfully tested on an Arduino Mega & Adafruit Feather M0
Adding a CI pipline.
Build & deploy doxygen documentation for the library.
Sensor status output as string.
keywords.txt updated for main library functions.
Switch to unions...
Write functions for all registers implemented.
Parity check on incoming data.
Improve initSPI()
ToString() for Error_t
Adding Library to Arduino Library Manager 🥳
Adding Library to PlattformIO Library Manager 🥳
Documentation update.
keywords.txt updated for all library functions.
🚧 Readme.md update.
🚧 Test of all wirte functions
🚧 Test of all read functions
Porting the library to be compatible with the STM32 HAL
Additional examples.
Unit Tests?!
Implementation & test of programming the one time programmable register of the AS5047P.

as5047p's People

Contributors

jonas-merkle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

as5047p's Issues

[FEATURE REQUEST]:teensy 3.2 compatibility

hi
first of all thank you for your useful library

I'm going to buy a teensy 3.2 board for a project and I'm wondering if your library works with that version.
could you please help me with that?

[BUG]: parity check on incoming data fails

[BUG]: parity check on incoming data fails

The wrong data gets tested for parity in bool AS5047P::checkForComErrorF(AS5047P_Types::ERROR_t *errorOut) and bool AS5047P::checkForSensorErrorF(AS5047P_Types::ERROR_t *errorOut) in AS5047P.cpp

// verify parity bit
if (!AS5047P_Util::parityCheck(errorReg.data.raw)) {
    errorOut->controllerSideErrors.flags.CONT_SPI_PARITY_ERROR = true;
}

[FEATURE REQUEST]: Presenting angles over 360

Hello Jonas,

Thank you for this simple to use library. I'm currently using it in a project but it seems it only shows angles within 360 degrees. Ideally I'd like to be able to continue receiving the angles higher than 360, for example if the motor continues to move it continues counting and while it moves the other direction it counts down. is there a way to achieve this? also is there a way to set the current position as zero position for homing?

[BUG]:Arduino Uno can not recognize the As5047p

Describe the bug
The library and code work perfectly with Arduino Mega, but can not recognize the As5047p when linked with Arduino Uno. The only feedback from the monitor is the error message. I tried three different Arduino Uno. None worked.

To Reproduce
Steps to reproduce the behavior:

  1. As the library said, I connected pins as follow: 5v-5v; GND-GND; MOSI-11; MISO-12; CLK-13; CSN-9
  2. Used the code "BasicReadAngle" from Github.
  3. The Serial monitor only outputs the error message saying: "Can't connect to the AS5047P sensor! Please check the connection..."

Expected behavior
The serial monitor reads and outputs the angle data from the As5047p sensor.

Arduino (please complete the following information):

  • Arduino Uno
  • Arduino 1.8.17
  • The Version of this Library 2.1.5

Hardware Setup (please complete the following information):

  • As the library said, I connected pins as follow: 5v-5v; GND-GND; MOSI-11; MISO-12; CLK-13; CSN-9

Additional context
I have no idea where I did wrong for the Arduino not recognizing the sensor. I borrowed an Arduino Mega and it worked. However, when I use Arduino Uno it does not.

[BUG]: Error Compiling for board Teensy 4.1

Describe the bug
Not able to compile the "BasicReadAngle" example.

Error Message
Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Teensy 4.1, Serial, 600 MHz, Faster, US English"

In file included from D:\0-Files\Documents\Arduino\libraries\AS5047P\src\types\AS5047P_Types.cpp:12:0:

D:\0-Files\Documents\Arduino\libraries\AS5047P\src\types\AS5047P_Types.h:140:18: error: 'string' in namespace 'std' does not name a type

         std::string toStdString();

              ^

D:\0-Files\Documents\Arduino\libraries\AS5047P\src\types\AS5047P_Types.cpp:35:38: error: no 'std::__cxx11::string AS5047P_Types::ERROR_t::toStdString()' member function declared in class 'AS5047P_Types::ERROR_t'

 std::string ERROR_t::toStdString() {

                                  ^

Error compiling for board Teensy 4.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

[FEATURE REQUEST]: OTP programming - ABIRES and Zero Position

Is your feature request related to a problem? Please describe.
I used Adrien's library, but I looked into yours also, both libraries are missing the programming of the OTP memory.

Describe the solution you'd like
I got a request at a project job to write code for sensor AS5047P, the code, for now, runs on Arduino Uno.
They wish to configure the sensor and make it permanent, I ask for your help to make it work.
They need to write ABIRES and Zero Position to the sensor and program the OTP, so the sensor remembers the settings.
They want to read absolute position over ABI interface, for that they use their gear.

Describe alternatives you've considered
I used Adrien's library to configure sensor settings which worked fine, but I was unable to program OTP register.
I also tried to pass raw commands to the sensor, it looked like it worked, but it seems like the sensor didn't remember its settings after the power cycle.

Additional context
I followed this datasheet for programming OTP https://ams.com/documents/20143/36005/AS5047P_DS000324_3-00.pdf
It looks like I got something wrong, but I can't figure out what the bug is.

It would be awesome if you would be able to test this code and maybe find out the bug by next week's Thursday 2.2.23.
If possible you can tweak my code to make it work.

It would be great if your library could support OTP programming natively but it seems like the commands for the PROG register refused to pass into the sensor.

Here is the code I wrote, it has a serial interface for some configuration.

ConfigureSensor_AS5074_MK_V1.10.zip

Thanks a lot, in advance.
Matej

[BUG]: Micros bugs out below ~370 microseconds

Describe the bug
If state machine method is used with "Micros" to control steps for stepper motor, bug happens when step on and off intervals is set to lower than ~370 microseconds. Changing interval to 350 microseconds, motor suddenly starts spinning ~50-70% faster. If setting interval to 50 microseconds, motor speed is the same as it were set to 350.

To Reproduce
Arduino UNO R3, A4988 stepper driver, Bipolar stepper motor, AS5047P-TS_EK_AB encoder.
Windows 10 x64, Arduino IDE 1.8.12

Expected behavior
Motor should spin full speed. Full speed should be reached at 43 microseconds step interval.

  • Arduino Board Type [Uno]
  • Arduino Software Version [1.8.12]
  • The Version of this Library [2.1.2]

Additional context
In schematics there is LCD Keypad Shield, but it isn't reason of the problem since I tried code without it and had same issue.
Tried to use int instead of float to store angle position, it maybe lowered the threshold from ~370 to ~360 microseconds.
Kembrik Pooper 3000v2

#include <AS5047P.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
LCDKeypad lcd;

//initial backlight
unsigned char bckl = 255;

// define the chip select port.
#define AS5047P_CHIP_SELECT_PORT 3

// define the spi bus speed
#define AS5047P_CUSTOM_SPI_BUS_SPEED 100000

int LCDrefreshRate = 40;
unsigned long LCDmillis = 0;
unsigned long CutterStepInterval = 43;
unsigned long CutterStepMicros = 0;
unsigned long DirectionChangeMillis = 0;
int DirectionChangeInterval = 3000;

const int EnableCutterPin = 15;
const int CutterDirPin = 16;
const int CutterStepPin = 17;
int EnableCutterState = LOW; // Cutter Enabled
int CutterDirState = HIGH; // Cutter spin clockwise
int CutterStepState = LOW; // Cutter step off
int DirectionChange = 0;

// initialize a new AS5047P sensor object.
AS5047P as5047p(AS5047P_CHIP_SELECT_PORT, AS5047P_CUSTOM_SPI_BUS_SPEED);

float angle;

void setup() {
  pinMode(EnableCutterPin, OUTPUT); //Enable Cutter
  pinMode(CutterDirPin, OUTPUT); //Cutter Dir
  pinMode(CutterStepPin, OUTPUT); //Cutter Step
  pinMode(10, OUTPUT); //LCD backlight control pin
  analogWrite(10, bckl);
  lcd.begin(16, 2);
  lcd.clear();

  // initialize the AS5047P sensor and hold if sensor can't be initialized..
  while (!as5047p.initSPI()) {
    lcd.print(F("No AS5047P"));
    delay(5000);
  }
}

void loop() {
  unsigned long currentMillis = millis();
  unsigned long currentMicros = micros();
  angle = as5047p.readAngleDegree();

  // refresh LCD and display cutter encoder angle
  if (currentMillis - LCDmillis >= LCDrefreshRate) {
    LCDmillis = currentMillis;
    lcd.clear();
    lcd.print(angle);      // read the angle value from the AS5047P sensor an print it.
  }

  // Direction change
  if (angle >= 350.00 && DirectionChange == 0) {
    DirectionChange = 3;
    DirectionChangeMillis = currentMillis;
    digitalWrite(EnableCutterPin, HIGH);
  }
  if (currentMillis - DirectionChangeMillis >= DirectionChangeInterval && DirectionChange == 3) {
    DirectionChange = 1;
    digitalWrite(EnableCutterPin, LOW);
  }
  if (angle <= 10.00 && DirectionChange == 1) {
    DirectionChange = 4;
    DirectionChangeMillis = currentMillis;
    digitalWrite(EnableCutterPin, HIGH);
  }
  if (currentMillis - DirectionChangeMillis >= DirectionChangeInterval && DirectionChange == 4) {
    DirectionChange = 0;
    digitalWrite(EnableCutterPin, LOW);
  }

  // stepper control clockwise
  if (currentMicros - CutterStepMicros >= CutterStepInterval && angle <= 350.00 && DirectionChange == 0) {
    // save the last time you made step
    CutterStepMicros = currentMicros;
    CutterDirState = HIGH;
    digitalWrite(CutterDirPin, CutterDirState); // Cutter spin clockwise
    // if step is off turn it on and vice-versa:
    if (CutterStepState == LOW) {
      CutterStepState = HIGH;
    } else {
      CutterStepState = LOW;
    }
    digitalWrite(CutterStepPin, CutterStepState);
  }

  // stepper control counter-clockwise
  if (currentMicros - CutterStepMicros >= CutterStepInterval && angle >= 10.00 && DirectionChange == 1) {
    // save the last time you made step
    CutterStepMicros = currentMicros;
    CutterDirState = LOW;
    digitalWrite(CutterDirPin, CutterDirState); // Cutter spin counter-clockwise
    // if step is off turn it on and vice-versa:
    if (CutterStepState == LOW) {
      CutterStepState = HIGH;
    } else {
      CutterStepState = LOW;
    }
    digitalWrite(CutterStepPin, CutterStepState);
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.