Closed fmentiplay closed 4 years ago
I tried your code and it displays 'Frank' properly and it printed the correct X measurement. I'm using an older generic ESP32 with no PSRAM. It's running today's version of MicroPython v1.10-54-g43a894fb4. Are you running the same version of MicroPython? Did you try other fonts? I got 48 for the X measurement. Did you get the same?
I would add a print statement after line 492 of the library in the draw_text() method to see if it is a width/height error. For example:
# Stop on error
if w == 0 or h == 0:
print('Invalid width {0} or height {1}'.format(w, h))
return
Thank you for your reply. I really appreciate you taking the time to help with my problem.
My version of Micropython is "esp32-20190125-v1.10.bin" My NodeMCU ESP32S development board does not have PSRAM. I did a check of free RAM.
micropython.mem_info() stack: 736 out of 15360 GC: total: 111168, used: 5136, free: 106032 No. of 1-blocks: 26, 2-blocks: 7, max blk sz: 264, max free sz: 6618
My x value was 63. I have tried several fonts.
I entered the print statement in ssd1351,py library in the draw_text() method as you suggested and run my script (demo_frank.py) and got the following output... "invalid width 0 or height 8" It looks like it is a font problem but in my code I said the font size was 5x8 fixed = XglcdFont('fonts/FixedFont5x8.c', 5, 8) Your suggestion of putting in the print statement seems to have found the problem. But I am not quite sure how to proceed from here. Could you please suggest a possible cause of action. In the meantime I will do some research. Once again I really appreciate your help. Regards Frank
I don't think the font is loading correctly. Try adding the following 2 lines in your code after loading FixedFont:
fixed = XglcdFont('fonts/FixedFont5x8.c', 5, 8)
import binascii
print(binascii.hexlify(fixed.letters))
You should get the following output:
0500000000000500005f000005000700070005147f147f1405242a7f2a1205231308646205364956205005000807030005001c224100050041221c00052a1c7f1c2a0508083e0808050080703000050808080808050000606000052010080402053e5149453e0500427f4000057249494946052141494d33051814127f10052745454539053c4a49493105412111090705364949493605464949291e050000140000050040340000050008142241051414141414050041221408050201590906053e415d594e057c1211127c057f49494936053e41414122057f4141413e057f49494941057f09090901053e41415173057f0808087f0500417f4100052040413f01057f08142241057f40404040057f021c027f057f0408107f053e4141413e057f09090906053e4151215e057f091929460526494949320503017f0103053f4040403f051f2040201f053f4038403f056314081463050304780403056159494d4305007f41414105020408102005004141417f050402010204054040404040050003070800052054547840057f2844443805384444442805384444287f0538545454180500087e09020518a4a49c78057f080404780500447d4000052040403d00057f102844000500417f4000057c04780478057c0804047805384444443805fc182424180518242418fc057c080404080548545454240504043f4424053c4040207c051c2040201c053c4030403c054428102844054c9090907c054464544c44050008364100050000770000050041360800050201020402053c2623263c
added lines as suggested. Got following output....
exec(open('./demo_frank.py').read(),globals()) spi started display started b'00000000000000000000000000000000000000000000000000000000000000000000' 61 w = 0 h = 8 Invalid width 0 or height 8 [0;32mI (9putEn: 0| OutEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m display off end of file
The w = 0 and h = 8 is because I added two print statements.
From the output it looks like you are right and the font is not loading correctly. I tried using Bally5x8.c font and Wendy7x8.c font and ArcadePix9x11.c font all with the same output.
I am using the uPyCraft IDE on a Windows 10. But I would not have thought that using the uPyCraft IDE would cause the font not to load. Not sure how to proceed. Once again thank you for all your help Regards frank
It might be an encoding issue. Try adding the following 3 print statements to the __load_xglcd_font() method in the xglcd_font.py file. Also add import binascii to the top of the file.
def __load_xglcd_font(self, path):
"""Load X-GLCD font data from text file.
Args:
path (string): Full path of font file.
"""
bytes_per_letter = self.bytes_per_letter
# Buffer to hold letter byte values
self.letters = bytearray(bytes_per_letter * self.letter_count)
mv = memoryview(self.letters)
offset = 0
with open(path, 'r') as f:
for line in f:
# Skip lines that do not start with hex values
line = line.strip()
print(line)
if len(line) == 0 or line[0:2] != '0x':
print('Skipped')
continue
# Remove comments
comment = line.find('//')
if comment != -1:
line = line[0:comment].strip()
# Remove trailing commas
if line.endswith(','):
line = line[0:len(line) - 1]
print(binascii.hexlify(bytearray(int(b, 16) for b in line.split(','))))
# Convert hex strings to bytearray and insert in to letters
mv[offset: offset + bytes_per_letter] = bytearray(
int(b, 16) for b in line.split(','))
offset += bytes_per_letter
The output should look like this:
// Generic 8 bit fixed width font Skipped // 5 x 8 pixels Skipped // Start at ASCII 32 Skipped
Skipped 0x05,0x00,0x00,0x00,0x00,0x00, // Code for char SPACE b'050000000000' 0x05,0x00,0x00,0x5f,0x00,0x00, // Code for char ! b'0500005f0000' 0x05,0x00,0x07,0x00,0x07,0x00, // Code for char " b'050007000700' 0x05,0x14,0x7f,0x14,0x7f,0x14, // Code for char # b'05147f147f14' 0x05,0x24,0x2a,0x7f,0x2a,0x12, // Code for char $ b'05242a7f2a12' 0x05,0x23,0x13,0x08,0x64,0x62, // Code for char % b'052313086462' 0x05,0x36,0x49,0x56,0x20,0x50, // Code for char & b'053649562050' 0x05,0x00,0x08,0x07,0x03,0x00, // Code for char ' b'050008070300' 0x05,0x00,0x1c,0x22,0x41,0x00, // Code for char ( b'05001c224100' 0x05,0x00,0x41,0x22,0x1c,0x00, // Code for char ) b'050041221c00' 0x05,0x2a,0x1c,0x7f,0x1c,0x2a, // Code for char * b'052a1c7f1c2a' 0x05,0x08,0x08,0x3e,0x08,0x08, // Code for char + b'0508083e0808' 0x05,0x00,0x80,0x70,0x30,0x00, // Code for char b'050080703000' 0x05,0x08,0x08,0x08,0x08,0x08, // Code for char - b'050808080808' 0x05,0x00,0x00,0x60,0x60,0x00, // Code for char . b'050000606000' 0x05,0x20,0x10,0x08,0x04,0x02, // Code for char / b'052010080402' 0x05,0x3e,0x51,0x49,0x45,0x3e, // Code for char 0 b'053e5149453e' 0x05,0x00,0x42,0x7f,0x40,0x00, // Code for char 1 b'0500427f4000' 0x05,0x72,0x49,0x49,0x49,0x46, // Code for char 2 b'057249494946' 0x05,0x21,0x41,0x49,0x4d,0x33, // Code for char 3 b'052141494d33' 0x05,0x18,0x14,0x12,0x7f,0x10, // Code for char 4 b'051814127f10' 0x05,0x27,0x45,0x45,0x45,0x39, // Code for char 5 b'052745454539' 0x05,0x3c,0x4a,0x49,0x49,0x31, // Code for char 6 b'053c4a494931' 0x05,0x41,0x21,0x11,0x09,0x07, // Code for char 7 b'054121110907' 0x05,0x36,0x49,0x49,0x49,0x36, // Code for char 8 b'053649494936' 0x05,0x46,0x49,0x49,0x29,0x1e, // Code for char 9 b'05464949291e' 0x05,0x00,0x00,0x14,0x00,0x00, // Code for char : b'050000140000' 0x05,0x00,0x40,0x34,0x00,0x00, // Code for char ; b'050040340000' 0x05,0x00,0x08,0x14,0x22,0x41, // Code for char < b'050008142241' 0x05,0x14,0x14,0x14,0x14,0x14, // Code for char = b'051414141414' 0x05,0x00,0x41,0x22,0x14,0x08, // Code for char > b'050041221408' 0x05,0x02,0x01,0x59,0x09,0x06, // Code for char ? b'050201590906' 0x05,0x3e,0x41,0x5d,0x59,0x4e, // Code for char @ b'053e415d594e' 0x05,0x7c,0x12,0x11,0x12,0x7c, // Code for char A b'057c1211127c' 0x05,0x7f,0x49,0x49,0x49,0x36, // Code for char B b'057f49494936' 0x05,0x3e,0x41,0x41,0x41,0x22, // Code for char C b'053e41414122' 0x05,0x7f,0x41,0x41,0x41,0x3e, // Code for char D b'057f4141413e' 0x05,0x7f,0x49,0x49,0x49,0x41, // Code for char E b'057f49494941' 0x05,0x7f,0x09,0x09,0x09,0x01, // Code for char F b'057f09090901' 0x05,0x3e,0x41,0x41,0x51,0x73, // Code for char G b'053e41415173' 0x05,0x7f,0x08,0x08,0x08,0x7f, // Code for char H b'057f0808087f' 0x05,0x00,0x41,0x7f,0x41,0x00, // Code for char I b'0500417f4100' 0x05,0x20,0x40,0x41,0x3f,0x01, // Code for char J b'052040413f01' 0x05,0x7f,0x08,0x14,0x22,0x41, // Code for char K b'057f08142241' 0x05,0x7f,0x40,0x40,0x40,0x40, // Code for char L b'057f40404040' 0x05,0x7f,0x02,0x1c,0x02,0x7f, // Code for char M b'057f021c027f' 0x05,0x7f,0x04,0x08,0x10,0x7f, // Code for char N b'057f0408107f' 0x05,0x3e,0x41,0x41,0x41,0x3e, // Code for char O b'053e4141413e' 0x05,0x7f,0x09,0x09,0x09,0x06, // Code for char P b'057f09090906' 0x05,0x3e,0x41,0x51,0x21,0x5e, // Code for char Q b'053e4151215e' 0x05,0x7f,0x09,0x19,0x29,0x46, // Code for char R b'057f09192946' 0x05,0x26,0x49,0x49,0x49,0x32, // Code for char S b'052649494932' 0x05,0x03,0x01,0x7f,0x01,0x03, // Code for char T b'0503017f0103' 0x05,0x3f,0x40,0x40,0x40,0x3f, // Code for char U b'053f4040403f' 0x05,0x1f,0x20,0x40,0x20,0x1f, // Code for char V b'051f2040201f' 0x05,0x3f,0x40,0x38,0x40,0x3f, // Code for char W b'053f4038403f' 0x05,0x63,0x14,0x08,0x14,0x63, // Code for char X b'056314081463' 0x05,0x03,0x04,0x78,0x04,0x03, // Code for char Y b'050304780403' 0x05,0x61,0x59,0x49,0x4d,0x43, // Code for char Z b'056159494d43' 0x05,0x00,0x7f,0x41,0x41,0x41, // Code for char [ b'05007f414141' 0x05,0x02,0x04,0x08,0x10,0x20, // Code for char BackSlash b'050204081020' 0x05,0x00,0x41,0x41,0x41,0x7f, // Code for char ] b'05004141417f' 0x05,0x04,0x02,0x01,0x02,0x04, // Code for char ^ b'050402010204' 0x05,0x40,0x40,0x40,0x40,0x40, // Code for char _ b'054040404040' 0x05,0x00,0x03,0x07,0x08,0x00, // Code for char ` b'050003070800' 0x05,0x20,0x54,0x54,0x78,0x40, // Code for char a b'052054547840' 0x05,0x7f,0x28,0x44,0x44,0x38, // Code for char b b'057f28444438' 0x05,0x38,0x44,0x44,0x44,0x28, // Code for char c b'053844444428' 0x05,0x38,0x44,0x44,0x28,0x7f, // Code for char d b'05384444287f' 0x05,0x38,0x54,0x54,0x54,0x18, // Code for char e b'053854545418' 0x05,0x00,0x08,0x7e,0x09,0x02, // Code for char f b'0500087e0902' 0x05,0x18,0xa4,0xa4,0x9c,0x78, // Code for char g b'0518a4a49c78' 0x05,0x7f,0x08,0x04,0x04,0x78, // Code for char h b'057f08040478' 0x05,0x00,0x44,0x7d,0x40,0x00, // Code for char i b'0500447d4000' 0x05,0x20,0x40,0x40,0x3d,0x00, // Code for char j b'052040403d00' 0x05,0x7f,0x10,0x28,0x44,0x00, // Code for char k b'057f10284400' 0x05,0x00,0x41,0x7f,0x40,0x00, // Code for char l b'0500417f4000' 0x05,0x7c,0x04,0x78,0x04,0x78, // Code for char m b'057c04780478' 0x05,0x7c,0x08,0x04,0x04,0x78, // Code for char n b'057c08040478' 0x05,0x38,0x44,0x44,0x44,0x38, // Code for char o b'053844444438' 0x05,0xfc,0x18,0x24,0x24,0x18, // Code for char p b'05fc18242418' 0x05,0x18,0x24,0x24,0x18,0xfc, // Code for char q b'0518242418fc' 0x05,0x7c,0x08,0x04,0x04,0x08, // Code for char r b'057c08040408' 0x05,0x48,0x54,0x54,0x54,0x24, // Code for char s b'054854545424' 0x05,0x04,0x04,0x3f,0x44,0x24, // Code for char t b'0504043f4424' 0x05,0x3c,0x40,0x40,0x20,0x7c, // Code for char u b'053c4040207c' 0x05,0x1c,0x20,0x40,0x20,0x1c, // Code for char v b'051c2040201c' 0x05,0x3c,0x40,0x30,0x40,0x3c, // Code for char w b'053c4030403c' 0x05,0x44,0x28,0x10,0x28,0x44, // Code for char x b'054428102844' 0x05,0x4c,0x90,0x90,0x90,0x7c, // Code for char y b'054c9090907c' 0x05,0x44,0x64,0x54,0x4c,0x44, // Code for char z b'054464544c44' 0x05,0x00,0x08,0x36,0x41,0x00, // Code for char { b'050008364100' 0x05,0x00,0x00,0x77,0x00,0x00, // Code for char | b'050000770000' 0x05,0x00,0x41,0x36,0x08,0x00, // Code for char } b'050041360800' 0x05,0x02,0x01,0x02,0x04,0x02, // Code for char ~ b'050201020402' 0x05,0x3c,0x26,0x23,0x26,0x3c, // Code for char DEL b'053c2623263c'
Hello
Added the import statement to xglcd_font.py library and added the 3 print statements as suggested to __load_xglcd_font() method.
Run demo_frank.py. Ouput was ....
exec(open('./demo_frank.py').read(),globals()) spi started display started // Generic 8,0x5f,0x00, a,0x1200,0x08,0x, f,0x1c05,0x08,0x0 0x05,0x3e,41,0x49,0x4d a,0x49,00x05,0x46,0b4,0x22L1,0x59,0x0,0x49,0x49,0Kf,0x49,0xf,0x08,0x08,5,0x7f,0x080x05,0x7f,05,0x3e,0x41,0har S 0x05,&or char V 0xM 1,0x59,0 BackSlash^5,0x00,0x038,0x44,0x44,^be,0x0,0x44,0x 0,0x41,0n 0x05,0x38,or char qbt 0x05,0x3b4,0x2x05,0x00,0} 0x05,L00000000000&00000000000000000000000L:j61 w = 0 h = 8 Invalid width 0 or height 8 [0;32mI (1KOutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 [0m display off end of file
This is nothing like the output you expected.
To test if the font file could be read, I did a simply...
f = open('fonts/FixedFont5x8.c', 'r') print(f.read())
and got following output.....
// Generic 8 bit fixed width font // 5 x 8 pixels // Start at ASCII 32
0x05,0x00,0x00,0x00,0x00,0x00, // Code for char SPACE 0x05,0x00,0x00,0x5f,0x00,0x00, // Code for char ! 0x05,0x00,0x07,0x00,0x07,0x00, // Code for char " 0x05,0x14,0x7f,0x14,0x7f,0x14, // Code for char # 0x05,0x24,0x2a,0x7f,0x2a,0x12, // Code for char $ 0x05,0x23,0x13,0x08,0x64,0x62, // Code for char % 0x05,0x36,0x49,0x56,0x20,0x50, // Code for char & 0x05,0x00,0x08,0x07,0x03,0x00, // Code for char ' 0x05,0x00,0x1c,0x22,0x41,0x00, // Code for char ( 0x05,0x00,0x41,0x22,0x1c,0x00, // Code for char ) 0x05,0x2a,0x1c,0x7f,0x1c,0x2a, // Code for char * 0x05,0x08,0x08,0x3e,0x08,0x08, // Code for char + 0x05,0x00,0x80,0x70,0x30,0x00, // Code for char 0x05,0x08,0x08,0x08,0x08,0x08, // Code for char - 0x05,0x00,0x00,0x60,0x60,0x00, // Code for char . 0x05,0x20,0x10,0x08,0x04,0x02, // Code for char / 0x05,0x3e,0x51,0x49,0x45,0x3e, // Code for char 0 0x05,0x00,0x42,0x7f,0x40,0x00, // Code for char 1 0x05,0x72,0x49,0x49,0x49,0x46, // Code for char 2 0x05,0x21,0x41,0x49,0x4d,0x33, // Code for char 3 0x05,0x18,0x14,0x12,0x7f,0x10, // Code for char 4 0x05,0x27,0x45,0x45,0x45,0x39, // Code for char 5 0x05,0x3c,0x4a,0x49,0x49,0x31, // Code for char 6 0x05,0x41,0x21,0x11,0x09,0x07, // Code for char 7 0x05,0x36,0x49,0x49,0x49,0x36, // Code for char 8 0x05,0x46,0x49,0x49,0x29,0x1e, // Code for char 9 0x05,0x00,0x00,0x14,0x00,0x00, // Code for char : 0x05,0x00,0x40,0x34,0x00,0x00, // Code for char ; 0x05,0x00,0x08,0x14,0x22,0x41, // Code for char < 0x05,0x14,0x14,0x14,0x14,0x14, // Code for char = 0x05,0x00,0x41,0x22,0x14,0x08, // Code for char > 0x05,0x02,0x01,0x59,0x09,0x06, // Code for char ? 0x05,0x3e,0x41,0x5d,0x59,0x4e, // Code for char @ 0x05,0x7c,0x12,0x11,0x12,0x7c, // Code for char A 0x05,0x7f,0x49,0x49,0x49,0x36, // Code for char B 0x05,0x3e,0x41,0x41,0x41,0x22, // Code for char C 0x05,0x7f,0x41,0x41,0x41,0x3e, // Code for char D 0x05,0x7f,0x49,0x49,0x49,0x41, // Code for char E 0x05,0x7f,0x09,0x09,0x09,0x01, // Code for char F 0x05,0x3e,0x41,0x41,0x51,0x73, // Code for char G 0x05,0x7f,0x08,0x08,0x08,0x7f, // Code for char H 0x05,0x00,0x41,0x7f,0x41,0x00, // Code for char I 0x05,0x20,0x40,0x41,0x3f,0x01, // Code for char J 0x05,0x7f,0x08,0x14,0x22,0x41, // Code for char K 0x05,0x7f,0x40,0x40,0x40,0x40, // Code for char L 0x05,0x7f,0x02,0x1c,0x02,0x7f, // Code for char M 0x05,0x7f,0x04,0x08,0x10,0x7f, // Code for char N 0x05,0x3e,0x41,0x41,0x41,0x3e, // Code for char O 0x05,0x7f,0x09,0x09,0x09,0x06, // Code for char P 0x05,0x3e,0x41,0x51,0x21,0x5e, // Code for char Q 0x05,0x7f,0x09,0x19,0x29,0x46, // Code for char R 0x05,0x26,0x49,0x49,0x49,0x32, // Code for char S 0x05,0x03,0x01,0x7f,0x01,0x03, // Code for char T 0x05,0x3f,0x40,0x40,0x40,0x3f, // Code for char U 0x05,0x1f,0x20,0x40,0x20,0x1f, // Code for char V 0x05,0x3f,0x40,0x38,0x40,0x3f, // Code for char W 0x05,0x63,0x14,0x08,0x14,0x63, // Code for char X 0x05,0x03,0x04,0x78,0x04,0x03, // Code for char Y 0x05,0x61,0x59,0x49,0x4d,0x43, // Code for char Z 0x05,0x00,0x7f,0x41,0x41,0x41, // Code for char [ 0x05,0x02,0x04,0x08,0x10,0x20, // Code for char BackSlash 0x05,0x00,0x41,0x41,0x41,0x7f, // Code for char ] 0x05,0x04,0x02,0x01,0x02,0x04, // Code for char ^ 0x05,0x40,0x40,0x40,0x40,0x40, // Code for char _ 0x05,0x00,0x03,0x07,0x08,0x00, // Code for char ` 0x05,0x20,0x54,0x54,0x78,0x40, // Code for char a 0x05,0x7f,0x28,0x44,0x44,0x38, // Code for char b 0x05,0x38,0x44,0x44,0x44,0x28, // Code for char c 0x05,0x38,0x44,0x44,0x28,0x7f, // Code for char d 0x05,0x38,0x54,0x54,0x54,0x18, // Code for char e 0x05,0x00,0x08,0x7e,0x09,0x02, // Code for char f 0x05,0x18,0xa4,0xa4,0x9c,0x78, // Code for char g 0x05,0x7f,0x08,0x04,0x04,0x78, // Code for char h 0x05,0x00,0x44,0x7d,0x40,0x00, // Code for char i 0x05,0x20,0x40,0x40,0x3d,0x00, // Code for char j 0x05,0x7f,0x10,0x28,0x44,0x00, // Code for char k 0x05,0x00,0x41,0x7f,0x40,0x00, // Code for char l 0x05,0x7c,0x04,0x78,0x04,0x78, // Code for char m 0x05,0x7c,0x08,0x04,0x04,0x78, // Code for char n 0x05,0x38,0x44,0x44,0x44,0x38, // Code for char o 0x05,0xfc,0x18,0x24,0x24,0x18, // Code for char p 0x05,0x18,0x24,0x24,0x18,0xfc, // Code for char q 0x05,0x7c,0x08,0x04,0x04,0x08, // Code for char r 0x05,0x48,0x54,0x54,0x54,0x24, // Code for char s 0x05,0x04,0x04,0x3f,0x44,0x24, // Code for char t 0x05,0x3c,0x40,0x40,0x20,0x7c, // Code for char u 0x05,0x1c,0x20,0x40,0x20,0x1c, // Code for char v 0x05,0x3c,0x40,0x30,0x40,0x3c, // Code for char w 0x05,0x44,0x28,0x10,0x28,0x44, // Code for char x 0x05,0x4c,0x90,0x90,0x90,0x7c, // Code for char y 0x05,0x44,0x64,0x54,0x4c,0x44, // Code for char z 0x05,0x00,0x08,0x36,0x41,0x00, // Code for char { 0x05,0x00,0x00,0x77,0x00,0x00, // Code for char | 0x05,0x00,0x41,0x36,0x08,0x00, // Code for char } 0x05,0x02,0x01,0x02,0x04,0x02, // Code for char ~ 0x05,0x3c,0x26,0x23,0x26,0x3c, // Code for char DEL
This indicates that the font file can be opened and read.
As mentioned the output from my script demo_frank.py is nothing like your expected output. So I am still not sure where the issue is.
Once again thanks for all your help Regards Frank
Looks like an encoding issue. What's your country? It's hard for me to troubleshoot encoding issues.
Try passing the encoding in the open command:
with open(path, 'r', encoding = 'UTF-8') as f:
Hello
I live in Australia. I tried adding the encoding = 'UTF-8' with the same negative result. Leave it with me and I will do some "pottering" around and do some more research. Please leave this issue open so I can report back hopefully with a positive result.
You have been extremely helpful. You have narrowed down the area of the problem. Please do not spend any more of your valuable time on this . I appreciate all your efforts
Kind Regards Frank Greetings from Down Under
Hello Thank you for a great OLED (ssd1351) library, examples and an excellent YouTube videos
I have a NodeMCU ESP32S development board. It has 4M Flash and 500KB of RAM It appears to have enough RAM to run the simple python script below. Before running the script I did a RAM memory check
An OLED 128x128 is connected to the NodeMCU ESP32S development board. I have wired then up as per your YouTube video and your website.
Using bits of code from your examples I wrote a simple demo py script Please see below.....
The script runs without any errors. But the text part is blank and no text is displayed. The pixel, cat, polygon, line and rectangle are all displayed on the OLED but the screen is blank for the time it should be displaying text. Could you please give me your thoughts why the text is not displaying Thanks in advance Frank