On Variable Changed icon On Variable Changed Run scripts automatically when specified ARC variables change; define variable-to-script pairs, monitor status, and trigger actions. Try it →
Tutorial
Published — Updated

Use Arduino For Wheel Encoder Counter

Step 3 of 4
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


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

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!