(WIP) Sitronix ST7735 TFT Display
Re: (WIP) Sitronix ST7735 TFT Display
Tried to get this driver working on my esp8266-12e.
To solve memory problems during script compiling, I put the four .py files in the 'scripts' folder, so they are compiled at the time of the make.
However, I still get the error message:
>>> import run_TFT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "run_TFT.py", line 2, in <module>
File "tft.py", line 4, in <module>
MemoryError: memory allocation failed, allocating 72 bytes
This occurs even if I remove all the byte data from the fonts.py definition, so it's not that.
Any thoughts?
To solve memory problems during script compiling, I put the four .py files in the 'scripts' folder, so they are compiled at the time of the make.
However, I still get the error message:
>>> import run_TFT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "run_TFT.py", line 2, in <module>
File "tft.py", line 4, in <module>
MemoryError: memory allocation failed, allocating 72 bytes
This occurs even if I remove all the byte data from the fonts.py definition, so it's not that.
Any thoughts?
Re: (WIP) Sitronix ST7735 TFT Display
Generally speaking, 320×240×2 is a lot of bytes. Any driver that uses a memory buffer to make the changes, and then transfers that when you call ``show()`` will be strained for memory on the ESP8266. That's why I made my driver not use any buffer, but instead send all the drawing commands to the display immediately.
Re: (WIP) Sitronix ST7735 TFT Display
Hi Deshipu,
I just found your st7735 driver by accident, while looking up your ili9341 driver (search on these boards finds no reference to it).
I pre-compiled it, reflashed, and successfully imported it in upython on my esp, without any memory problems.
Do you have a use example?
SPI speed, options etc.?
I can only see the driver itself on your code pages.
Dalex
I just found your st7735 driver by accident, while looking up your ili9341 driver (search on these boards finds no reference to it).
I pre-compiled it, reflashed, and successfully imported it in upython on my esp, without any memory problems.
Do you have a use example?
SPI speed, options etc.?
I can only see the driver itself on your code pages.
Dalex
Re: (WIP) Sitronix ST7735 TFT Display
@dalex: On esp8266 files in the scripts folder are NOT compiled at the time of the make. They are just packed as source into flash. If you want to use pre-compiled code in flash, you have to use Damien's PR 2067. You may also use mpy-cross to compile code and put it into the files system, by using a modified make as detailed here: http://forum.micropython.org/viewtopic. ... zen#p11014.
You can use both methods in parallel.
You can use both methods in parallel.
Re: (WIP) Sitronix ST7735 TFT Display
Thanks Roberthh,
I will try both of these suggestions.
I will try both of these suggestions.
Re: (WIP) Sitronix ST7735 TFT Display
That driver is not ready. I wrote it by looking at the datasheet and drivers for Arduino, but I don't have an st7735 display to test it on -- I have it ordered and I will release the driver officially as soon as it arrives and I can test it.dalex wrote:Hi Deshipu,
I just found your st7735 driver by accident, while looking up your ili9341 driver (search on these boards finds no reference to it).
I pre-compiled it, reflashed, and successfully imported it in upython on my esp, without any memory problems.
Do you have a use example?
SPI speed, options etc.?
I can only see the driver itself on your code pages.
Dalex
As for how to use, it has exactly the same api as the ili9341 one, so this should work:
Code: Select all
>>> import st7735
>>> from machine import Pin, SPI
>>> spi = SPI(miso=Pin(12), mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
>>> display = st7735.ST7735(spi, cs=Pin(0), dc=Pin(5), rst=Pin(4))
>>> display.fill(0xf0fa)
>>> display.pixel(120, 160, 0)
Re: (WIP) Sitronix ST7735 TFT Display
Ok, fixed the memory problem by actually precompiling the code (thanks Roberthh).
Now I get an error, that I can't for the life of me work out.
>>> tft = TFT_GREEN(128, 160, spi, dc, cs, rst)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/david/esp-open-sdk/micropython/esp8266/scripts/tft.py", line 95, in __init__
File "/home/david/esp-open-sdk/micropython/esp8266/scripts/tft.py", line 25, in __init__
TypeError: function takes 5 positional arguments but 3 were given
Here is line 25 (at bottom of this snippet)
class TFT(ST7735):
def __init__(self, width, height, spi, dc, cs, rst, bl=None):
"""
SPI - SPI Bus (CLK/MOSI/MISO)
DC - RS/DC data/command flag
CS - Chip Select, enable communication
RST/RES - Reset
BL/Lite - Backlight control
"""
# self.tab = tab
self.spi = spi
self.dc = dc
self.cs = cs
self.rst = rst
self.bl = bl
# ST7735 init
super().__init__(width, height)
Here is line 95 (at bottom of this snippet)
class TFT_GREEN(TFT):
def __init__(self, width, height, spi, dc, cs, rst, bl=None):
super().__init__(width, height, spi, dc, cs, rst, bl)
So the ST7735 __init__ does expect 3 arguments (self,width,height).
The TFT __init__ expects more arguments, but only asks for the 3 in turn from the ST7735 __init__.
Now I'm not that familiar with OOP, but I guessing it can't be because the __init__ functions have the same name, because TFT.__init__ is not the same name as ST7735.__init__, and otherwise someone before me would have had this problem. But perhaps there's something about OOP conventions I don't know about. Also, I don't know where it gets the number 5 from anyway, instead of say, 7 (self, width, height, spi, dc, cs, rst)
Help!
Now I get an error, that I can't for the life of me work out.
>>> tft = TFT_GREEN(128, 160, spi, dc, cs, rst)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/david/esp-open-sdk/micropython/esp8266/scripts/tft.py", line 95, in __init__
File "/home/david/esp-open-sdk/micropython/esp8266/scripts/tft.py", line 25, in __init__
TypeError: function takes 5 positional arguments but 3 were given
Here is line 25 (at bottom of this snippet)
class TFT(ST7735):
def __init__(self, width, height, spi, dc, cs, rst, bl=None):
"""
SPI - SPI Bus (CLK/MOSI/MISO)
DC - RS/DC data/command flag
CS - Chip Select, enable communication
RST/RES - Reset
BL/Lite - Backlight control
"""
# self.tab = tab
self.spi = spi
self.dc = dc
self.cs = cs
self.rst = rst
self.bl = bl
# ST7735 init
super().__init__(width, height)
Here is line 95 (at bottom of this snippet)
class TFT_GREEN(TFT):
def __init__(self, width, height, spi, dc, cs, rst, bl=None):
super().__init__(width, height, spi, dc, cs, rst, bl)
So the ST7735 __init__ does expect 3 arguments (self,width,height).
The TFT __init__ expects more arguments, but only asks for the 3 in turn from the ST7735 __init__.
Now I'm not that familiar with OOP, but I guessing it can't be because the __init__ functions have the same name, because TFT.__init__ is not the same name as ST7735.__init__, and otherwise someone before me would have had this problem. But perhaps there's something about OOP conventions I don't know about. Also, I don't know where it gets the number 5 from anyway, instead of say, 7 (self, width, height, spi, dc, cs, rst)
Help!
Re: (WIP) Sitronix ST7735 TFT Display
This is really hard to read and figure out. Could you maybe link to the complete code you are running, preferably in some repository or gist, so that we can see the line numbers and correlate them with the exception you got?
Re: (WIP) Sitronix ST7735 TFT Display
Hi Deshipu,
The link to the git repository is in the first post of this thread.
The line numbers refer to lines in the tft.py file.
The only changes I have made are in the main.py, to get it to run on my esp8266-12e, basically some pin changes and the way spi is invoked:
------------
from machine import Pin, SPI
from tft import TFT_GREEN
# DC - RS/DC data/command flag
# CS - Chip Select, enable communication
# RST/RES - Reset
dc = Pin(12, Pin.OUT)
cs = Pin(14, Pin.OUT)
rst = Pin(16, Pin.OUT)
# SPI Bus (CLK/MOSI/MISO)
# check your port docs to see which Pins you can use
spi = SPI(baudrate=8000000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
# TFT object, this is ST7735R green tab version
tft = TFT_GREEN(128, 160, spi, dc, cs, rst)
# init TFT
tft.init()
# start using the driver
tft.clear(tft.rgbcolor(255, 0, 0))
--------------
Thanks,
Dalex.
The link to the git repository is in the first post of this thread.
The line numbers refer to lines in the tft.py file.
The only changes I have made are in the main.py, to get it to run on my esp8266-12e, basically some pin changes and the way spi is invoked:
------------
from machine import Pin, SPI
from tft import TFT_GREEN
# DC - RS/DC data/command flag
# CS - Chip Select, enable communication
# RST/RES - Reset
dc = Pin(12, Pin.OUT)
cs = Pin(14, Pin.OUT)
rst = Pin(16, Pin.OUT)
# SPI Bus (CLK/MOSI/MISO)
# check your port docs to see which Pins you can use
spi = SPI(baudrate=8000000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
# TFT object, this is ST7735R green tab version
tft = TFT_GREEN(128, 160, spi, dc, cs, rst)
# init TFT
tft.init()
# start using the driver
tft.clear(tft.rgbcolor(255, 0, 0))
--------------
Thanks,
Dalex.
Re: (WIP) Sitronix ST7735 TFT Display
So my display just arrived, and I was able to test my driver. After fixing some really silly mistakes, it now seems to work.
The code is at https://bitbucket.org/thesheep/micropyt ... /st7735.py
Example usage on the ESP8266:
For now it's slow with the software SPI, it will get much faster when the HSPI patch is merged.
The code is at https://bitbucket.org/thesheep/micropyt ... /st7735.py
Example usage on the ESP8266:
Code: Select all
>>> from machine import Pin, SPI
>>> import st7735
>>> spi = SPI(miso=Pin(12), mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))
>>> display = st7735.ST7735(128, 128, spi, Pin(2), Pin(4), Pin(5))
>>> display.fill(0x7521)
>>> display.pixel(64, 64, 0)