mirror of
https://github.com/danbulant/ambientlightdemo
synced 2026-07-08 20:40:52 +00:00
angle monitoring
This commit is contained in:
parent
2c8dd76031
commit
10a1b6d9d8
1 changed files with 23 additions and 0 deletions
23
rpi/angle-test.py
Normal file
23
rpi/angle-test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import smbus2
|
||||||
|
import time
|
||||||
|
|
||||||
|
# Define I2C address and bus
|
||||||
|
AS5600_ADDR = 0x36
|
||||||
|
ANGLE_REG = 0x0E
|
||||||
|
|
||||||
|
bus = smbus2.SMBus(1)
|
||||||
|
|
||||||
|
def read_angle():
|
||||||
|
# Read two bytes from the angle register
|
||||||
|
raw_data = bus.read_i2c_block_data(AS5600_ADDR, ANGLE_REG, 2)
|
||||||
|
angle = (raw_data[0] << 8) | raw_data[1] # Combine MSB and LSB
|
||||||
|
angle = angle & 0x0FFF # Mask to 12 bits
|
||||||
|
return (angle / 4096.0) * 360.0 # Convert to degrees
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
angle = read_angle()
|
||||||
|
print(f"Angle: {angle:.2f} degrees")
|
||||||
|
time.sleep(0.5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Exiting...")
|
||||||
Loading…
Reference in a new issue