Lessons and the learning game

Build receipt printer gadgets

A mini thermal receipt printer and one big arcade button on an Uno, from raw ESC/POS bytes to a daily brief you tear off every morning.

What you build

One circuit carries the whole course. Every lesson opens on the same wiring and changes only the sketch:

  • The printer: a thermal printer on SoftwareSerial at 19200 baud, its RX from pin 6 and its TX into pin 5, powered from its own 9 V supply. Its head is a row of 384 heaters; the paper darkens where it is heated.
  • The button: an arcade button on pin 2 and ground, read with INPUT_PULLUP and debounced.
  • The brain: an Arduino Uno.

How it works

Commands. Ordinary characters go into the printer's line, and a line feed (10) prints it. Commands start with a byte that is never text, ESC (0x1B) or GS (0x1D): ESC @ resets, ESC E 1 is bold, ESC a 1 centers, GS ! 0x11 doubles the size, ESC d n feeds n lines, and ESC v 0 asks for the status, whose bit 2 means the paper has run out. This family is ESC/POS, the language of most shop receipt printers.

Bitmaps. A picture for a print head is one bit per dot, eight dots to a byte, so a 16 x 16 icon is 32 bytes. The ESC/POS standard sends it with GS v 0 and its width and height; Adafruit's library uses DC2 *. Flipping every bit with ~ makes a negative.

Gadgets. The fortune button deals fortunes from a shuffled deck so none repeats before all have appeared. The to-do printer keeps up to eight items in a char array and prints a checklist. The photo booth turns brightness into characters from a ten-step ramp, " .:-=+*#%@", and prints a face 32 characters wide.

The daily brief puts it together: the day in big letters, a small weather picture made of characters, the to-do list and a fortune, from one press.

The course

Build receipt printer gadgets takes six lessons:

  1. Printer commands: ESC/POS bytes by hand, and the paper sensor.
  2. Text and bitmaps: one bit per dot, the raster header, and inverting.
  3. A fortune button: debouncing, tickets and a shuffled deck.
  4. A to-do printer: a list in a char array, printed as a checklist.
  5. A tiny photo booth of text: ASCII art, contrast and a negative.
  6. Project: a daily brief: the day, the weather, your list and a fortune.

Every step but the last is checked against the running circuit.