Interfacing the AS5600 sensor

Place code snippets and demo code here
Post Reply
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Interfacing the AS5600 sensor

Post by cicciocb »

Hi all,
folowing the comments on the forum, I bought an AS5600 magnetic rotary position sensor and played a little bit with it.
The AS5600 uses Hall-effect sensors to measure the angle of a magnetic field and provides a digital output proportional to the angle of the magnetic field.
This sensor has a direct analog output (as reported by peridot [Local Link Removed for Guests]) so can be used "perfectly straight out the box" using an analog input.
It has a lot of functionalities (such as the possibility to define a given angle range) using the I2C interface.
However, I think that the default 0-360° range is adapted to most of the applications.
You can find here an example on how handle this AS5600 sensor using the I2C without requiring a dedicated driver.
I tried to comment the code so should not be hard to understand how use it.

Code: [Local Link Removed for Guests]

' Example of interfacing with the sensor AS5600
' without using any library but only
' existing 'I2C commands / functions
' datasheet 
' https://dammedia.osram.info/media/resource/hires/osram-dam-25175617/AS5600_DS000365_5-00.pdf
'---------------------------------------------------------------------
I2C.SETUP 21, 22 ' set I2C port on pins 21 and 22
a = 0
while 1
  as5600_read a
  wlog "angle "; int(a /4096 * 360) ; "°" 
  pause 200
wend
end  
  
'AS5600 library
' the range goes from 0 to 4095
' greater values means no detection 
sub as5600_read(angle)
  i2c.begin &h36
  i2c.write &h0c ' raw angle
  i2c.end
  I2C.REQFROM &h36, 2
  HI = i2c.read
  LO = i2c.read
  angle = hi*256+lo
end sub
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

Re: Interfacing the AS5600 sensor

Post by Zim »

If anyone is having problems with getting the analog out signal, connect the GPO pin of the AS5600 encoder to VCC.

Cheers
Zim
Post Reply