ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
Hello. Who can tell you where to get the ESP32 library for displays 1602, 2004 (I2C interface) with Russian letters (Cyrillic). By the link "https://github.com/dhylands/python_lcd " there is no library for ESP32 I2C, but there is for ESP8266. Will it work on ESP32?
Last edited by Tesla_X on Fri Dec 17, 2021 7:00 am, edited 4 times in total.
Re: ESP32 library for displays 1602, 2004 (I2C interface) with Russian letters (Cyrillic)
I would expect that it would run on a ESP32. GPIO assignment will probably need looking at, as some pins are reserved for other functions on each device.
Re: ESP32 library for displays 1602, 2004 (I2C interface) with Russian letters (Cyrillic)
I checked on ESP 32 - it works. Tested the library on the MT-20S4M_en LCD display. The problem is that it does not display Russian letters. Judging by the symbol table (attached), there is an offset. How can I fix it?
https://github.com/dhylands/python_lcd/ ... en.LCD.pdf
https://github.com/dhylands/python_lcd/ ... en.LCD.pdf
Re: ESP32 library for displays 1602, 2004 (I2C interface) with Russian letters (Cyrillic)
I haven't really dealt with non-ASCII characters, but my understanding is that micropython strings are UTF8 encoded, and the LCD isn't. So you'll need to translate your strings from UTF8 to the codeset needed by the LCD.
Can you provide some examples of what you're trying to do, and elaborate on what exactly you mean by "there is an offset".
Can you provide some examples of what you're trying to do, and elaborate on what exactly you mean by "there is an offset".
Re: ESP32 library for displays 1602, 2004 (I2C interface) with Russian letters (Cyrillic)
Hello. I use the MT-20S4M_en LCD display. I attached the documentation above. In the first photo in the attachment, part of the code for displaying lines on the display. The second photo shows the output result. As you can see from the photo, the characters in the third and fourth lines do not correspond to the characters in the code. If you look at the symbol table on page 9 of the documentation for the display, you can see that there is a certain offset when comparing the symbols according to the table. Or the library processes 8 bits of a character, and you need 16. Tell me how can I fix it?




