Personality Generator icon Personality Generator Background randomizer that executes timed scripts to add lifelike actions (movement, servos, camera/control) and unique personality to your robot Try it →
Asked
QR scan repeats, servos jitter on Leonardo

QR Scan Repeats, Servos Jitter On Leonardo

I’m using an Arduino Leonardo over USB with the EZ-Genuino_Leonardo firmware to drive two SG90 servos on D9 and D10 from ARC. Connection is solid (DTR Enabled checked in the Connection Config, baud per the tutorial). Servos have their own 5V BEC and share ground with the Leonardo; they move smoothly using the standard Servo() commands from the servo Controls.

I’m trying to trigger servo positions by scanning QR codes. I added the QR Code Generator skill to make two codes: LEFT and RIGHT. I then use the Camera Device skill set to track QR Codes. The detection works, but as long as the QR code stays in frame, the Camera script seems to fire repeatedly and my servos twitch because they keep getting the same position commands at a high rate. Sometimes the text variable is blank on the first frame, then populated on subsequent frames.

Here’s what I’ve got in Camera Device -> Scripts -> On QR Code:

# trying to debounce repeat scans
if ($CameraObject != $lastQR)
  $lastQR = $CameraObject
  if ($lastQR = "LEFT")
    Servo(D9, 60)
    Servo(D10, 120)
  elseif ($lastQR = "RIGHT")
    Servo(D9, 120)
    Servo(D10, 60)
  endif
endif

Questions: is $CameraObject the correct variable for the decoded QR text from the Camera control, or should I be reading something else for QR Code Generator output, and what’s the best practice in ARC to latch a QR detection so it only triggers once per unique code (or until the code leaves the frame) to avoid servo jitter on the Leonardo?



Related Hardware (view all EZB hardware)
Connect Synthiam ARC to Arduino Leonardo via USB using EZB firmware to control GPIO, PWM, servos, and ADC; enable DTR in ARC connection.
USB
Servos 12
Camera
Audio
UART Varies
I2C
ADC Varies
Digital Varies

ARC Pro

Upgrade to ARC Pro

Experience early access to the latest features and updates. You'll have everything that is needed to unleash your robot's potential.