rm-hull / luma.examples

Companion repo for running examples against the luma.oled, luma.lcd, luma.led_matrix and luma.emulator display drivers.
MIT License
367 stars 140 forks source link

ST7735 goes black #142

Closed aparatowo closed 3 years ago

aparatowo commented 3 years ago

Hi, I'm struggling with this issue:

  1. I have a screen from WS (1,44" 128x128) based on st7735s driver
  2. It works with their crappy library
  3. I'm trying to write some texts and previously white screen goes black
  4. Screen goes white again after the script ends

No errors throwed.

I have no idea how to build my own script using Luma.

My way of initialisation:

frame_size = (128, 128)
spi_config = spi(port=0, device=0, gpio_DC=25, gpio_RST=27, bus_speed_hz=9000000, spi_mode=0b00)
display_device = st7735(spi_config, rotate=2, gpio_LIGHT=24, h_offset=1, v_offset=2)
display_device.size = frame_size

display_device.clear()
display_device.show()

Is this way correct?

Find out this already was solved here: https://github.com/rm-hull/luma.lcd/issues/70

Since I know more people with similar problem, the proper way to initiate this screen is:

from luma.core.interface.serial import spi
from luma.lcd.device import st7735
from luma.core.render import canvas
from time import sleep

#need to install pillow as a drop in replacement for discontinued PIL
# pip3 install pillow
from PIL import Image, ImageDraw

frame_size = (128, 128)
spi_config = spi(port=0, device=0, gpio_DC=25, gpio_RST=27, bus_speed_hz=16000000)
display_device = st7735(spi_config, rotate=2, gpio_LIGHT=24, h_offset=1, v_offset=2, active_low=False, bgr=True)
display_device.size = frame_size
display_device.clear()

base_image = Image.new('RGB', frame_size, 'black')

draw = ImageDraw.Draw(base_image)

with canvas(display_device) as draw:

    #this won't work properly
    #draw.rectangle(display_device.bounding_box, outline="white")

    draw.rectangle([(0,0), (126,126)], outline="red", width=2)
    draw.text((10, 40), "Hello World", fill="blue")

sleep(4)