Skip to content
esp-labsESP32-S3 bench guide
ESP32-S3 DevKitC pinoutThis lesson uses: VCC on 3V3, RC 3.3V on 3V3, BLK on 7, RES on 8, DC on 9, CS on 10, SDA on 11, SCL on 12, GND on GND, RC SDA on 15, RC SCK on 16, MOSI on 17, MISO on 18, RC RST on 14, IRQ on 13, RC GND on GND, BTN on 5, BOOT on 0.ESP32-S3WROOM-1 N16R8BOOTRSTRGBUSBCOM3V3VCC3V3RC 3.3VRST45BTN67BLK15RC SDA16RC SCK17MOSI18MISO8RES3469DC10CS11SDA12SCL13IRQ14RC RST5VGNDGNDGNDRC GNDTX 43RX 441242414039383736350BOOT454847212019GNDGND
  • used in this lesson
  • safe GPIO
  • avoid
  • power
  • ground
  • button input
  • RC522
Between lessons
  1. Ctrl+C closes the monitor on the Mac only. The board keeps running.
  2. Unplug USB: this is what stops the program and the screen
  3. Rewire while off
  4. Check VCC is on 3V3, no loose ends
  5. Plug in, flash the next lesson

Never unplug during Writing at 0x…. Pin changing from output to input? Flash first, then wire.

Lesson R5

RFID & NFC · lesson 5 of 8

Write a label, keep a count

built, not flashed

Write your own 16 bytes into a data block and read them back. Then use MIFARE's built-in arithmetic: a value block stores a number three times (once inverted) and the card itself adds or subtracts, then commits the result in one step. A backup block keeps the value from before.

Goal

Write text to your card and keep a credit counter on it that the card itself updates.

You're done when

  • write 4 hello bench says “written and read back”.
  • After credits init 50 and credits use 3, the credits view shows 47 with backup 50.
  • dump shows block 4 as data and blocks 8 and 9 as value blocks.

You will learn

  • block writes · ACK / NAK
  • read-back checks
  • value block format
  • INCREMENT · DECREMENT · TRANSFER
  • backup blocks
  • guard rails
uv run pio run -d labs/rfid-lab-r5 -e rfid-lab-r5 -t upload
Open this lab's code on GitHubesp-labs / labs / rfid-lab-r5 (opens in a new tab)

Parts required

Parts library
  • ESP32-S3-DevKitC-1 + USB-C data cable
  • 1.9″ ST7789 screen
  • RC522 card reader
  • MIFARE card and key fob

A value block, byte by byte

How the card stores a number so that it can check it itself. Change the value and watch which bytes move.

Interactive MIFARE Classic value-block calculator demonstrating signed 32-bit counters and increment/decrement/transfer commands. How the card stores a number so that it can check it itself. Change the value and watch which bytes move.

  • Key concepts: block writes · ACK / NAK, read-back checks, value block format, INCREMENT · DECREMENT · TRANSFER, backup blocks, guard rails.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

credits use 3, step by step

The four card commands behind one credits use 3.

ISO14443-A handshake sequence showing REQA/WUPA, ATQA, anticollision cascade, and SAK responses. The four card commands behind one credits use 3.

  • Key concepts: block writes · ACK / NAK, read-back checks, value block format, INCREMENT · DECREMENT · TRANSFER, backup blocks, guard rails.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).
  • Walkthrough flows: credits.

Interactive diagram loads after page initialization.

What the screen shows

The board's screen has six views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses card polling. Pick a view to see what each part means; the numbers match the list below it.

Gallery of ST7789 display screens rendered during the RC522 RFID labs. The board's screen has six views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses card polling. Pick a view to see what each part means; the numbers match the list below it.

  • Key concepts: block writes · ACK / NAK, read-back checks, value block format, INCREMENT · DECREMENT · TRANSFER, backup blocks, guard rails.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

Commands, in order

