Want to know the rotational angle of a motor spindle? Want 12 bit precision? Want easy I2C connectivity? All for less than £5.
Well, the AS5600 is just the board for you.
When purchasing; make sure you get a module with the diametric magnet. It is a special magnet. A standard neodymium magnet won’t work.
Hardware
Electrical connections
The hook up guide for this module is a standard I2C connection.
The module is 5V rated (check your own supplier) and has it’s own pull-up resistors for the I2C bus.
There is an additional connection from the DIR pin. Pull this to ground for normal operation. Pull to logic-high to reverse the direction.
PhysicaL Setup
The magnet needs to be placed above the IC of the sensor with the flat faces parallel to each other.
The magnet ideally needs to be within 1.0mm from the face of the IC.
The connector to the motor will depend on your motor. For best results, you will need a 3D printer to make custom mounts.
There do appear to be specific modules for NEMA 17 applications. I’ve not tried these; but they do interest me.
Software
I use the library by Rob Tillaart: GitHub – RobTillaart/AS5600: Arduino library for AS5600 magnetic rotation meter
I’ve found the library easy to use. This is a copy of an example code for simple position reading; good for simple testing.
// FILE: AS5600_position.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/AS5600
#include "AS5600.h"
AS5600 as5600; // use default Wire
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("AS5600_LIB_VERSION: ");
Serial.println(AS5600_LIB_VERSION);
Wire.begin();
as5600.begin(4); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
Serial.println(as5600.getAddress());
// as5600.setAddress(0x40); // AS5600L only
int b = as5600.isConnected();
Serial.print("Connect: ");
Serial.println(b);
delay(1000);
}
void loop()
{
static uint32_t lastTime = 0;
// set initial position
as5600.getCumulativePosition();
// update every 100 ms
// should be enough up to ~200 RPM
if (millis() - lastTime >= 100)
{
lastTime = millis();
Serial.print(as5600.getCumulativePosition());
Serial.print("\t");
Serial.println(as5600.getRevolutions());
}
// just to show how reset can be used
if (as5600.getRevolutions() >= 10)
{
as5600.resetPosition();
}
}
There may be other nuances with different MCUs; should I find any then I will update this page.
Page created: 23rd April 2024