I have a problem that I’m not able to solve and need your help.
I’m trying to read the stepper motor angle using the AS5600 magnetic position encoder.
I’m using raspberry pi 4 and the pinout is the following:
VCC to 3.3V , GND to Ground ,SDA to GPIO2 (Pin 3) , SCL to GPIO3 (Pin 5) , DIR to Ground
the code I’m using is this:
import smbus
import time
# Define I2C bus number and AS5600 device address
bus = smbus.SMBus(1)
AS5600_ADDRESS = 0x36
# AS5600 register addresses
AS5600_REG_ANGLE = 0x0E # Read-only register for angle value
def read_angle():
# Read 14-bit angle value from AS5600
data = bus.read_i2c_block_data(AS5600_ADDRESS, AS5600_REG_ANGLE, 2)
angle = (data[0] << 8) | data[1]
return angle
try:
while True:
# Read angle value from AS5600
angle = read_angle()
print("Angle:", angle)
time.sleep(0.1) # Wait for 100 ms before next reading
except KeyboardInterrupt:
print("Program stopped by user")
I used the same code and it worked before but after few days I tried it and all I get is “angle: 0”
I tried replacing the encoder module and wires, but no use. I even tried to make it work on Arduino but also nothing.
I can’t figure this out. If you have any idea please let me know.