I wrote my own code based upon the scrolling-text.py code.
I left my code running for about 20 mins and it failed with :-
free(): invalid pointer Aborted
No stacktrace or anything. So naturally I assumed I was doing something wrong. I’m not python expert for sure, so thought that was most likely. Btw, I was using python3.
In the scrolling-text.py example, an image and draw are created. Then the draw is updated and displayed over and over again. Which is what I was doing as I had a static part to my image and a smaller part I could update quickly. As this caused the error, I changed the code to create a new draw object every time around and that still failed.
So I removed 1 line. The disp.display(). So not updating the display. This time, it didn’t fail. So, I thought the issue is somewhere in the driver (or the demo code).
So I went back to the scrolling-text.py code and added a simple counter, so I know if it failed, how many times around the loop it was going. For my program it always failed after 37278 updates.
Amazingly, so did scrolling-text.py :-
pi@pi4-2:~/st7789-python/examples $ python3 scrolling-text.py count 37278free(): invalid pointer Aborted
It takes it about 25 minutes before it failed on my pi 4 with the default spi speed of 80mhz. Slightly quicker if you increase it 100mhz. Either way its always at 37278.
So I decided to run it using python 2. It still failed, but with a different error :-
pi@pi4-2:~/st7789-python/examples $ python scrolling-text.py 37279 Traceback (most recent call last): File "scrolling-text.py", line 50, in <module> draw.text((int(text_x - x), text_y), MESSAGE, font=font, fill=(255, 255, 255)) File "/usr/lib/python2.7/dist-packages/PIL/ImageDraw.py", line 276, in text xy = xy + offset, xy + offset IndexError: tuple index out of range Segmentation fault
I decided to see if the gif.py had the same issue. Sadly it does, so its not specific to the calls to draw.text() that’s the issue as gif.py doesn’t do any of those :-
pi@pi4-2:~/st7789-python/examples $ python gif.py deployrainbows.gif gif.py - Display a gif on the LCD. If you're using Breakout Garden, plug the 1.3" LCD (SPI) breakout into the front slot. Loading gif: deployrainbows.gif... Drawing gif, press Ctrl+C to exit! 37277Segmentation fault
I did adapt it to display a loop counter again, but no other changes. I even ran scrolling-text.py with the unmodified code and it still failed :-
python scrolling-text.py # Segmentation fault
Any ideas what’s wrong? Is it the code or the driver?
I did spot one typing mistake in all the example code. Its in a comment however, but someone could following it and get misled by it :-
# Create ST7789 LCD display class. disp = ST7789.ST7789( port=0, cs=ST7789.BG_SPI_CS_FRONT, # BG_SPI_CSB_BACK or BG_SPI_CS_FRONT dc=9, backlight=19, # 18 for back BG slot, 19 for front BG slot. spi_speed_hz=80 * 1000 * 1000 )
The comment ‘BG_SPI_CSB_BACK or BG_SPI_CS_FRONT’ should be ‘BG_SPI_CS_BACK or BG_SPI_CS_FRONT’.
It’s not BG_SPI_CSB_BACK, but BG_SPI_CS_BACK. But obviously that’s not the cause of the problems.