Skip to content

Latest commit

 

History

History
263 lines (201 loc) · 12.2 KB

README.md

File metadata and controls

263 lines (201 loc) · 12.2 KB

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

Overview

The AS5047P Arduino Library provides an easy way to interface with the AS5047P high-resolution rotary position sensor, as well as several other sensors from the AS5x47 series. This library supports reading the angular position and other diagnostic information using SPI communication, and is designed to work with a variety of microcontrollers, including Arduino, Adafruit Feather, and Teensy boards.

The AS5047P sensor provides high-resolution rotary position sensing with a 14-bit resolution, making it ideal for applications that require accurate angular measurements, such as robotics, motor control, and industrial automation.

Features

  • Support for multiple sensor models: AS5047P, AS5047D, AS5147, AS5147P, and AS5247.
  • Easy-to-use interface for reading angular position.
  • SPI communication for reliable data transmission.
  • Example sketches to help get started quickly.
  • Compatibility with Arduino, Adafruit Feather, Teensy, and other boards.

Contents

Supported Sensors

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

Not supported are the following sensors:

Documentation

The library documentation is deployed on GitHub Pages. For detailed reference on the API, examples, and usage guides, check the links below:

Branch Link
Master Documentation
Develop Documentation

Installation Instructions

Install via Arduino Library Manager

The easiest way to install this library is to use the built-in Arduino Library Manager:

  1. Open the Arduino IDE.
  2. Go to Sketch > Include Library > Manage Libraries...
  3. In the Library Manager, type AS5047P in the search bar.
  4. Install the latest version of the library.

You can also upgrade the library to the newest release via the Arduino Library Manager. For more information, refer to the Arduino Libraries Guide. Note that you need at least version 1.6.2 of the Arduino IDE to use the Library Manager.

Manual Installation

  1. Download the latest version of the library from GitHub Releases.
  2. Extract the downloaded ZIP file.
  3. Copy the extracted folder to your Arduino libraries directory (e.g., Documents/Arduino/libraries).

Follow the Arduino Libraries Guide for more detailed instructions.

Install via PlatformIO Library Manager

To add this library to your PlatformIO project, follow these steps:

  1. Open PlatformIO IDE.
  2. Search for AS5047P in the Library Manager UI, or run the following command in the PlatformIO CLI:
    pio lib install "jonas-merkle/AS5047P"
    

Connecting the AS5047P to Your Arduino

Arduino Uno

AS5047P Pin Arduino Uno Pin Comment
GND GND Ground connection
VDD 5V Power supply (5V)
VDD3V NC Not connected
MOSI MOSI (Pin: 11) SPI Data Out
MISO MISO (Pin: 12) SPI Data In
CLK SCK (Pin: 13) SPI Clock
CSn 9 Chip select (configurable pin)

Arduino Mega

AS5047P Pin Arduino Mega Pin Comment
GND GND Ground connection
VDD 5V Power supply (5V)
VDD3V NC Not connected
MOSI MOSI (Pin: 51) SPI Data Out
MISO MISO (Pin: 50) SPI Data In
CLK SCK (Pin: 52) SPI Clock
CSn 9 Chip select (configurable pin)

Adafruit Feather M0

AS5047P Pin Adafruit Feather M0 Pin Comment
GND GND Ground connection
VDD 3V Power supply (3.3V)
VDD3V 3V Power supply (3.3V)
MOSI MOSI SPI Data Out
MISO MISO SPI Data In
CLK SCK SPI Clock
CSn 9 Chip select (configurable pin)

Warning: Ensure the sensor is powered with 3.3V to avoid damage to the Adafruit Feather M0 board.

Teensy Board Connections

Teensy 3.5

AS5047P Pin Teensy Pin Comment
GND GND Ground connection
VDD 3V Power supply (3.3V)
VDD3V 3V Power supply (3.3V)
MOSI MOSI0 (Pin: 11) SPI Data Out
MISO MISO0 (Pin: 12) SPI Data In
CLK SCK0 (Pin: 13) SPI Clock
CSn CS0 (Pin: 10) Chip select (configurable pin)

Warning: Ensure the sensor is powered with 3.3V to avoid damage to the Teensy board.

Teensy 3.6

AS5047P Pin Teensy Pin Comment
GND GND Ground connection
VDD 3V Power supply (3.3V)
VDD3V 3V Power supply (3.3V)
MOSI MOSI0 (Pin: 11) SPI Data Out
MISO MISO0 (Pin: 12) SPI Data In
CLK SCK0 (Pin: 13) SPI Clock
CSn CS0 (Pin: 10) Chip select (configurable pin)

Warning: Ensure the sensor is powered with 3.3V to avoid damage to the Teensy board.

Teensy 4.0

AS5047P Pin Teensy Pin Comment
GND GND Ground connection
VDD 3V Power supply (3.3V)
VDD3V 3V Power supply (3.3V)
MOSI MOSI (Pin: 11) SPI Data Out
MISO MISO (Pin: 12) SPI Data In
CLK SCK (Pin: 13) SPI Clock
CSn CS (Pin: 10) Chip select (configurable pin)

Warning: Ensure the sensor is powered with 3.3V to avoid damage to the Teensy board.

Teensy 4.1

AS5047P Pin Teensy Pin Comment
GND GND Ground connection
VDD 3V Power supply (3.3V)
VDD3V 3V Power supply (3.3V)
MOSI MOSI (Pin: 11) SPI Data Out
MISO MISO (Pin: 12) SPI Data In
CLK SCK (Pin: 13) SPI Clock
CSn CS (Pin: 10) Chip select (configurable pin)

Warning: Ensure the sensor is powered with 3.3V to avoid damage to the Teensy board.

Usage Guide

Basic Example

The following example demonstrates how to read the angle from the AS5047P sensor using an Arduino board.

#include <SPI.h>
#include <AS5047P.h>

AS5047P as5047p(9); // Chip select pin 9

void setup() {
  Serial.begin(9600);
  SPI.begin();
  as5047p.initSPI();
}

void loop() {
  uint16_t angle = as5047p.readAngle();
  Serial.print("Angle: ");
  Serial.println(angle);
  delay(500);
}

Advanced Usage

The library provides several functions for advanced interaction with the sensor, including reading diagnostic registers and status flags. Refer to the documentation for a complete API reference and usage examples.

License

This project is licensed under the GNU General Public License v3.0. You can find the full license text in the LICENSE file or visit the GPL v3.0 License page for more information.

Project Status & To-Do'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 pipeline.
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 PlatformIO Library Manager 🥳
Documentation update.
keywords.txt updated for all library functions.
🚧 Readme.md update.
🚧 Test of all write 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.