micropython-oled - gen.py missing

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
PNZ20
Posts: 4
Joined: Tue Mar 16, 2021 10:16 am

micropython-oled - gen.py missing

Post by PNZ20 » Thu Mar 18, 2021 10:11 pm

Hello dears,
has anyone ever used the micropython-oled modules?

I cannot manage to generate a custom font via the script to execute on the desktop.
https://micropython-oled.readthedocs.io ... ustom-font

I have installed

Code: Select all

pip3 install micropython-oled
pip3 install pygame
on my desktop as described, but the result that I get is:

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/lib/oled/fonts/gen.py", line 224
SyntaxError: invalid syntax
looks like I miss the gen.py
How can I solve this?
I aim to create a font to display Awesome Font icons on my oled.
Here there is the Cheatsheet: https://fontawesome.com/cheatsheet
Thanks

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: micropython-oled - gen.py missing

Post by pythoncoder » Sat Mar 20, 2021 1:52 pm

Your starting point is to actually read and follow the instructions in the document you cite. Specifically, at the very start:

Code: Select all

import upip
upip.install("micropython-oled")
Then get his examples working first.
Peter Hinch
Index to my micropython libraries.

PNZ20
Posts: 4
Joined: Tue Mar 16, 2021 10:16 am

Re: micropython-oled - gen.py missing

Post by PNZ20 » Sun Mar 21, 2021 7:23 pm

@pythoncoder thank you very much for your reply and for your help
I missed to say that I can complete with success all the examples in the Getting Started section.
So I installed successfully "micropython-oled" via upip, as you stated.

My problem is only in the generation of the font.py file.

Since I have your attention, can you please help me solving this trouble?
The gen.py file in that package creates a font.py file with this format:

Code: Select all

_FONT = {
48: [8, 65535, 65535, 65535, 65535, 61455, 62415, 53235, 53235, 53235, 53235, 53235, 53235, 62415, 61455, 65535, 65535, 65535],
49: [8, 65535, 65535, 65535, 65535, 62463, 61503, 61455, 62463, 62463, 62463, 62463, 62463, 62463, 62463, 65535, 65535, 65535],
50: [8, 65535, 65535, 65535, 65535, 61455, 53187, 53247, 53247, 62463, 64767, 65343, 65487, 65523, 49155, 65535, 65535, 65535],
51: [8, 65535, 65535, 65535, 65535, 61455, 53235, 53247, 53247, 61503, 50175, 53247, 53247, 50163, 61455, 65535, 65535, 65535],
52: [8, 65535, 65535, 65535, 65535, 62463, 61695, 62271, 62415, 62415, 62451, 62460, 49152, 62463, 62463, 65535, 65535, 65535],
53: [8, 65535, 65535, 65535, 65535, 49155, 65523, 65523, 64515, 62463, 53247, 53247, 53247, 50163, 61455, 65535, 65535, 65535],
...
This is ubuntu_15.py font.

For the icons, in the description of the package, there is another example:

Code: Select all

_FONT = {
    'battery-empty': [20, 1099511627775, 1099511627775, 1099511627775, 824633720832, 824633720832, 17179869168, 17179869168, 68719476720, 68719476720, 17179869168, 17179869168, 824633720832, 824633720832, 1099511627775],
}
This kind of file is very different from a font python file generated with another tool that I have found online
(micropython font to file https://github.com/peterhinch/micropython-font-to-py)
which is similar to this:

Code: Select all

# Code generated by font-to-py.py.
# Font: Courier Prime.ttf
version = '0.2'

def height():
    return 20

def max_width():
    return 14

def hmap():
    return True

def reverse():
    return False

def monospaced():
    return True

def min_ch():
    return 32

def max_ch():
    return 126

_font =\
b'\x0e\x00\x00\x00\x00\x00\x7c\x00\xfe\x00\xc7\x00\xc3\x00\x03\x00'\
b'\x07\x00\x1e\x00\x18\x00\x18\x00\x18\x00\x3c\x00\x3c\x00\x18\x00'\
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00'\
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
b'\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x60\x00\x60\x00\x60\x00'\
b'\x60\x00\x60\x00\x60\x00\x60\x00\x60\x00\x00\x00\x60\x00\xf0\x00'\
b'\xf0\x00\x60\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00'\
b'\x00\x00\x00\x00\xe6\x00\xe6\x00\x66\x00\x66\x00\x66\x00\x66\x00'\
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\
b'\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x03\x30\x02\x20'\
...
I am aiming to obtain a string like this:
48: [8, 65535, 65535, 65535, 65535, 61455, 62415, 53235, 53235, 53235, 53235, 53235, 53235, 62415, 61455, 65535, 65535, 65535],
which looks very different from this
b'\x0e\x00\x00\x00\x00\x00\x7c\x00\xfe\x00\xc7\x00\xc3\x00\x03\x00'\

I imagine that these are both two methods for draw pixels on the OLED but I cannot generate the first (via gen.py or anything else, since I don't know what to search for), and I cannot manage easily the second (I am not able to input a unicode character with the awesome font and to obtaining his font.py file), so I am stucked.

Every help is very appreciated.
Thank you very much

Post Reply