Screen Recorder icon Screen Recorder Record your screen to WMV1/WMV2/H263P files with selectable bitrate, save-folder and start/stop controls, creating tutorial or demo video snippets. 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

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.