ST7735 with large fonts

Hi,
I got the new ST7735 library to work well. THe included font is rather small, and I like to use bigger fonts as well.
After testing, my impression is that larger fonts don’t work. More specifically, I think that fonts with character widths lager than 8 pixels (and thus two bytes for each line of the character) don’t work correctly.

Another remark: to make the library to work, I needed to make a small change in line 151 of st7735.py to make it look as below:
# list of configuration to set the rotation
rotation_settings = [
[ST7735_MAD_MX | ST7735_MAD_MY | ST7735_MAD_MH | ST7735_MAD_BGR, 26, 1, “”],
[ST7735_MAD_MV | ST7735_MAD_MY | ST7735_MAD_BGR, 0, 0, “”], # KV 201009 0,0 was 1, 26 en swap
[ST7735_MAD_BGR, 26, 1, “”],
[ST7735_MAD_MX | ST7735_MAD_MV | ST7735_MAD_BGR, 1, 26, “swap”]

Thanks @kverbeke for the note, We will look into it.

Hi Karim, just to easier demonstrate my point on the character widths > 8 pixels: using the font built in into the example, use a percentage sign “%”, and you’ll observe it isn’t shown correctly on the ST7735 display. The %-sign is the only character in the built-in font that has a width of 9 pixels.

If you look into the fonts.py file, you’ll observe line 109 which has twice the length of all others. This is the line of the percentage sign.

Hope this helps.
Best regards.

I fixed the issue by updating the function _write_c_to_buf. With the version below, character s of any width will be handled and displayed correctly. This means that even very large characters are displayed correctly.

Best regards.

def _write_c_to_buf(self, c):
    idx = 8 + ((ord(c) - self.first_char) << 2)
    c_width = self.font[idx]
    offset = self.font[idx+1] | (self.font[idx+2] << 8) | (self.font[idx+3] << 16)
    area = self.font_height*c_width
    self.c_buf = bytearray(area*2)
    cnt = 0
    x_count = 0
    mask = 1 
    while cnt < area:
        if mask == 1<<8:
            mask = 1
            offset += 1   
        if mask==1:
            byte = self.font[offset]
        if (byte & mask) != 0:
            colorprint = 1
            self.c_buf[cnt*2] = self.font_color[0]
            self.c_buf[(cnt*2) + 1] = self.font_color[1]
        else:
            colorprint = 0
            self.c_buf[cnt*2] = self.background[0]
            self.c_buf[(cnt*2) + 1] = self.background[1]
        mask = mask << 1

        cnt += 1
        x_count += 1
        if x_count == c_width:
            x_count = 0
            offset += 1
            mask=1
    return c_width