Printing with annex-Basic

Code tips and tricks for beginners
Post Reply
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Printing with annex-Basic

Post by RonS »

first a "Happy Easter" from Germany...

To complement my project "shopping list" i need of course also a possibility to print it out. The ESP32 is bloetooth-capable and annex-basic supports it well, it makes sense to use a bluetooth printer, I thought
I found the MPT-II on the "Ali". Is cheap - has a built-in battery and supports Bluetooth and USB´

On github I found some control codes and made a small test program out of them - so far I only found the code for normal text and bold text and of course the initialization sequence

Code: [Local Link Removed for Guests]

bluetooth.clear
BLUETOOTH.SETUP "ESP32_Device"
IOBUFF.DIM(1, 1000)  ' Puffer für Texte
NewOrder$=""
Art1$ = "Butter" : Art2$ = "Bread": Art3$="Onions" : Art4$="Milk" : Art5$ ="toilet paper" :Art6$="":Art7$ = "" : Art8$ = "": Art9$="" : Art10$="" : Art11$="":Art12$=""
NewOrder$=Art1$+chr$(10)+Art2$+chr$(10)+Art3$+chr$(10)+Art4$+chr$(10)+Art5$+chr$(10)+Art6$+chr$(10)+Art7$+chr$(10)+Art8$+chr$(10)+Art9$+chr$(10)
file.save "/DatenT/Orders.dat",NewOrder$
onbluetooth ble_receive
bluetooth.scan 5
pause 600
bluetooth.client "66:22:F5:FA:C9:36", "18f0", "2af1"
pause 250

wait

ble_receive:
pause 50
select case bluetooth.status
  case 1
    wlog "------> Verbunden!"
    
    ' --- Initialisierung (nur einmal!) ---
    iobuff.fromhex(1, "1B40")  ' ESC @ = Reset
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 100
    
    ' --- Fettdruck für ALLE folgenden Texte ---
   iobuff.fromhex(1, "1B4501")  ' ESC E 1 = Fett AN
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 50
    
    ' --- Texte drucken (mit Zeilenumbruch chr$(10)) ---
    text$ = "Hallo Drucker! Dies ist ein Test" + chr$(10)
    iobuff.fromstring(1, text$)
    bluetooth.clwrite_iobuff "2af1", (1)
    
    text2$ = "Und dies ist Zeile 2" + chr$(10)
    iobuff.fromstring(1, text2$)
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 50
      
    'iobuff.fromhex(1, "1B4500")  ' ESC E 1 = Fett aus
   ' bluetooth.clwrite_iobuff "2af1", (1)
    'pause 50
    text4$=file.read$("/DatenT/Orders.dat")
    rem text$ = "Hallo Drucker!Dies ist  Test 3 " + chr$(10)'prüfe  ausschalten fettdruck
    iobuff.fromstring(1, text4$)
    bluetooth.clwrite_iobuff "2af1", (1)
    
    
  case 2
    wlog "====== Verbindung getrennt- verbinde"
    bluetooth.client "66:22:F5:FA:C9:36", "18f0", "2af1"
pause 250
end select
return
Of course, it can be even better. Maybe I can find more control code, for example, to make a line feed .. If anyone has time and interests I am grateful for hints

Ron
DSCN1132.JPG
PS:https://github.com/bitbank2/Thermal_Printer/tree/master
You do not have the required permissions to view the files attached to this post.
Last edited by RonS on Mon Apr 21, 2025 10:16 am, edited 1 time in total.
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
Starraker
Posts: 116
Joined: Tue Sep 03, 2024 1:53 am
Location: Canberra Australia
Been thanked: 29 times
Contact:

Re: Printing with annex-Basic

Post by Starraker »

Ron,

Good to see you on the forum.

The Carriage Return (CR) character (0x0D, \r) moves the cursor to the beginning of the line without advancing to the next line.

The Line Feed (LF) character (0x0A, \n) moves the cursor down to the next line without returning to the beginning of the line.

The End of Line (EOL) sequence (0x0D 0x0A, \r\n) is actually two ASCII characters, a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line.

These are the historical values (from the days of typewriters). Perhaps you can give them a try. The \r and \n are abstractions used in certain programming languages.

How is your ESP32-8048S043C going?

All the very best,

Paul
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Re: Printing with annex-Basic

Post by RonS »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Mon Apr 21, 2025 9:17 am Ron,

Good to see you on the forum.

The Carriage Return (CR) character (0x0D, \r) moves the cursor to the beginning of the line without advancing to the next line.

The Line Feed (LF) character (0x0A, \n) moves the cursor down to the next line without returning to the beginning of the line.

The End of Line (EOL) sequence (0x0D 0x0A, \r\n) is actually two ASCII characters, a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line.

