(WIP) Sitronix ST7735 TFT Display
(WIP) Sitronix ST7735 TFT Display
I have written a little driver for the st7735 displays and the HAL to control it: hosaka/micropython-st7735
The driver was tested on WiPy but should work on any other hardware, as long as the HAL functions are defined correctly. The code is fairly self explanatory but it's worth mentioning that the init() function in the tft.py HAL is written for the "Green Tab" type of display and is not included in the driver on purpose, as there are other version and thus the init should be left up to the user. I will eventually add other inits as examples, font and text support.
As some of the recent discussions cover the fact that there might be very little advantage to use const(), I might eventually replace some of them that used inside the driver only, with hardcoded values.
Any comments, suggestions or criticism are welcome!
The driver was tested on WiPy but should work on any other hardware, as long as the HAL functions are defined correctly. The code is fairly self explanatory but it's worth mentioning that the init() function in the tft.py HAL is written for the "Green Tab" type of display and is not included in the driver on purpose, as there are other version and thus the init should be left up to the user. I will eventually add other inits as examples, font and text support.
As some of the recent discussions cover the fact that there might be very little advantage to use const(), I might eventually replace some of them that used inside the driver only, with hardcoded values.
Any comments, suggestions or criticism are welcome!
Re: (WIP) Sitronix ST7735 TFT Display
Very much looking forward to trying this! I love the 7735 (cheapest full colour screen around). Out of curiosity, any more detail on this Font object you have for collating font information?
Re: (WIP) Sitronix ST7735 TFT Display
I have developed this on the WiPy and there might be problems using different boards that I would have to fix. Please use the github issues if you hit any! I also need to tidy up the code a little bit :)
The font is a dictionary defining individual characters (ASCII start/end). This font is then passed to the driver class for char/text drawing. I don't know if this is a good practice, but I took this model from other discussions on the forum I have seen before.
The font is a dictionary defining individual characters (ASCII start/end). This font is then passed to the driver class for char/text drawing. I don't know if this is a good practice, but I took this model from other discussions on the forum I have seen before.
Code: Select all
font = {
"width": 6,
"height": 8,
"start": 32,
"end": 127,
"data": bytearray([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x06, 0x5F, 0x06, 0x00,
0x00, 0x07, 0x03, 0x00, 0x07, 0x03,
0x00, 0x24, 0x7E, 0x24, 0x7E, 0x24,
0x00, 0x24, 0x2B, 0x6A, 0x12, 0x00,
0x00, 0x63, 0x13, 0x08, 0x64, 0x63,
0x00, 0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x00, 0x07, 0x03, 0x00, 0x00,
0x00, 0x00, 0x3E, 0x41, 0x00, 0x00,
0x00, 0x00, 0x41, 0x3E, 0x00, 0x00,
0x00, 0x08, 0x3E, 0x1C, 0x3E, 0x08,
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x00, 0xE0, 0x60, 0x00, 0x00,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,
0x00, 0x62, 0x51, 0x49, 0x49, 0x46,
0x00, 0x22, 0x49, 0x49, 0x49, 0x36,
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,
0x00, 0x2F, 0x49, 0x49, 0x49, 0x31,
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x6C, 0x6C, 0x00, 0x00,
0x00, 0x00, 0xEC, 0x6C, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,
0x00, 0x24, 0x24, 0x24, 0x24, 0x24,
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,
0x00, 0x02, 0x01, 0x59, 0x09, 0x06,
0x00, 0x3E, 0x41, 0x5D, 0x55, 0x1E,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,
0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,
0x00, 0x30, 0x40, 0x40, 0x40, 0x3F,
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,
0x00, 0x7F, 0x02, 0x04, 0x02, 0x7F,
0x00, 0x7F, 0x02, 0x04, 0x08, 0x7F,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,
0x00, 0x7F, 0x09, 0x09, 0x19, 0x66,
0x00, 0x26, 0x49, 0x49, 0x49, 0x32,
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,
0x00, 0x3F, 0x40, 0x3C, 0x40, 0x3F,
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,
0x00, 0x71, 0x49, 0x45, 0x43, 0x00,
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,
0x00, 0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,
0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x03, 0x07, 0x00, 0x00,
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,
0x00, 0x7F, 0x44, 0x44, 0x44, 0x38,
0x00, 0x38, 0x44, 0x44, 0x44, 0x28,
0x00, 0x38, 0x44, 0x44, 0x44, 0x7F,
0x00, 0x38, 0x54, 0x54, 0x54, 0x08,
0x00, 0x08, 0x7E, 0x09, 0x09, 0x00,
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,
0x00, 0x7F, 0x04, 0x04, 0x78, 0x00,
0x00, 0x00, 0x00, 0x7D, 0x40, 0x00,
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x00, 0x00, 0x7F, 0x40, 0x00,
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,
0x00, 0x7C, 0x04, 0x04, 0x78, 0x00,
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,
0x00, 0xFC, 0x44, 0x44, 0x44, 0x38,
0x00, 0x38, 0x44, 0x44, 0x44, 0xFC,
0x00, 0x44, 0x78, 0x44, 0x04, 0x08,
0x00, 0x08, 0x54, 0x54, 0x54, 0x20,
0x00, 0x04, 0x3E, 0x44, 0x24, 0x00,
0x00, 0x3C, 0x40, 0x20, 0x7C, 0x00,
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,
0x00, 0x3C, 0x60, 0x30, 0x60, 0x3C,
0x00, 0x6C, 0x10, 0x10, 0x6C, 0x00,
0x00, 0x9C, 0xA0, 0x60, 0x3C, 0x00,
0x00, 0x64, 0x54, 0x54, 0x4C, 0x00,
0x00, 0x08, 0x3E, 0x41, 0x41, 0x00,
0x00, 0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x00, 0x41, 0x41, 0x3E, 0x08,
0x00, 0x02, 0x01, 0x02, 0x01, 0x00,
0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C
])}
Re: (WIP) Sitronix ST7735 TFT Display
I wonder if you could use the font that is included in Micropython in the framebuffer extmod somehow. I use a hack to do it in my driver: https://bitbucket.org/thesheep/micropyt ... py-142:157
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: (WIP) Sitronix ST7735 TFT Display
Re fonts, these tend to use precious RAM. One solution is to store them in a dedicated Python file as bytes objects (not bytearrays as, being mutable, these have to exist in RAM). If the Python file is saved as frozen bytecode it uses virtually no RAM. The Python files can be created from other font file formats using a command line utility running in Python. Note that frozen bytecode exists on the Pyboard but is not yet implemented on the ESP8266.
Two variants of this approach have been used in the ePaper driver https://github.com/peterhinch/micropython-epaper and the SSD1963 TFT driver https://github.com/robert-hh/SSD1963-TF ... or-PyBoard.
Two variants of this approach have been used in the ePaper driver https://github.com/peterhinch/micropython-epaper and the SSD1963 TFT driver https://github.com/robert-hh/SSD1963-TF ... or-PyBoard.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: (WIP) Sitronix ST7735 TFT Display
Damien's PR2067 implements frozen bytecode on esp8266. As far as my test go, it works and all changes up to now can be merged with that PR version. I wonder why that PR is not merged yet with the main stream.
-
- Posts: 70
- Joined: Wed Oct 14, 2015 5:07 pm
Re: (WIP) Sitronix ST7735 TFT Display
Been trying to get the GHI N18 display running.
https://www.ghielectronics.com/catalog/product/425
I think its the same controller st7735, but I am a bit confused as to wether I should use pyb.SPI or machine.SPI and neither contain the write command only send. Has the api changed sometime.
Anyway not insurmountable but no success as yet.
https://www.ghielectronics.com/catalog/product/425
I think its the same controller st7735, but I am a bit confused as to wether I should use pyb.SPI or machine.SPI and neither contain the write command only send. Has the api changed sometime.
Anyway not insurmountable but no success as yet.
-
- Posts: 70
- Joined: Wed Oct 14, 2015 5:07 pm
Re: (WIP) Sitronix ST7735 TFT Display
does this method do something I don't understand.
Code: Select all
def power(self, state=None):
"""
Get/set display power.
"""
if state is None:
return self.power # ???
self.write_cmd(CMD_DISPON if state else CMD_DISPOFF)
self.power = state # ???
Re: (WIP) Sitronix ST7735 TFT Display
If called without parameters, returns the power state.Peter.Kenyon wrote:does this method do something I don't understand.
If called with a parameter, sets the power state to that, and calls DISPON/DISPOFF depending on it.
update: After an additional look, there is a bug in it -- it returns itself. Should probablu be "return self._power".
Re: (WIP) Sitronix ST7735 TFT Display
It should presumably also set self._power rather than self.power.
Calling self.power will replace the power function with the value passed in. And then if you try to call self.power again it will fail since it's no longer a function, but rather an int.
Calling self.power will replace the power function with the value passed in. And then if you try to call self.power again it will fail since it's no longer a function, but rather an int.