Use Arduino for Wheel Encoder Counter

EZ-Script Program

In EZ-Builder, add a new EZ-Script control.

This code will be pasted into the EZ-Script control. The code will loop and continue to request the interrupt counts of the encoders from the Arduino.

The values of the encoder are in the array $encoders[0] and $encoders[1]. You may use these two values globally within the project to identify what the encoder values are.

EZB Code

Code:


uartinit(0, 0, 9600)

:loop

# Send a request for data to the arduino
uartwrite(0, 0, "a")

# wait a bit for the data to be transmitted
sleep(50)

$dataAvail = UartAvailable(0, 0)

IF ($dataAvail != 2)

print("The arduino didn't send us anything. Exiting")

halt()

ELSE

UartReadBinary(0, 0, 2, $encoders)

print("Encoder A: " + $encoders[0])
print("Encoder B: " + $encoders[1])

ENDIF

sleep(100)

goto(loop)


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.