Thermal Printer Part 2: Adding AI and a Web Interface
At the end of Part 1, I had a working thermal printer. Images printed fast. The BLE protocol was figured out. Victory.
But it still required SSH-ing into a Raspberry Pi and running Python scripts manually.
Not exactly something I could hand to a friend and say “here, print something fun.”
The obvious next step
I wanted two things:
- Generate images with AI — type a prompt, get a weird little print
- A web interface — so anyone on my network could use it from their phone
The first part meant calling an image generation API. I went with Google’s Gemini — mostly because I already had an API key lying around.
The second part meant Flask. Simple, boring, perfect.
Just like Part 1, Claude Code did most of the heavy lifting here. I described what I wanted, and it wrote the Flask server, the HTML, the JavaScript — all of it. My job was mostly pointing it in the right direction and testing things on the actual printer.
The whole thing is embarrassingly simple
Here’s the basic flow:
- User opens a webpage on their phone
- Types something like “a cat wearing a tiny hat”
- Hits print
- Gemini generates the image
- The Pi processes it and sends it to the printer over BLE
- A grainy, slightly cursed cat-in-a-hat emerges from the printer
The web UI is maybe 50 lines of HTML. One text input. One button. A status message.
@app.route('/print', methods=['POST'])
def print_image():
prompt = request.get_json().get('prompt', '')
# Generate image with AI
generated_img = generate_image(prompt, API_KEY)
# Prepare and print
img = prepare_image(generated_img)
# ... send to printer over BLE
That’s really it.
The fun part
What makes this actually enjoyable isn’t the code — it’s what happens when you use it.
You type a prompt. You wait a few seconds. And then this tiny printer spits out something that looks like it came from a 1990s fax machine, except the content is completely unhinged because an AI generated it.
There’s something weirdly satisfying about holding a physical printout of something that didn’t exist 10 seconds ago.
My friends started requesting increasingly absurd prints. My personal favorite: “a programmer telling his manager it works on my machine.”
Each one took about 5-6 seconds. Type, wait, print. Repeat.
What I actually built
The server runs on the Pi. It listens on port 5000. Anyone on my home network can hit it from their browser.
export GOOGLE_API_KEY='your-key-here'
python3 web.py
That’s the entire deployment.
No Docker. No nginx. No SSL. Just a Flask app running on a Raspberry Pi connected to a $15 thermal printer.
Sometimes the best version of something is the simplest one that works.
What’s next
Honestly? Probably nothing.
This project is done in the way weekend projects are done — it works, it’s fun, and I’ve already moved on to thinking about something else.
But if I were to keep going:
- Add JBIG compression (the thing the Android app uses) for even faster prints
- Let people upload their own images instead of just generating them
- Make a little enclosure so the printer doesn’t just sit on my desk looking chaotic
For now though, I’m happy. I learned BLE. I reverse-engineered a cheap printer. I made something my friends can actually use.
That’s a good weekend.