Skip to content

Python NFC model railroad

Motivation

Lets transport real bytes and gamify model railroading!

NFC Sticker

NFC sticker glued under the middle of the waggon

The NFC Sticker i use has the following specifications:

  • format: Ntag213
  • capacity: 144 bytes
  • procotol: ISO14443A
  • frequency: 13,56 MHZ
  • size: 11*21

It is small enough to be glued under the middle belly of a waggon, but sticking it onto the boogie should work too. The middle position is favorable in my opinion.

This way you always know where to position the waggon onto the reader independently of the direction.

Link to buy on: Aliexpress

Data structure

This is "text/json" json structure saved in the Ndef format on the sticker:

{
    "cargo_type": "steel",
    "cargo_max": "42",
    "cargo_amount": "0"
}

Use your smartphone

My Google Pixel 3a smartphone was very handy for debugging and understanding the NFC and Ndef tag after installing this app: NFC Tools from wakdev.

Reading

Here how the NFC data looks like in the "NFC Tools" app:

NFC Tools read NFC Tools read advanced

Writing

Writing any data to the sticker is also very easy. Here an example how i created the tags with the json data shown above.

NFC Tools read advanced NFC Tools read advanced NFC Tools read advanced NFC Tools read advanced

TODO:

  • check if it is possible to remove the quotes for the integers in json repr to save bytes. But i think writing without escaping the string was not possible, hmmmm ...

Display

I use a 2.4" diagonal LCD TFT display from wemos.cc It coomes with 320x240 pixels and uses an ILI9341 driver. Touchscreen capability is also available with the XPT2046 controller. Sadly it cannot be utilized with the raspberry pi display driver solution i use at the moment.

Some documentation:

Wiring