AS5600-Driver 0.1.0

A platform-agnostic driver for the AS5600 magnetic rotary encoder using embedded-hal.
Documentation

AS5600 Driver (Rust)

License: MIT Crates.io

A comprehensive, low-level, platform-agnostic Rust driver for the AS5600 magnetic rotary encoder (12-bit contactless potentiometer). Built on embedded-hal 1.0, it provides direct access to all device registers and OTP programming functions.

๐Ÿ“Œ Table of Contents

๐Ÿš€ Key Features

  • no_std Support: Ready for bare-metal microcontrollers (ESP32, STM32, nRF, etc.).
  • Full Register Map: Complete coverage of ZPOS, MPOS, MANG, CONF, STATUS, RAW_ANGLE, ANGLE, AGC, and MAGNITUDE.
  • Hardware Configuration: Support for Hysteresis, Power Modes, PWM settings, and Fast/Slow Filters.
  • Diagnostics: Methods to monitor magnet detection, magnetic field strength, and Automatic Gain Control (AGC).
  • OTP Programming: Secure methods for permanent burning of settings (marked unsafe).
  • Mocking Support: Built-in hardware emulator for testing and simulation (behind the mock feature).
  • Trait-based Interface: AS5600Interface trait allows easy swapping between real hardware and mocks.
  • Cross-Platform: Support for Linux (SBCs like Raspberry Pi), ESP32 (std & no_std), and any other platform implementing embedded-hal.

๐Ÿ“ฆ Installation

Add this to your Cargo.toml:

[dependencies]
# Basic no_std version
AS5600-Driver = "0.1.0"

# Or with std and anyhow support (recommended for ESP32/Linux)
AS5600-river = { version = "0.1.0", features = ["std", "anyhow"] }

โš™๏ธ Features

  • std: Enables standard library support.
  • anyhow: Enables integration with anyhow crate for easier error handling (requires std).
  • mock: Enables the hardware mock emulator (requires std).

๐Ÿ›  Usage Examples

All examples provide a real-time monitoring dashboard as shown below:

AS5600 Dashboard Preview Typical real-time diagnostic output from the provided examples.

We provide several ready-to-use examples for different environments:

Quick Start: Decoupled Interface (Traits)

Using AS5600Interface allows your application logic to be independent of the specific I2C implementation.

use AS5600_Driver::AS5600Interface;

// This function works with ANY sensor implementation (Real or Mock)
fn run_diagnostic(encoder: &mut impl AS5600Interface) -> anyhow::Result<()> {
    let raw = encoder.read_raw_angle()?;
    let status = encoder.get_magnet_status()?;
    
    println!("Position: {}, Detected: {}", raw, status.detected);
    Ok(())
}

๐Ÿ”„ Sharing the I2C Bus

The AS5600 has a fixed I2C address (0x36).

Multiple Sensors

To use multiple AS5600 sensors on the same bus, you must use an I2C multiplexer (e.g., TCA9548A).

Shared Bus with Other Devices

To share the bus with other device types, use a bus manager like embedded-hal-bus:

// Using a reference (&mut) to the I2C bus
let mut bus = I2cDriver::new(...)?;
let mut encoder1 = AS5600Driver::new(&mut bus);
// Other sensors on the same bus must have different addresses
let mut other_sensor = OtherSensor::new(&mut bus, 0x42); 

โš ๏ธ Safety Warning: OTP Programming

The AS5600 has One-Time Programmable (OTP) memory. These methods perform permanent, irreversible hardware changes:

  • danger_permanent_burn_settings(): Programs ZPOS and MPOS. Max 3 times.
  • danger_permanent_burn_config(): Programs CONF register. ONLY ONCE.

Support the Project / ะŸั–ะดั‚ั€ะธะผะฐั‚ะธ ะฟั€ะพะตะบั‚

If you find this extension useful and want to support development or speed up new features:

Donate via:

  • ๐Ÿ‡บ๐Ÿ‡ฆ Donatello โ€” Ukrainian service supporting:
    • ๐Ÿ’ณ Visa/Mastercard
    • ๐Ÿช™ Cryptocurrency (USDT)
    • ๐Ÿฆ Other payment methods
  • ๐ŸŒ PayPal: pavvers1@gmail.com

Your support helps keep this project alive and growing. Thank you! / ะ”ัะบัƒัŽ ะทะฐ ะฟั–ะดั‚ั€ะธะผะบัƒ! ๐Ÿ’™๐Ÿ’›


You can contact me via telegram or pavvers1@gmail.com.

๐Ÿ“„ License

Licensed under either of: