bitfasching / AS5601

Library for driving the sensor AS5601 over I²C on an Arduino
Other
16 stars 6 forks source link

AS5601 Library for Arduino

A wrapper for driving the cheap but great magnetic rotary sensor AS5601 over I²C on an Arduino. The library aims to offer clean high-level access to the sensor's capabilities and to provide convenience functions for common tasks. The current implementation supports only a subset of the sensor's functionality, more functions may be added in future versions.

Quick Start

Initialize the driver, which sets up the I²C bus:

AS5601 Sensor;

Find out if the magnet is in range:

if ( Sensor.magnetDetected() ) { … }

Query the sensor to get the magnet's current angle:

int angle = Sensor.getAngle();

Reference

Static Properties

The sensor's register addresses are available as static constants as specified in the datasheet. The struct ByteRegister includes the 8-bit registers, WordRegister contains the starting addresses of the 16-bit registers.

Low-Level Instance Methods

readRaw8( registerAddress )
readRaw16( registerStartAddress )
writeRaw8( registerAddress, value )
writeRaw16( registerStartAddress, value )

Higher-Level Instance Methods

magnetDetected()
getMagnitude()
getGain()
getRawAngle()
setZeroPosition( rawAngle )
setResolution( angleSteps )
getAngle()

Functionality not covered by the above higher-level methods can be easily added using the low-level communication methods. The already included register address maps facilitate this. In any case, giving the datasheet a read is highly recommended to understand how the sensor works.