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.
- Carte
- Nano 33 BLE · Arduino
- Difficulté
- Moyen
- Thème
- Data Handling & Algorithms
- Accès
- Offre complète
La tâche
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.Serialis 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
LOWfirst, then B goesLOW, then A returnsHIGH, then B returnsHIGH. 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.
Voici le début de la tâche. Connectez-vous avec l'offre complète pour lire la suite et la résoudre.
Ce que vous obtenez
- Votre firmware est compilé et exécuté sur une carte émulée, puis vérifié par des tests matériels.
- Une explication écrite de la solution.
- Aucune carte de développement ni toolchain locale requise.
Débutant en embarqué ? Commencez par la feuille de route : Apprendre les systèmes embarqués (en anglais)