entrees_num.py

Adafruit Feather nRF52840 Express · File : entrees_num.py · Language : Python · Use case : Surveiller quatre entrées numériques

Four buttons or digital sensors on D5, D6, D9, D10 — the Feather pins as marked — polled in a loop with every change traced to the serial console. The debug dashboard of any multi-input build.

Hardware

An Adafruit Feather nRF52840 Express (nRF52840 Cortex-M4F SoC, BLE 5 / 802.15.4) with on-board NeoPixel, red LED, 2 MB QSPI flash for the CircuitPython filesystem and a LiPo battery connector. Up to four buttons or 3.3 V digital outputs; grounds common with the Feather. The pins are 3.3 V — no 24 V or 5 V on these inputs.

Wiring

Each button between its pin (D5/D6/D9/D10) and GND. Neighboring 3V3 and GND pins serve as test rails; never exceed 3.3 V on an input.

How it works

Each pin is a digitalio object with pull-up; the loop compares against the dict-stored state and prints only on change, at 50 Hz. Light, readable, extensible.

Running it

CircuitPython (feather_nrf52840_express build) installed via the UF2 bootloader (double reset); edit code.py on the CIRCUITPY drive, console in Mu/Thonny.

Variants

Move to interrupts (digitalio + alarm for wake), count presses per pin, or push the state over BLE UART to a phone.

entrees_num.py

# Moniteur de 4 entrées : D5, D6, D9, D10 (broches Feather marquées).
# Trace l'état sur la console série (Ctrl-C dans Mu/Thonny pour sortir).
import time
import board
import digitalio

ENTREES = {}
for nom, broche in [("D5", board.D5), ("D6", board.D6),
                    ("D9", board.D9), ("D10", board.D10)]:
    ligne = digitalio.DigitalInOut(broche)
    ligne.direction = digitalio.Direction.INPUT
    ligne.pull = digitalio.Pull.UP
    ENTREES[nom] = ligne

dernier = {}
while True:
    for nom, ligne in ENTREES.items():
        etat = ligne.value
        if dernier.get(nom) != etat:          # trace sur changement
            print(nom, "->", "ENFONCE" if not etat else "libre")
            dernier[nom] = etat
    time.sleep(0.02)

← Back to the board