{"id":20443952,"url":"https://github.com/jonas-merkle/as5047p","last_synced_at":"2026-01-18T19:01:12.309Z","repository":{"id":43289089,"uuid":"325641954","full_name":"jonas-merkle/AS5047P","owner":"jonas-merkle","description":"An Arduino library for the AS5047P high-resolution rotary position sensor. Supporting also the following sensor types: AS5047D, AS5147, AS5147P, AS5247","archived":false,"fork":false,"pushed_at":"2025-10-07T16:26:51.000Z","size":1407,"stargazers_count":33,"open_issues_count":8,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-07T18:20:01.637Z","etag":null,"topics":["abi","angle","arduino-library","as5047d","as5047p","as5147","as5147p","as5247","as5x47","encoder","high-resolution","rotary-encoder","rotary-position-sensor","rotaty","sensor","spi","uvw"],"latest_commit_sha":null,"homepage":"https://github.com/jonas-merkle/AS5047P","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonas-merkle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"jonas-merkle","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-12-30T20:28:10.000Z","updated_at":"2025-09-08T09:37:37.000Z","dependencies_parsed_at":"2025-04-12T23:51:57.237Z","dependency_job_id":"41dd553a-44ed-46f5-8e92-a076255ae414","html_url":"https://github.com/jonas-merkle/AS5047P","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/jonas-merkle/AS5047P","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonas-merkle%2FAS5047P","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonas-merkle%2FAS5047P/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonas-merkle%2FAS5047P/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonas-merkle%2FAS5047P/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonas-merkle","download_url":"https://codeload.github.com/jonas-merkle/AS5047P/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonas-merkle%2FAS5047P/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28548941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abi","angle","arduino-library","as5047d","as5047p","as5147","as5147p","as5247","as5x47","encoder","high-resolution","rotary-encoder","rotary-position-sensor","rotaty","sensor","spi","uvw"],"created_at":"2024-11-15T09:50:02.554Z","updated_at":"2026-01-18T19:01:12.303Z","avatar_url":"https://github.com/jonas-merkle.png","language":"C++","funding_links":["https://github.com/sponsors/jonas-merkle"],"categories":[],"sub_categories":[],"readme":"# AS5047P – Arduino Library\n\n![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/jonas-merkle/AS5047P/Arduino-Library-CI.yml?branch=master\u0026label=build%20master)\n![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/jonas-merkle/AS5047P/Arduino-Library-CI.yml?branch=develop\u0026label=build%20develop)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/jonas-merkle/AS5047P)\n![GitHub](https://img.shields.io/github/license/jonas-merkle/AS5047P)\n![GitHub issues](https://img.shields.io/github/issues/jonas-merkle/AS5047P)\n![GitHub pull requests](https://img.shields.io/github/issues-pr/jonas-merkle/AS5047P)\n![Maintenance](https://img.shields.io/maintenance/yes/2026)\n\nHigh-level, type-safe SPI driver for **ams/TA** **AS5047P** (and compatible AS5x47 parts).\nRead 14-bit angles, magnitude, and diagnostics with concise APIs—works on classic Arduino, Feather, Teensy, and other SPI-capable boards.\n\n---\n\n## Table of Contents\n\n- [AS5047P – Arduino Library](#as5047p--arduino-library)\n  - [Table of Contents](#table-of-contents)\n  - [Features](#features)\n  - [Supported Sensors](#supported-sensors)\n  - [Installation](#installation)\n    - [Arduino Library Manager](#arduino-library-manager)\n    - [Manual](#manual)\n    - [PlatformIO](#platformio)\n  - [Hardware Setup](#hardware-setup)\n    - [SPI Pins \\\u0026 Power Notes](#spi-pins--power-notes)\n    - [Quick Wiring Tables](#quick-wiring-tables)\n      - [Arduino Uno](#arduino-uno)\n      - [Adafruit Feather M0 (3.3 V logic)](#adafruit-feather-m0-33-v-logic)\n  - [Quick Start](#quick-start)\n  - [Advanced Usage](#advanced-usage)\n    - [Error \\\u0026 Diagnostic Handling](#error--diagnostic-handling)\n    - [Low-level Register Access](#low-level-register-access)\n  - [Documentation](#documentation)\n  - [Troubleshooting](#troubleshooting)\n  - [Project Status](#project-status)\n  - [License](#license)\n    - [Acknowledgements](#acknowledgements)\n\n---\n\n## Features\n\n- ✅ 14-bit **angle** readout (raw or DAE-compensated)\n- ✅ **Magnitude (CMAG)** \u0026 **diagnostics** (AGC, CORDIC overflow, field strength)\n- ✅ Clean **C++ types** for all registers and SPI frames (with parity helpers)\n- ✅ **Even parity** verification over 15 LSBs (MSB parity bit handled for you)\n- ✅ Arduino-style, minimal API + detailed status strings\n- ✅ Examples for quick bring-up\n\n---\n\n## Supported Sensors\n\nThis library targets [**AS5047P**](https://look.ams-osram.com/m/d05ee39221f9857/original/AS5047P-DS000324.pdf) and is compatible with several AS5x47 variants that share the same SPI framing:\n\n- **AS5047P**, **AS5047D**, **AS5147**, **AS5147P**, **AS5247**\n\nNot supported: **AS5047U**, **AS5147U**, **AS5247U** (different protocol/regs).\n\n---\n\n## Installation\n\n### Arduino Library Manager\n\n1. **Sketch → Include Library → Manage Libraries…**\n2. Search **`AS5047P`**, then **Install**.\n\n\u003e You’ll need Arduino IDE ≥ 1.6.2 for Library Manager.\n\n### Manual\n\n1. Download the latest **Release** ZIP.\n2. Extract to your Arduino `libraries/` folder.\n3. Restart the IDE.\n\n### PlatformIO\n\n```sh\npio lib install \"jonas-merkle/AS5047P\"\n```\n\nOr add to `platformio.ini`:\n\n```ini\nlib_deps = jonas-merkle/AS5047P\n```\n\n---\n\n## Hardware Setup\n\n### SPI Pins \u0026 Power Notes\n\n- **SPI mode**: `MODE1` (CPOL=0, CPHA=1), **MSB first**\n- **Voltage**:\n\n  - Many dev boards (Feather M0, Teensy 3.x/4.x) are **3.3 V only** → power sensor @ **3.3 V**\n  - Classic Arduino Uno/Mega can power at **5 V**, but confirm **logic levels** and your breakout’s level shifting.\n\n- **CS pin** defaults to **D9**, configurable in the constructor.\n\n### Quick Wiring Tables\n\n#### Arduino Uno\n\n| AS5047P | Uno | Notes                      |\n| ------: | :-: | -------------------------- |\n|     GND | GND | Ground                     |\n|     VDD | 5V  | Sensor Vcc                 |\n|   VDD3V | NC  | —                          |\n|    MOSI | 11  | SPI MOSI                   |\n|    MISO | 12  | SPI MISO                   |\n|     CLK | 13  | SPI SCK                    |\n|     CSn |  9  | Chip Select (configurable) |\n\n#### Adafruit Feather M0 (3.3 V logic)\n\n| AS5047P | Feather M0 | Notes                             |\n| ------: | :--------: | --------------------------------- |\n|     GND |    GND     | Ground                            |\n|     VDD |     3V     | **3.3 V only**                    |\n|   VDD3V |     3V     | Tie to 3.3 V if required by board |\n|    MOSI |    MOSI    | SPI MOSI                          |\n|    MISO |    MISO    | SPI MISO                          |\n|     CLK |    SCK     | SPI SCK                           |\n|     CSn |     9      | Chip Select (configurable)        |\n\n\u003e ⚠️ **3.3 V ONLY** on Feather/Teensy. Do **not** feed 5 V.\n\nTeensy 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**.\n\n---\n\n## Quick Start\n\n```cpp\n#include \u003cSPI.h\u003e\n#include \u003cAS5047P.h\u003e\n\n// CS pin 9, SPI speed default from library header (can pass a custom speed)\nAS5047P as5047p(9);\n\nvoid setup() {\n  Serial.begin(115200);\n  // Initialize SPI via library and verify connectivity\n  if (!as5047p.initSPI()) {\n    Serial.println(\"AS5047P init failed. Check wiring and power.\");\n    while (true) { delay(1000); }\n  }\n}\n\nvoid loop() {\n  // Read 14-bit angle (degrees) with DAE compensation\n  float deg = as5047p.readAngleDegree(true);\n  Serial.print(\"Angle (deg): \");\n  Serial.println(deg, 3);\n\n  // Read magnitude\n  uint16_t mag = as5047p.readMagnitude();\n  Serial.print(\"Magnitude: \");\n  Serial.println(mag);\n\n  delay(500);\n}\n```\n\n---\n\n## Advanced Usage\n\n### Error \u0026 Diagnostic Handling\n\nYou can request parity verification and collect communication/sensor diagnostics on each read:\n\n```cpp\nAS5047P_Types::ERROR_t err;\nfloat deg = as5047p.readAngleDegree(\n  /*withDAEC*/ true,\n  /*errorOut*/ \u0026err,\n  /*verifyParity*/ true,\n  /*checkForComError*/ true,\n  /*checkForSensorError*/ true\n);\n\nif (!err.noError()) {\n  Serial.println(err.toArduinoString()); // nicely formatted error report\n}\n```\n\nYou can also dump a combined status block:\n\n```cpp\nSerial.println(as5047p.readStatusAsArduinoString());\n```\n\n### Low-level Register Access\n\nTyped wrappers let you work with registers directly:\n\n```cpp\n// Read DIAAGC (AGC, LF, COF, MAGH/L)\nAS5047P_Types::DIAAGC_t dia = as5047p.read_DIAAGC(/*errorOut*/ nullptr, /*verifyParity*/ true);\n\n// Write to SETTINGS1 (example: toggle DAE compensation disable bit)\nAS5047P_Types::SETTINGS1_t s1 = as5047p.read_SETTINGS1();\ns1.data.values.DAECDIS = 1; // disable DAE\nAS5047P_Types::ERROR_t err;\nbool ok = as5047p.write_SETTINGS1(\u0026s1, \u0026err, /*checkForComError*/ true, /*verifyWittenReg*/ true);\nif (!ok) Serial.println(err.toArduinoString());\n```\n\n\u003e Parity for frames is handled internally by the SPI layer; you can also use `AS5047P_Util::parityCheck()` if you construct frames yourself.\n\n---\n\n## Documentation\n\n- **Master**: [https://jonas-merkle.github.io/AS5047P/docs/master/html/index.html](https://jonas-merkle.github.io/AS5047P/docs/master/html/index.html)\n- **Develop**: [https://jonas-merkle.github.io/AS5047P/docs/develop/html/index.html](https://jonas-merkle.github.io/AS5047P/docs/develop/html/index.html)\n\nDoxygen is generated from the extensively commented headers and sources.\n\n---\n\n## Troubleshooting\n\n- **`initSPI()` fails**\n\n  - Check **power** (3.3 V vs 5 V board), **common ground**, and **CS pin** number.\n  - Verify **SPI mode 1** (the library sets this), and that no other library reconfigures SPI mid-flight.\n  - If multiple SPI users exist, consider enabling `AS5047P_SPI_ARDUINO_INIT_ON_COM_ENAB` in `util/AS5047P_Settings.h`.\n\n- **Random read errors**\n\n  - Try disabling the ~100 ns NOP delay (`AS5047P_SPI_ARDUINO_USE_100NS_NOP_DELAY`) or vice versa depending on your MCU clock.\n  - Shorten wires; keep SPI lines tight and add GND reference near sensor.\n\n- **Angles look noisy**\n\n  - Check **magnet distance/centering** (MAGH/MAGL flags, AGC value in `DIAAGC`).\n  - Consider using **DAE-compensated** angle (`readAngleDegree(true)`).\n\n---\n\n## Project Status\n\n- ✅ Read/write APIs for all relevant registers\n- ✅ Parity checking \u0026 formatted error/status strings\n- ✅ CI, Doxygen docs, Arduino \u0026 PlatformIO registry\n- 🚧 Broader write-path testing across MCUs/clock rates\n- 🚧 More examples (DAE tuning, ABI/U VW config)\n- ❌ STM32 HAL backend (PRs welcome)\n\n---\n\n## License\n\nLicensed under **GNU GPLv3**. See [LICENSE](./LICENSE).\n\n---\n\n### Acknowledgements\n\nThanks to contributors and users testing across different boards. Issues and PRs are welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonas-merkle%2Fas5047p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonas-merkle%2Fas5047p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonas-merkle%2Fas5047p/lists"}