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.
- 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.
- AS5047P - Arduino Library
The following sensors of the AS5x47 series of rotary position sensors are supported by this library:
Not supported are the following sensors:
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 |
The easiest way to install this library is to use the built-in Arduino Library Manager:
- Open the Arduino IDE.
- Go to Sketch > Include Library > Manage Libraries...
- In the Library Manager, type
AS5047P
in the search bar. - 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.
- Download the latest version of the library from GitHub Releases.
- Extract the downloaded ZIP file.
- Copy the extracted folder to your Arduino libraries directory (e.g.,
Documents/Arduino/libraries
).
Follow the Arduino Libraries Guide for more detailed instructions.
To add this library to your PlatformIO project, follow these steps:
- Open PlatformIO IDE.
- Search for
AS5047P
in the Library Manager UI, or run the following command in the PlatformIO CLI:pio lib install "jonas-merkle/AS5047P"
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) |
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) |
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.
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.
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.
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.
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.
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);
}
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.
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.
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. |