There are free online tools available to convert your own images to .pbm - it’s best if your image size is already 128x64 pixels.
NOP. Every one I have tried causes the code to crash at line 249.
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
File "PiicoDev_SSD1306.py", line 249, in load_pbm
IndexError: bytearray index out of range
The PiicoDev Logo is 1080 bytes, all the converted files are 1034 bytes.
Please advise which converter will work.
Cheers
Jim
Edit: The image is 128 x 64 pixels, my image editor can save as .pbm and the size is 1034.
To me it looks like an error with the library.
Has anyone else had problems, if not can you advise what you did.
I found the problem. There are 3 readlines for the first few bytes of the tile.
The PiicoDev logo was created with GIMP which has itself identified in one of the lines.
Commenting out one readline it now works for files not created by GIMP.
It is the difference between a file size of 1080 and 1034 bytes.
Funny.
def load_pbm(self, filename, c):
with open(filename, 'rb') as f:
# f.readline()
f.readline()
f.readline()
data_piicodev = bytearray(f.read())
for byte in range(WIDTH // 8 * HEIGHT):
for bit in range(8):
if data_piicodev[byte] & 1 << bit != 0:
x_coordinate = ((8-bit) + (byte * 8)) % WIDTH
y_coordinate = byte * 8 // WIDTH
if x_coordinate < WIDTH and y_coordinate < HEIGHT:
self.pixel(x_coordinate, y_coordinate, c)
Regards
Jim
PiicoDev Logo
P4
# Created by GIMP version 2.10.28 PNM plug-in
128 64
I changed the PiicoDev OLED SSD1306 Display library to check the length of the second line and read a third line if it is greater than 15. (see below) Seemed to be the easiest way, could have checked for characters in the line, but …
This will allow for bitmaps with larger displays than 128x64, but it is hardly an issue in this case.
Both GIMP files and other .pbm files now display correctly.
Regards
Jim
def load_pbm(self, filename, c):
with open(filename, 'rb') as f:
f.readline()
line = f.readline()
if len(line) > 15:
f.readline()
data_piicodev = bytearray(f.read())
for byte in range(WIDTH // 8 * HEIGHT):
for bit in range(8):
if data_piicodev[byte] & 1 << bit != 0:
x_coordinate = ((8-bit) + (byte * 8)) % WIDTH
y_coordinate = byte * 8 // WIDTH
if x_coordinate < WIDTH and y_coordinate < HEIGHT:
self.pixel(x_coordinate, y_coordinate, c)