AS5600 - Read Angle
This page contains simple examples demonstrating sensor initialization and angle measurement using the AS5600 magnetic position sensor.
Read Angle
In this code snippet, the loop() function continuously reads the current angular position measured by the AS5600 sensor. The readAngle() function returns the angle value, while rawAngle() returns the raw sensor measurement which is converted to degrees.
void loop()
{
Serial.print(sensor.readAngle()); // Read angle value
Serial.print("\t"); // Tab spacing for readability
Serial.println(sensor.rawAngle() * AS5600_RAW_TO_DEGREES); // Convert raw value to degrees
delay(1000); // Wait before taking another measurement
}
sensor.readAngle()
Reads the current angular position measured by the AS5600 sensor.
Returns value: An integer representing the measured angle.
sensor.rawAngle()
Reads the raw angular measurement value from the AS5600 sensor.
Returns value: A raw integer value representing the sensor measurement.
Full example
Open the Serial Monitor at 115200 baud to observe measured angle values.
#include <Wire.h>
#include "Position-sensor-AS5600-breakout-SOLDERED.h"
PositionSensor sensor; // Create sensor object
/**
* Connecting diagram:
*
* AS5600 NULA DeepSleep
* VCC------------------------->3.3V
* GND------------------------->GND
* SCL------------------------->IO9
* SDA------------------------->IO8
*
* Or, simply use a Qwiic cable!
*
*/
void setup()
{
Serial.begin(115200); // Begin serial communication
Wire.begin(8, 9); // SDA, SCL for NULA DeepSleep
if (!sensor.begin()) // Initialize sensor
{
Serial.print("AS5600 not found!");
while (true)
{
delay(1000);
}
}
Serial.println("AS5600 found!");
while (!sensor.magnetDetected()) // Wait for magnet detection
{
Serial.println("Magnet not detected!");
delay(1000);
}
}
void loop()
{
Serial.print(sensor.readAngle());
Serial.print("\t");
Serial.println(sensor.rawAngle() * AS5600_RAW_TO_DEGREES);
delay(1000);
}

Read_Angle.ino
Example file for using the AS5600 sensor with Qwiic/I2C