Skip to content

Matthias-Wandel/AS5600-Raspberry-Pi-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connecting AS5600 magnetic encoder to Raspberry Pi, using Python

The AS5600 chip is a magnetic rotary encoder, containing two hall effect sensors tha enalbe it to accurately measure the angle and magnitude of a magnetic field.

Rotating a magnet above the chip allows it to act as a rotary encoder.

Talking to the AS5600 turns out to be simple, but I found no example code for this on the internet. I always prefer to start with a working example before changing any code.

So I added this github repository as an example for others to find as a starting point.


Physical wring to Raspberry Pi 40-pin GPIO header:

Pi pinPi functionAS5600 board
013.3V DC powerVCC
03GPIO 02 / I2C SDASDA
05GPIO 03 / I2C SCLSCL
09GroundGROUND
and DIR

The actual code to talk to the AS5600 chip is just 9 lines of python:
import smbus
DEVICE_AS5600 = 0x36 # Default device I2C address
bus = smbus.SMBus(1)

def ReadRawAngle(): # Read angle (0-360 represented as 0-4096) read_bytes = bus.read_i2c_block_data(DEVICE_AS5600, 0x0C, 2) return (read_bytes[0]<<8) | read_bytes[1];

def ReadMagnitude(): # Read magnetism magnitude read_bytes = bus.read_i2c_block_data(DEVICE_AS5600, 0x1B, 2) return (read_bytes[0]<<8) | read_bytes[1];

This code is contained in several stand alone python programs in this repository which I used for testing the AS5600 chip.

I used a stepper motor to rotate the magnet to check for accuracy.

I found the AS5600 provided good 12 bit precision, with little jitter for the rotation angle, but absolute rotational accuracy depends on having the magnet exactly centered above the chip. Without a precision machined jig or 3d printed jig, It is unlikely that you will be able to position the magnet accurately enough to have less than 1 degree error variation over a full rotation.

About

Code and scematic to connect to AS5600 magnetic encoder from Raspberry Pi using Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages