Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Post Reply
Posts: 2
Joined: Sun Mar 25, 2018 10:03 am


Post by Lepeshka » Sun Mar 25, 2018 3:11 pm

TelegaGraph prints messages from Telegram Bot on a thermal printer only with ESP8266.

It is only the first version. The code is not the best, but I would like to have something to work. Used board Wemos D1 mini firmware Micropython v.1.9.3

I wrote a basic library for working with bot api Telegram. It can only send and receive messages. At the moment, sending of the message is very limited, in view of the need to complete the URL character encoding function.

For the thermal printer was also written a library, which implements only a small functionality. This library also requires improvements. For example, you need to add a function that will turn the printer into low-energy mode so that it does not discharge the battery so quickly.

To connect the printer to the microcontroller, UART1 was used, which is located on GPIO2 (D4). This UART, as I understand it, has only TX pins. I did not go to hell with UART0, because one-way transmission is enough for me. I sacrifice only the status functions of the printer, for example, I can not find out that the paper is over.


User avatar
Posts: 3214
Joined: Fri Jul 18, 2014 8:01 am
Location: UK

Re: TelegaGraph

Post by pythoncoder » Mon Mar 26, 2018 6:13 am

I like it :D I wonder if there's scope for saving power by switching off the DC supply to the printer until a message arrives?
Peter Hinch

Posts: 2
Joined: Sun Mar 25, 2018 10:03 am

Re: TelegaGraph

Post by Lepeshka » Mon Mar 26, 2018 8:24 am

pythoncoder wrote:
Mon Mar 26, 2018 6:13 am
I like it :D I wonder if there's scope for saving power by switching off the DC supply to the printer until a message arrives?
Printer can be put into energy-saving mode until arrival of a new message

Posts: 24
Joined: Wed Jan 10, 2018 8:19 pm
Location: Bulgaria

Re: TelegaGraph

Post by newb » Fri Feb 01, 2019 7:04 pm


I'm trying ti get this thermal printer working but I fail to get the right codepage conversion.
I think the key is converting the UTF-8 bytearray into a codepage the printer recognises. Here is a self-test printout showing the active codepage iso-8852-5 along with the charset table.
codepage.jpg (165.64 KiB) Viewed 108 times
I try to pass via uart.write() to the printer following string "АБВГ". As it's utf-8, I need to convert it to the printer active codepage. I'm trying with:

Code: Select all

bytes('АБВГ', 'ISO-8852-5')
and the result is "\xd0\x90\xd0\x91\xd0\x92\xd0\x93"

May be I'm using he docs in a wrong way? Here's the source: ... html#bytes

However if I manually find the bytes in the charset (see printout above):


and pass it to the printer on the UART, it prints the correct characters. This makes me think that the conversion function is wrong.
Any ideas why?

Posts: 5
Joined: Thu Sep 28, 2017 10:19 am

Re: TelegaGraph

Post by d4ß » Tue Feb 19, 2019 8:35 pm


is it possible to get a general usable
I would like to use it for communication with some simple sensors on a ESP8266 (NodeMCU) in the long term, but first it seems to make sense to just understand what is going one.
I have no clue what is happening in this part of

Code: Select all

    def update(self):
        url = self._url + '/getUpdates?timeout=30&limit=1&offset=' + \
            r = requests.get(url)
            jo = json.loads(r.text)
            return None

        if len(jo['result']) > 0:
            self.offset = jo['result'][0]['update_id'] + 1
            if 'message' in jo['result'][0]:
                if 'text' in jo['result'][0]['message']:
                    return (jo['result'][0]['message']['chat']['id'],
        return None

    def listen(self, handler):
        while True:
            message = self.update()
            if message:
Lepeshka's Code.

So removed it and its running (surprisingly) with a basic

Code: Select all

import api

telegram = api.TelegramBot('token')

telegram.send('ChatID','Send me Message')
But than I get a
TLS buffer overflow, record size: 5165 (+5)
ssl_handshake_status: -257
Error, which means there is not enough RAM, ok. But why.
How Lepeshka can run the thermal printer driver and the bot without running out of memory.
Maybe somebody can simplify Lepeshka's code to an understandable level.


Post Reply