AS5600 i2C: Incorrect angle readings

Hi @SHI-R-ISH , welcome to SimpleFOC!

That seems fine. But please work in radians as @VIPQualityPost suggests, otherwise you will have a constant source of errors.

I think you should change the code back to the original version of the library, and then try again. It sounds like you might have inadvertently mixed something up.

To print the current angle value in degrees you can use:

Serial.println(sensor.getAngle()/_2PI * 360.0f, 2);

Otherwise your test-code seems ok. When just printing the angles it will run too fast. You can add a delay to the main loop:

delayMicroseconds(1000); // run main loop 1000x per second, its enough

Remember to remove that when actually running a motor though.

If the problems still persist, then it most likely has to do with the setup:

  • is the magnet a correct diametrical type?
  • is the sensor close enough to the magnet?
  • is the sensor correctly configured for the voltage you are using 3.3V/5V?
  • are the other terminals of the sensor properly configured (e.g. the DIR pin in particular should not be left floating)

Many people have problems with the AS5600 related to one of these points.