Type these in the serial monitor (uv run pio device monitor) unless the grey tag says otherwise. The coloured tag says what should be near the board while it runs.

  1. uv run pio run -d labs/rfid-lab-r5 -e rfid-lab-r5 -t uploadMac terminalcard: doesn't matter
    Does
    Flashes lab R5's own firmware: everything from R4, plus the credits view, write and credits. help lists exactly this lab's commands.
    You should see
    rfid-lab-r5: reader task started, then this lab's command list and views.
    If not
    “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
  2. write 4 hello benchserial monitorcard on the reader
    Does
    Opens sector 1, checks its access bits allow key A writes, writes 16 bytes (text padded with zeros), reads them back.
    You should see
    Block 4's bytes, |hello bench.....| and written and read back.
    If not
    READ BACK DIFFERS: the card moved mid-write; run it again.
  3. write 3 testserial monitorcard: doesn't matter
    Does
    Tries to write a sector trailer.
    You should see
    Refused before anything is sent: not writable here (block 0 and trailers are off limits).
  4. credits init 50serial monitorcard on the reader
    Does
    Writes 50 as a value block into block 8 and the same into the backup, block 9.
    You should see
    The credits view: 50, backup 50, a coin stack.
  5. credits use 3 (then credits add 10)serial monitorcard on the reader
    Does
    Copies the value into the backup, then the card subtracts (or adds) and commits with TRANSFER.
    You should see
    47, backup 50; then 57, backup 47.
    If not
    no credits on this card yet: run credits init first.
  6. credits use 999serial monitorcard on the reader
    Does
    The firmware checks the balance first.
    You should see
    only 57 credits, can't use 999: nothing is sent to the card.
  7. creditsserial monitorcard on the reader
    Does
    Reads blocks 8 and 9 and decodes them.
    You should see
    The current value and the backup.

Steps

0 of 6 ticked. Ticks are saved in this browser.

Credits on a MIFARE Classic are a learning toy, not money: anyone with the key can rewrite the block. Payment and transit systems use cards with modern cryptography (such as MIFARE DESFire) and check every transaction on a server.

Preview: what you should see

Interactive RC522 13.56 MHz RFID reader simulator showing tag detection, VersionReg 0x92, UIDs, and serial monitor logs.

  • Key concepts: block writes · ACK / NAK, read-back checks, value block format, INCREMENT · DECREMENT · TRANSFER, backup blocks, guard rails.
  • Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).

Interactive diagram loads after page initialization.

ESP32-S3 peripherals used in this lab

Open interactive GPIO pinout

Explore the hardware blocks, pin rules, and registers behind this experiment.

  • GPIO and IO MUX

    45 pins, and a matrix that routes almost any signal to almost any pin

  • SPI

    Fast four-wire bus for screens, card readers and flash

  • UART

    Three serial ports, the one you see in the serial monitor

  • CPU

    Two Xtensa LX7 cores at up to 240 MHz

  • SRAM

    512 KB of fast on-chip RAM for your code and data

  • ROM

    384 KB of factory code: the bootloader and download mode

Troubleshooting & hardware gotchas

See all 17 ESP32-S3 hardware gotchas
What if it does not work or behaves unexpectedly?
Credits on a MIFARE Classic are a learning toy, not money: anyone with the key can rewrite the block. Payment and transit systems use cards with modern cryptography (such as MIFARE DESFire) and check every transaction on a server.
If “uv run pio run -d labs/rfid-lab-r5 -e rfid-lab-r5 -t upload” does not work
“Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
If “write 4 hello bench” does not work
READ BACK DIFFERS: the card moved mid-write; run it again.
If “credits use 3 (then credits add 10)” does not work
no credits on this card yet: run credits init first.
Four pins are read at reset
GPIO0, GPIO3, GPIO45 and GPIO46 are sampled the moment the chip comes out of reset: they pick the boot mode, the flash voltage, the ROM log and the JTAG source. Anything wired to them must not pull them the wrong way at power-up. After reset they are normal pins again.
GPIO3 has no pull resistor at reset
GPIO0 has a weak pull-up and GPIO45/46 weak pull-downs, but GPIO3 floats. When the eFuses make it choose the JTAG source, an outside circuit has to hold it at a clear level.
GPIO47 and 48 run at 1.8 V on R16V modules
Modules with the ESP32-S3R16V chip set the flash voltage to 1.8 V, and GPIO47/48 share that supply. A 3.3 V part on those pins sees the wrong levels.
The pins are not 5 V tolerant
A high input may go up to the pin's supply plus 0.3 V, so about 3.6 V on a 3.3 V board, and the power pins are rated to 3.6 V at most. 5 V from a sensor or an Arduino can damage the chip: use a level shifter or a divider.