Re: ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
What's the output of the following?
Code: Select all
import binascii
print(binascii.hexlify("The string with your characters here"))
Re: ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
Code: Select all
>>> print(binascii.hexlify("Test string"))
b'5465737420737472696e67'
>>> print(binascii.hexlify("/n"))
b'2f6e'
>>> print(binascii.hexlify("Русские символы"))
b'd0a0d183d181d181d0bad0b8d0b520d181d0b8d0bcd0b2d0bed0bbd18b'
>>>
Re: ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
The hex data that you printed is the UTF-8 encoding of the string. The Cyrillic alphabet can be seen on this page: https://en.wikipedia.org/wiki/ISO/IEC_8859-5
If you iterate through each of the characters of the string character by character and subtract 864 from the unicode value, you'll see something like this: which produces this output:
You'll notice that the rightmost column corresponds to the index into the "Codepage layout"
I took a look at the docs for your LCD and it doesn't look like the characters map directly to the codepage, you'll need to create your own map. I would make a 256 entry lookup table, where you use (ord(ch) - 864) as the index into the table and the value is the value to send to the LCD.
For example, the first character looks like a capital P, and the only thing I see like that is the ASCII P at 0x50. So map[0xc0] would have the value 0x50. The backwards N appears on the LCD with a code of 0xb8, so map[0xd8] would equal 0xb8. Rather than use an actual array, I would probably using a 256 byte bytearray. This will take up less memory than a list.
You could also just treat the values 0x400 thru 0x45f specially, and subtract 0x400 (1024) from the ord(ch) and get a value from 0 thru 95. Then your map would only need the 96 values corresponds to values 0xA0 thru 0xFF on the Codelayout.
If you iterate through each of the characters of the string character by character and subtract 864 from the unicode value, you'll see something like this:
Code: Select all
import binascii
s = "Русские символы"
print(binascii.hexlify(s))
for ch in s:
if ord(ch) >= 864:
print(ch, hex(ord(ch)), hex(ord(ch) - 864))
else:
print(ch, hex(ord(ch)))
Code: Select all
b'd0a0d183d181d181d0bad0b8d0b520d181d0b8d0bcd0b2d0bed0bbd18b'
Р 0x420 0xc0
у 0x443 0xe3
с 0x441 0xe1
с 0x441 0xe1
к 0x43a 0xda
и 0x438 0xd8
е 0x435 0xd5
0x20
с 0x441 0xe1
и 0x438 0xd8
м 0x43c 0xdc
в 0x432 0xd2
о 0x43e 0xde
л 0x43b 0xdb
ы 0x44b 0xeb
I took a look at the docs for your LCD and it doesn't look like the characters map directly to the codepage, you'll need to create your own map. I would make a 256 entry lookup table, where you use (ord(ch) - 864) as the index into the table and the value is the value to send to the LCD.
For example, the first character looks like a capital P, and the only thing I see like that is the ASCII P at 0x50. So map[0xc0] would have the value 0x50. The backwards N appears on the LCD with a code of 0xb8, so map[0xd8] would equal 0xb8. Rather than use an actual array, I would probably using a 256 byte bytearray. This will take up less memory than a list.
You could also just treat the values 0x400 thru 0x45f specially, and subtract 0x400 (1024) from the ord(ch) and get a value from 0 thru 95. Then your map would only need the 96 values corresponds to values 0xA0 thru 0xFF on the Codelayout.
Re: ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
Thanks for the detailed explanation. I have no experience in drawing up bypass maps yet, and I can send symbols using the library specified above. You can write an example of a solution to my problem in the code applied to this library. In theory, there is a table of Russian characters sewn into the display, where each letter has a specific code. The library should read this code, find a match in the table and output the symbol.dhylands wrote: ↑Mon Dec 20, 2021 2:15 amThe hex data that you printed is the UTF-8 encoding of the string. The Cyrillic alphabet can be seen on this page: https://en.wikipedia.org/wiki/ISO/IEC_8859-5
If you iterate through each of the characters of the string character by character and subtract 864 from the unicode value, you'll see something like this:which produces this output:Code: Select all
import binascii s = "Русские символы" print(binascii.hexlify(s)) for ch in s: if ord(ch) >= 864: print(ch, hex(ord(ch)), hex(ord(ch) - 864)) else: print(ch, hex(ord(ch)))
You'll notice that the rightmost column corresponds to the index into the "Codepage layout"Code: Select all
b'd0a0d183d181d181d0bad0b8d0b520d181d0b8d0bcd0b2d0bed0bbd18b' Р 0x420 0xc0 у 0x443 0xe3 с 0x441 0xe1 с 0x441 0xe1 к 0x43a 0xda и 0x438 0xd8 е 0x435 0xd5 0x20 с 0x441 0xe1 и 0x438 0xd8 м 0x43c 0xdc в 0x432 0xd2 о 0x43e 0xde л 0x43b 0xdb ы 0x44b 0xeb
I took a look at the docs for your LCD and it doesn't look like the characters map directly to the codepage, you'll need to create your own map. I would make a 256 entry lookup table, where you use (ord(ch) - 864) as the index into the table and the value is the value to send to the LCD.
For example, the first character looks like a capital P, and the only thing I see like that is the ASCII P at 0x50. So map[0xc0] would have the value 0x50. The backwards N appears on the LCD with a code of 0xb8, so map[0xd8] would equal 0xb8. Rather than use an actual array, I would probably using a 256 byte bytearray. This will take up less memory than a list.
You could also just treat the values 0x400 thru 0x45f specially, and subtract 0x400 (1024) from the ord(ch) and get a value from 0 thru 95. Then your map would only need the 96 values corresponds to values 0xA0 thru 0xFF on the Codelayout.
Re: ESP32 library for displays 1602, 2004, MT-20S4M (I2C interface) with Russian letters (Cyrillic)
The mapping for Page 1 (Table 6, p.9 of the datasheet) is fairly straightforward, subtracting 848 from the Unicode character number:
But I don't know how easy it is to switch between character ROM pages. Page 0 is not so easy to work out
Code: Select all
LCD Python Unicode
Decimal Decimal Entity Letter Full Unicode Glyph Name
======= ======= ======= ====== ===============================
192 1040 U+0410 А CYRILLIC CAPITAL LETTER A
193 1041 U+0411 Б CYRILLIC CAPITAL LETTER BE
194 1042 U+0412 В CYRILLIC CAPITAL LETTER VE
195 1043 U+0413 Г CYRILLIC CAPITAL LETTER GHE
196 1044 U+0414 Д CYRILLIC CAPITAL LETTER DE
197 1045 U+0415 Е CYRILLIC CAPITAL LETTER IE
198 1046 U+0416 Ж CYRILLIC CAPITAL LETTER ZHE
199 1047 U+0417 З CYRILLIC CAPITAL LETTER ZE
200 1048 U+0418 И CYRILLIC CAPITAL LETTER I
201 1049 U+0419 Й CYRILLIC CAPITAL LETTER SHORT I
202 1050 U+041A К CYRILLIC CAPITAL LETTER KA
203 1051 U+041B Л CYRILLIC CAPITAL LETTER EL
204 1052 U+041C М CYRILLIC CAPITAL LETTER EM
205 1053 U+041D Н CYRILLIC CAPITAL LETTER EN
206 1054 U+041E О CYRILLIC CAPITAL LETTER O
207 1055 U+041F П CYRILLIC CAPITAL LETTER PE
208 1056 U+0420 Р CYRILLIC CAPITAL LETTER ER
209 1057 U+0421 С CYRILLIC CAPITAL LETTER ES
210 1058 U+0422 Т CYRILLIC CAPITAL LETTER TE
211 1059 U+0423 У CYRILLIC CAPITAL LETTER U
212 1060 U+0424 Ф CYRILLIC CAPITAL LETTER EF
213 1061 U+0425 Х CYRILLIC CAPITAL LETTER HA
214 1062 U+0426 Ц CYRILLIC CAPITAL LETTER TSE
215 1063 U+0427 Ч CYRILLIC CAPITAL LETTER CHE
216 1064 U+0428 Ш CYRILLIC CAPITAL LETTER SHA
217 1065 U+0429 Щ CYRILLIC CAPITAL LETTER SHCHA
218 1066 U+042A Ъ CYRILLIC CAPITAL LETTER HARD SIGN
219 1067 U+042B Ы CYRILLIC CAPITAL LETTER YERU
220 1068 U+042C Ь CYRILLIC CAPITAL LETTER SOFT SIGN
221 1069 U+042D Э CYRILLIC CAPITAL LETTER E
222 1070 U+042E Ю CYRILLIC CAPITAL LETTER YU
223 1071 U+042F Я CYRILLIC CAPITAL LETTER YA
224 1072 U+0430 а CYRILLIC SMALL LETTER A
225 1073 U+0431 б CYRILLIC SMALL LETTER BE
226 1074 U+0432 в CYRILLIC SMALL LETTER VE
227 1075 U+0433 г CYRILLIC SMALL LETTER GHE
228 1076 U+0434 д CYRILLIC SMALL LETTER DE
229 1077 U+0435 е CYRILLIC SMALL LETTER IE
230 1078 U+0436 ж CYRILLIC SMALL LETTER ZHE
231 1079 U+0437 з CYRILLIC SMALL LETTER ZE
232 1080 U+0438 и CYRILLIC SMALL LETTER I
233 1081 U+0439 й CYRILLIC SMALL LETTER SHORT I
234 1082 U+043A к CYRILLIC SMALL LETTER KA
235 1083 U+043B л CYRILLIC SMALL LETTER EL
236 1084 U+043C м CYRILLIC SMALL LETTER EM
237 1085 U+043D н CYRILLIC SMALL LETTER EN
238 1086 U+043E о CYRILLIC SMALL LETTER O
239 1087 U+043F п CYRILLIC SMALL LETTER PE
240 1088 U+0440 р CYRILLIC SMALL LETTER ER
241 1089 U+0441 с CYRILLIC SMALL LETTER ES
242 1090 U+0442 т CYRILLIC SMALL LETTER TE
243 1091 U+0443 у CYRILLIC SMALL LETTER U
244 1092 U+0444 ф CYRILLIC SMALL LETTER EF
245 1093 U+0445 х CYRILLIC SMALL LETTER HA
246 1094 U+0446 ц CYRILLIC SMALL LETTER TSE
247 1095 U+0447 ч CYRILLIC SMALL LETTER CHE
248 1096 U+0448 ш CYRILLIC SMALL LETTER SHA
249 1097 U+0449 щ CYRILLIC SMALL LETTER SHCHA
250 1098 U+044A ъ CYRILLIC SMALL LETTER HARD SIGN
251 1099 U+044B ы CYRILLIC SMALL LETTER YERU
252 1100 U+044C ь CYRILLIC SMALL LETTER SOFT SIGN
253 1101 U+044D э CYRILLIC SMALL LETTER E
254 1102 U+044E ю CYRILLIC SMALL LETTER YU
255 1103 U+044F я CYRILLIC SMALL LETTER YA