Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

jonas-merkle/AS5047P

Repository files navigation

GitHub Workflow Status (with branch)GitHub Workflow Status (with branch)GitHub release (latest by date)GitHubGitHub issuesGitHub pull requestsMaintenance

High-level, type-safe SPI driver forams/TAAS5047P (and compatible AS5x47 parts).Read 14-bit angles, magnitude, and diagnostics with concise APIs—works on classic Arduino, Feather, Teensy, and other SPI-capable boards.


Table of Contents


Features

  • ✅ 14-bitangle readout (raw or DAE-compensated)
  • Magnitude (CMAG) &diagnostics (AGC, CORDIC overflow, field strength)
  • ✅ CleanC++ types for all registers and SPI frames (with parity helpers)
  • Even parity verification over 15 LSBs (MSB parity bit handled for you)
  • ✅ Arduino-style, minimal API + detailed status strings
  • ✅ Examples for quick bring-up

Supported Sensors

This library targetsAS5047P and is compatible with several AS5x47 variants that share the same SPI framing:

  • AS5047P,AS5047D,AS5147,AS5147P,AS5247

Not supported:AS5047U,AS5147U,AS5247U (different protocol/regs).


Installation

Arduino Library Manager

  1. Sketch → Include Library → Manage Libraries…
  2. SearchAS5047P, thenInstall.

You’ll need Arduino IDE ≥ 1.6.2 for Library Manager.

Manual

  1. Download the latestRelease ZIP.
  2. Extract to your Arduinolibraries/ folder.
  3. Restart the IDE.

PlatformIO

pio lib install"jonas-merkle/AS5047P"

Or add toplatformio.ini:

lib_deps = jonas-merkle/AS5047P

Hardware Setup

SPI Pins & Power Notes

  • SPI mode:MODE1 (CPOL=0, CPHA=1),MSB first

  • Voltage:

    • Many dev boards (Feather M0, Teensy 3.x/4.x) are3.3 V only → power sensor @3.3 V
    • Classic Arduino Uno/Mega can power at5 V, but confirmlogic levels and your breakout’s level shifting.
  • CS pin defaults toD9, configurable in the constructor.

Quick Wiring Tables

Arduino Uno

AS5047PUnoNotes
GNDGNDGround
VDD5VSensor Vcc
VDD3VNC
MOSI11SPI MOSI
MISO12SPI MISO
CLK13SPI SCK
CSn9Chip Select (configurable)

Adafruit Feather M0 (3.3 V logic)

AS5047PFeather M0Notes
GNDGNDGround
VDD3V3.3 V only
VDD3V3VTie to 3.3 V if required by board
MOSIMOSISPI MOSI
MISOMISOSPI MISO
CLKSCKSPI SCK
CSn9Chip Select (configurable)

⚠️3.3 V ONLY on Feather/Teensy. Donot feed 5 V.

Teensy 3.5/3.6/4.0/4.1 use their standard SPI pins (MOSI/MISO/SCK) and a free GPIO for CS (e.g., 10). Power @3.3 V.


Quick Start

#include<SPI.h>#include<AS5047P.h>// CS pin 9, SPI speed default from library header (can pass a custom speed)AS5047Pas5047p(9);voidsetup() {  Serial.begin(115200);// Initialize SPI via library and verify connectivityif (!as5047p.initSPI()) {    Serial.println("AS5047P init failed. Check wiring and power.");while (true) {delay(1000); }  }}voidloop() {// Read 14-bit angle (degrees) with DAE compensationfloat deg = as5047p.readAngleDegree(true);  Serial.print("Angle (deg):");  Serial.println(deg,3);// Read magnitudeuint16_t mag = as5047p.readMagnitude();  Serial.print("Magnitude:");  Serial.println(mag);delay(500);}

Advanced Usage

Error & Diagnostic Handling

You can request parity verification and collect communication/sensor diagnostics on each read:

AS5047P_Types::ERROR_t err;float deg = as5047p.readAngleDegree(/*withDAEC*/true,/*errorOut*/ &err,/*verifyParity*/true,/*checkForComError*/true,/*checkForSensorError*/true);if (!err.noError()) {  Serial.println(err.toArduinoString());// nicely formatted error report}

You can also dump a combined status block:

Serial.println(as5047p.readStatusAsArduinoString());

Low-level Register Access

Typed wrappers let you work with registers directly:

// Read DIAAGC (AGC, LF, COF, MAGH/L)AS5047P_Types::DIAAGC_t dia = as5047p.read_DIAAGC(/*errorOut*/nullptr,/*verifyParity*/true);// Write to SETTINGS1 (example: toggle DAE compensation disable bit)AS5047P_Types::SETTINGS1_t s1 = as5047p.read_SETTINGS1();s1.data.values.DAECDIS =1;// disable DAEAS5047P_Types::ERROR_t err;bool ok = as5047p.write_SETTINGS1(&s1, &err,/*checkForComError*/true,/*verifyWittenReg*/true);if (!ok) Serial.println(err.toArduinoString());

Parity for frames is handled internally by the SPI layer; you can also useAS5047P_Util::parityCheck() if you construct frames yourself.


Documentation

Doxygen is generated from the extensively commented headers and sources.


Troubleshooting

  • initSPI() fails

    • Checkpower (3.3 V vs 5 V board),common ground, andCS pin number.
    • VerifySPI mode 1 (the library sets this), and that no other library reconfigures SPI mid-flight.
    • If multiple SPI users exist, consider enablingAS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB inutil/AS5047P_Settings.h.
  • Random read errors

    • Try disabling the ~100 ns NOP delay (AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY) or vice versa depending on your MCU clock.
    • Shorten wires; keep SPI lines tight and add GND reference near sensor.
  • Angles look noisy

    • Checkmagnet distance/centering (MAGH/MAGL flags, AGC value inDIAAGC).
    • Consider usingDAE-compensated angle (readAngleDegree(true)).

Project Status

  • ✅ Read/write APIs for all relevant registers
  • ✅ Parity checking & formatted error/status strings
  • ✅ CI, Doxygen docs, Arduino & PlatformIO registry
  • 🚧 Broader write-path testing across MCUs/clock rates
  • 🚧 More examples (DAE tuning, ABI/U VW config)
  • ❌ STM32 HAL backend (PRs welcome)

License

Licensed underGNU GPLv3. SeeLICENSE.


Acknowledgements

Thanks to contributors and users testing across different boards. Issues and PRs are welcome!

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp