dhylands / python_lcd

Python based library for talking to character based LCDs.
MIT License
298 stars 116 forks source link

putchar() can’t display custom chars #43

Open CptDangerous opened 1 year ago

CptDangerous commented 1 year ago

I have an application which drives a 20x4 LCD display on a RPi Pico. I have 6 custom characters which I need to display occasionally. However, when I try to send a number between 0 & 5 via putchar() I get an error at line 147 in lcd_api.py

On investigation I had to modify the code at line 147 as follows:

original code:

self.hal_write_data(ord(char))

which I moded to:

if type(char) is int:
    self.hal_write_data(char)
else:
    self.hal_write_data(ord(char))

This successfully allowed the api to display my custom chars but I have no idea if it would break other applications.

I guess it would be possible to move the test for int to the calling code and call hal_write_data() if test returns True. That somehow offends my OCD and wouldn’t advance the LCD cursor. 😀

dhylands commented 1 year ago

Instead of calling putchar(3) (which passes an int) you could call putchar('\x03') which passes in a char. Or you could also do: putchar(chr(3))