Rotary Encoder Position Counter

On an Arduino Nano 33 BLE, decode a mechanical quadrature handwheel so that each full click counts once in the right direction, while contact chatter, rocking and invalid transitions never count, and a push button zeroes the position.

Placa
Nano 33 BLE · Arduino
Dificultad
Media
Tema
Data Handling & Algorithms
Acceso
Plan completo

La tarea

Rotary Encoder Position Counter

A small CNC router gets a manual handwheel for jogging the spindle. The wheel is a mechanical quadrature encoder with clicks (detents). Mechanical contacts bounce and operators rock the wheel back and forth, but a wrong step here moves a cutting tool, so every click must count exactly once, in the right direction, and nothing else may count.

Hardware

  • Arduino Nano 33 BLE (nRF52840, 3.3 V logic). Serial console on Serial1 (D0/D1), 115200 baud. Serial is USB and is not seen by the tests. The motion controller reads the console.
  • Encoder channels A on D2 and B on D3, common pin to GND. Use the internal pull-ups. At a click (rest position) both channels are HIGH.
  • Turning one click clockwise, A goes LOW first, then B goes LOW, then A returns HIGH, then B returns HIGH. Counter-clockwise is the same with B leading.
  • D5: the wheel's push button (zero), to GND, LOW = pressed.

Write the sketch in sketch/sketch.ino. In setup() open Serial1 at 115200 baud, start at position 0, then print READY. Never block with delay(): a loop that reads the pins all the time is fast enough.

Este es el inicio de la tarea. Inicia sesión con el plan completo para leer el resto y resolverla.

Qué incluye

  • Tu firmware se compila y ejecuta en una placa emulada y se comprueba con pruebas a nivel de hardware.
  • Una explicación escrita de la solución.
  • No necesitas placa de desarrollo ni toolchain local.

¿Nuevo en embebidos? Empieza por la hoja de ruta: Cómo aprender sistemas embebidos (en inglés)