Getting my daily news from a dot matrix printer 2024

To reduce screen time and improve mental health, a developer built a system using a vintage dot matrix printer and Raspberry Pi to print a custom daily news summary.
For a while now I've started my day by unlocking my phone and scrolling through different news and social media sites to see what's going on. It's not exactly great for my mental health and I've been trying to cut down on screen time for a while. I still want to stay up-to-date though, especially after I get up in the morning.
I recently purchased a dot matrix printer from eBay, and thought it would be a great excuse to have a custom "front page" printed out and ready for me each day. So, that's what I built!
I'll take this article to dive in and show you what I used, how I set it up, and the PHP script that powers it all.
Purchasing the hardware
The supply list for this project was pretty small, and with the exception of the printer, most of this can be found on Amazon or other online retailers. The printer I purchased was a Star NP-10 from what looks like the mid-80's. Any dot matrix printer with a serial port should do the trick. I was able to get this one for a low price because it was marked as "unsure if working".
It did need a little cleaning up and some tuning of the ink ribbon cartridge, but after that it fired right up. I hooked everything up: the Raspberry Pi is connected to my WiFi, and then via USB to the serial port of the printer. I verified that the printer is available at /dev/usb/lp0.
Figuring out the printer's code
Because the printer is available at lp0, I wanted to see if I could just echo raw text to it. After fixing some permissions issues with chmod 666 /dev/usb/lp0, I saw the text available on the printer!
I used PHP to write a basic script that accesses the file through fopen(). I quickly found out that there's not as much character support on the printer as I was sending. After digging through an old manual, I found this printer has a very specific character set based off of the IBM PC's Code Page 437. Sending these characters is straightforward by echoing out hex values with PHP.
Gathering the data
I wanted four distinct sections: weather, stocks, major news headlines, and a few top reddit posts. I used several free APIs:
- Open-Meteo for weather.
- Twelve Data for stocks.
- NYTimes for news headlines.
- Reddit JSON for social posts.
For each section, I wrote PHP code to pull the payload and compile the data into a larger array.
Printing out my front page
I wanted a bit of flair, so I decided to have a box at the top displaying the current date and my front page name. Since the page width is 80 characters, I used str_repeat and hex values to create borders.
To prevent the printer from cutting words in half at the end of a line, I implemented a splitString function to handle line length and return an array of lines with a max length corresponding to the page width. Now, I can start my day with a physical copy of the news instead of staring at a screen.
Source: Hacker News
















