logging_qspi.py

Adafruit Feather nRF52840 Express · File : logging_qspi.py · Language : Python · Use case : Journaliser des mesures sur la flash QSPI

The 2 MB QSPI flash exposed as a filesystem makes a standalone logger: this script journals an analog reading to CSV every 10 s with relative timestamps. Fetch the file later by plugging the board in USB.

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. Just the Feather; a 0-3.3 V sensor on A0 (or nothing: the floating channel gives test values). A PC to read journal.csv afterwards.

Wiring

Sensor on A0/3V3/GND per its datasheet. The QSPI flash is on-board — nothing to wire, and writes survive power loss.

How it works

open("/journal.csv", "a") appends one line per cycle; CircuitPython writes to the CIRCUITPY partition in QSPI flash. time.monotonic gives relative seconds since boot, enough for a curve.

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

Timestamp absolutely with a DS3231 module (I2C), compress to binary to save space, or dump the journal to a phone over BLE before rotation.

logging_qspi.py

# Journal CSV sur la flash QSPI de 2 Mo (le système de fichiers).
# Les fichiers survivent à la coupure d'alimentation.
import time
import board
import analogio
import rtc

entree = analogio.AnalogIn(board.A0)
CHEMIN = "/journal.csv"

# Horloge interne : figée à minuit au boot, d'où le temps relatif.
t0 = time.monotonic()

with open(CHEMIN, "a") as f:
    f.write("t_s,brut,volts\n") if False else None  # en-tête optionnel

while True:
    brut = entree.value
    with open(CHEMIN, "a") as f:
        f.write("%d,%d,%.3f\n" % (
            time.monotonic() - t0, brut, brut * 3.3 / 65535))
    time.sleep(10)   # une ligne toutes les 10 s

← Back to the board