- C 95.2%
- Python 3.8%
- Assembly 0.6%
- CMake 0.3%
A bare `trace` armed a new recording, so asking for the state threw away the one just made. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| core | ||
| docs | ||
| host | ||
| p6dump | ||
| pico | ||
| tools | ||
| .gitignore | ||
| CLAUDE.md | ||
| CMakeLists.txt | ||
| README.md | ||
Parallel printer emulator
A Raspberry Pi Pico W or Pico 2 W that pretends to be a matrix printer. Plug it into the Centronics port of a computer, print as usual, and pick the resulting PDF up over WiFi.
Bauanleitung (deutsch): docs/bauanleitung.md – Teileliste, Verdrahtung mit D-Sub-25-Stecker für PC-kompatible Druckerports, Firmware, WLAN-Einrichtung.
- Centronics input — full hardware handshake (/STROBE, BUSY, /ACK, PE, SELECT, /ERROR, /INIT) implemented in PIO, so the host is held off properly instead of losing characters.
- Pluggable printer emulation — Epson FX-80 (9 wire), NEC Pinwriter P6 plus (24 wire) and Star NX-1020 (9 wire) are built in; a new personality is one file plus one line in the registry. The P6 plus prints with the fonts read out of its own character generator ROM: draft, Courier, Bold PS, ITC Souvenir, Times, Helvette and Prestige Elite, super- and subscripts, code page 437 and fifteen national character sets, and implements the documented command set: downloaded characters, justification, tab channels, repeat, high speed draft, triple width, the panel menu's settings and its hex dump. An emulated font card adds the LQMATRIX soft fonts (Prestige, sans serif, script, OCR-B, OCR-A). The NX-1020 prints with the fonts read out of its own font ROM: draft and the near letter quality faces Courier, Sanserif, Orator and Script, the IBM code pages with their box drawing characters and the italic character table.
- PDF output — one PDF per job, written straight into flash as the page is rasterised, so a long listing never has to fit in RAM.
- Matrix fonts — the characters are drawn dot by dot on the print head's own grid, with round overlapping dots, so the output looks like it came off the platen rather than out of a word processor.
- Serial console — WiFi is set up from any terminal program over the Pico's USB port; the console also switches printers and ejects pages.
- Graphics — the ESC/P bit image commands (ESC K/L/Y/Z, ESC *, ESC ^), 8, 9 and 24 wire modes, 60 to 360 dpi.
The emulation core is plain portable C with no Pico dependencies. The same code runs as a command line tool, which is how it is developed and tested.
Layout
| path | what |
|---|---|
core/ |
portable emulation core: parser, fonts, rasteriser, PDF writer |
core/fonts/ |
editable dot matrix font artwork (.pef), LQMATRIX 24 pin soft fonts, Star NX-1020 font ROM, NEC P6 plus character generator ROM |
host/ |
pe2pdf, the command line converter |
pico/ |
Pico W firmware: PIO Centronics, flash spool, web interface, serial console |
tools/ |
font generators, PDF page renderer, test page script, ROM and soft font viewers |
docs/ |
hardware, German build guide, building, architecture, supported commands, P6 and NX-1020 font sources |
The host tool
See docs/building.md for building the host tool and
the firmware from source. Once built, pe2pdf converts a captured printer
stream or prints the built in test page:
./build/pe2pdf --list
./build/pe2pdf -d fx80 -o listing.pdf capture.prn
./build/pe2pdf -d p6 --test-page -o testpage.pdf
./build/pe2pdf -d nx1020 -o listing.pdf capture.prn
./build/pe2pdf -d fx80 --bars green3 -o listing.pdf capture.prn
tools/testpages.sh renders the test page of every emulation, and any
capture, to PDF and PNG in one go - see
docs/building.md.
capture.prn is the raw byte stream the machine would have sent to its
printer - exactly what the firmware receives.
Firmware
Prebuilt images for the Raspberry Pi Pico W (pico_printer-pico_w.uf2) and
the Pico 2 W (pico_printer-pico2_w.uf2) are attached to each
release.
Hold BOOTSEL while plugging the Pico in and copy the image onto the drive
that appears. The pinout is in docs/hardware.md; building
from source is described in docs/building.md.
Setting up WiFi
Open the Pico's USB serial port in a terminal program (screen /dev/tty.usbmodem* 115200 on macOS, /dev/ttyACM0 on Linux, the COM port
in PuTTY on Windows; the baud rate does not matter) and press Enter:
> wifi
SSID (empty to cancel): mynetwork
password (empty for an open network): ************
wifi: connecting to "mynetwork"
>
wifi: connected, web interface at http://192.168.1.57/
The credentials are kept in flash and used on every start; a lost
connection is retried automatically. status shows the address of the web
interface at any time, log replays the recent console output (including
what happened at boot with no console attached), help lists the other
commands. The web page shows
what the printer is doing, switches the emulated printer, the size of the
dots and the paper - plain white or tractor feed forms with green, blue or
grey bars one or three lines high and numbered lines - and the printer's
own settings, as
its control panel menu has them (on the P6 plus the font card, power-up
style, character table, language set and more), as soon
as a choice is made, lists the stored jobs, ejects a page and prints a test
page. The console does the same with printer, dots, paper and set.
For a handshake problem at a remote site, "record trace" on the web page
(or trace start on the console) turns the Pico into a logic analyser: from the
next change on the port it records every change of the sixteen lines with
a microsecond timestamp, until two quiet seconds or 2048 changes (8192 on
the Pico 2 W). The web page then offers trace.bin, which
tools/porttrace.py lists as a table or converts to VCD for PulseView.
For debugging the parallel port, the web page keeps a live view of every
control line, the byte on the data bus and the number of bytes captured,
refreshed several times a second, and shows the console log below the job
list. The log records what happens on the port: the start of a transfer,
/INIT pulses, changes of /AUTOFEED, the first bytes of every job in hex,
why a job could not be started, and warnings when the handshake is stuck
(strobes without captured bytes, or BUSY held high while idle), and it
measures the width of every /STROBE pulse and how long the full capture
ring held the host off with BUSY. status on the console prints the same
line levels and counters; /status.json, /log.txt and /raw.bin (the
newest bytes captured) serve them to scripts. The console commands hold
and select exist for experiments with a host's handshake, see
docs/building.md.
How a job starts and ends
Old software rarely says "I am done": it just stops sending. The firmware therefore closes a job - ejects the page and finalises the PDF - after four seconds of silence, or immediately when the host pulses /INIT or you press eject page in the web interface. A form feed inside the stream starts a new page, not a new job.
Continuous integration
.forgejo/workflows/ci.yml builds the host tool, runs the tests, checks
that the generated font tables match their source and builds the firmware
for the Pico W and the Pico 2 W. A pushed v* tag publishes both images as
a release.
Adding a printer
See docs/adding-a-printer.md. The two built in drivers are caps tables around a shared ESC/P interpreter; a printer speaking a different language implements the same four callbacks and draws dots through the same engine.