❌

Reading view

There are new articles available, click to refresh the page.

Writing an ESP32 Bluetooth Printer Driver In Two Acts

[Bas BotBerg] wanted to use a portable Bluetooth thermal printer to run off reports on sensor data collected by an ESP32-C3 microcontroller. But as is so often the case these days, the only official way to interface with the printer was through a proprietary smartphone application provided by the manufacturer. With no documentation on how the thing works, he set out to reverse engineer the printer’s communications protocol so he could control it from the MCU β€” but the route he took to get there was a bit different than what we usually see, and is an excellent case study for those who might have similar projects in mind.

The standard procedure for something like this, if it can be called that, is to use Android’s built-in debugging capability to log Bluetooth communications while running the manufacturer’s application. The resulting file can be fed into Wireshark, and with patience and some educated guesses, you can usually work out the various commands and values that get passed to the hardware.

But in this case, [Bas BotBerg] ignored the manufacturer’s software and instead used an application that can query a device and list its Bluetooth Low Energy services and characteristics. Specifically, he looks for services that are marked as writable, and starts pushing data into them to see how the printer responds. For this he uses Python with the Bleak library, as it allows him to rapidly iterate and adapt his code. After a bit of poking and experimentation, he finds the proper incantation to get the printer’s motor to kick on an advance the paper β€” a critical first milestone that tells him he’s on the right path.

Once [Bas BotBerg] mapped out what data needed to be sent to what endpoints to operate the printer in Python, it was a relatively straightforward process to send those same payloads using C++ code on the ESP32. For extra style points he also brought in the Adafruit GFX library so he could produce icons and more easily format the output of the printer.

It doesn’t look like [Bas BotBerg] has released the code in this case (perhaps if we all ask nicely), but we’ve seen similar efforts to bring open source drivers to these cheap Bluetooth printers for the good of the community.

Doubling Thermal Printer Resolution by Wiggling

Insides of the Sears 12 calculator. (Credit: Danalog, YouTube)
Insides of the Sears 12 calculator. (Credit: Danalog, YouTube)

Thermal printers are still extremely common today, using small heating elements in combination with temperature-sensitive paper to create a dot matrix-like effect without messing with ink ribbons and complex mechanisms. Of course, even with just a line of elements you still needed one of these per pixel, which at least in the 1970s when the Sears 12 calculator was released added significantly to the cost. The solution here was to wiggle the elements, doubling the resolution of the print head, as detailed in this video by [Danalog].

Using a contemporary Texas Instruments TI-5015 calculator as comparison with its non-wiggling print head, it’s easy to see the advantages here. In an era where electronic calculators didn’t have displays but a thermal printer, this print quality was the selling point, yet adding more thermal elements added to the price tag of the final device and more complexity to the design in terms of driving circuitry.

In this regard adding a way to make the print head move side-to-side at a set rate and tying this fact into the printing would save about half of that circuitry. Inside the Sears 12 is a fairly standard Mitsubishi M58671 calculator IC, but also the whole printer mechanism. When operating, as demonstrated in the video with the cover removed, you can see the whole print head moving rapidly.

With this mechanism this much cheaper Sears 12 definitely gives the TI-5015 a run for its money, even if as noted by [Danalog] the timing would go off a bit after a longer session, resulting slightly wavy printing. Presumably with the massive cost savings of buying a Sears calculator over a TI one, this was deemed an acceptable trade-off.

❌