These are the historical values (from the days of typewriters). Perhaps you can give them a try. The \r and \n are abstractions used in certain programming languages.
hi Paul,
yes, that's also a way - but there are also certain control codes for this and to do other things - if you take a look at it on GitHub
How is your ESP32-8048S043C going?
the display is still stable, only when saving the sync slips a little bit away - but that's what I found the trick for... What does your display do with the new software version of CiccioCB ?
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
Starraker
Posts: 116
Joined: Tue Sep 03, 2024 1:53 am
Location: Canberra Australia
Been thanked: 29 times
Contact:

Re: Printing with annex-Basic

Post by Starraker »

Ron,

I am still waiting for the link from Francesco. I thought he must have been busy.

If you have it could you please send it privately.

Paul
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Re: Printing with annex-Basic

Post by RonS »

i've found a hint - so that my question about more control codes has been settled

quote from github

Code: [Local Link Removed for Guests]

even if the printer supports barcode printing, it probably doesn't support
// the complete list of code types defined by the ESC/POS printer commands.
// In the case of the GOOJPRT PT210/MTP-2, it only supports a small subset of 1D codes
:o Ron :o
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
comptebidouille
Posts: 22
Joined: Sun Nov 19, 2023 10:52 am
Has thanked: 37 times

Re: Printing with annex-Basic

Post by comptebidouille »

Hello ;) ,
I don't no why but it seems that my "vulgarity ticket distributor" (guess which movie i'm thinking about :D ) will be soon ready in my entryway :lol:
User avatar
Starraker
Posts: 116
Joined: Tue Sep 03, 2024 1:53 am
Location: Canberra Australia
Been thanked: 29 times
Contact:

Re: Printing with annex-Basic

Post by Starraker »

Ron,

I am glad that you found your answer - I was not looking forward to finding it on GitHub - I find it difficult navigating that site.

Paul
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Re: Printing with annex-Basic

Post by RonS »

So I teased out something else: double size is now possible and the line spacing is adjustable, bold and centered printing are now possible too
also linefeed at the end.. :)

good night Ron
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
cicciocb
Site Admin
Posts: 3135
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 635 times
Been thanked: 2234 times
Contact:

Re: Printing with annex-Basic

Post by cicciocb »

Very interesting, nice application.
👏
RonS
Posts: 238
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 111 times
Been thanked: 59 times

Re: Printing with annex-Basic

Post by RonS »

these are the new features . bold - centered - double size - the timing is critical (insert pause > 100) and the io buffer needs to be flushed if needed

Code: [Local Link Removed for Guests]

ble_receive:
pause 50
select case bluetooth.status
  case 1
    wlog "------> Verbunden!"
    
    ' --- Initialisierung (nur einmal!) ---
    iobuff.fromhex(1, "1B40")  ' ESC @ = Reset
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 100
    
    ' --- Fettdruck für ALLE folgenden Texte ---
   iobuff.fromhex(1, "1B4501")  ' ESC E 1 = Fett AN (bold on )
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 50
    
    ' --- Texte drucken (mit Zeilenumbruch chr$(10)) ---
    text$ = "Hallo Drucker! Dies ist ein Test" + chr$(10)
    iobuff.fromstring(1, text$)
    bluetooth.clwrite_iobuff "2af1", (1)
    
    text2$ = "Und dies ist Zeile 2" + chr$(10)
    iobuff.fromstring(1, text2$)
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 50
      
    iobuff.fromhex(1, "1B4500")  ' ESC E 1 = Fett aus ( bold off)
     bluetooth.clwrite_iobuff "2af1", (1)
     pause 50
    text4$=file.read$("/DatenT/Orders.dat")
    iobuff.fromstring(1, text4$)
    bluetooth.clwrite_iobuff "2af1", (1)
    pause 1000
    ' Doppelte Höhe/Breite funktioniert (double size )
       IOBUFF.fROMHEX(1, "1D2111")   '  "1D2110"=1,5 x |"1D2111"=2 x size
        BLUETOOTH.CLWRITE_IOBUFF "2af1", (1)
        pause 150

' --- Drucke Liste (fett & zentriert) ---
      IOBUFF.FROMHEX(1, "1B6101" + "1B4501")  ' Zentriert + Fett (bold and centered + double size)
      BLUETOOTH.CLWRITE_IOBUFF "2af1", (1)
      pause 250
      IOBUFF.FROMSTRING(3, "*** EINKAUFSLISTE ***" + CHR$(10))
      BLUETOOTH.CLWRITE_IOBUFF "2af1", (3)
      PAUSE 500
  case 2
    wlog "====== Verbindung getrennt- verbinde"
    bluetooth.client "66:22:F5:FA:C9:36", "18f0", "2af1"
    pause 50
    
pause 250
end select
return
According to the manual, the printer can also use Bar- code - for this something has to be switched I have not yet figured out how
The commandset is ESC/POS compatible according to the manual - but some things don't work but at least more than the first time
to use everything useful you have to construct a frame or a template with which you then print different files

Image

have a nice day Ron
PS. advanced informations :https://learn.microsoft.com/en-us/windo ... formatting + https://support.epson-europe.com/online ... 0300-00100
You do not have the required permissions to view the files attached to this post.
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
Post Reply