adafruit / Adafruit_CircuitPython_ST7735

CircuitPython display driver for ST7735
MIT License
5 stars 9 forks source link

Unable to get display working with HalloWing M4 #9

Closed reversefold closed 4 years ago

reversefold commented 4 years ago

I have tried both adafruit-circuitpython-hallowing_m4_express-en_US-4.1.2.uf2 and adafruit-circuitpython-hallowing_m4_express-en_US-5.0.0-beta.3.uf2 with the appropriate version of the mpy libraries. This is the code I'm using to initialize the display from looking into the python code and the code used for the default eye:

import board
import displayio
from adafruit_st7735 import ST7735

displayio.release_displays()

spi = board.SPI()
tft_cs = board.TFT_CS  # D5
tft_dc = board.TFT_DC  # D6
reset = board.TFT_RESET  # D9

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=reset)
display = ST7735(display_bus, width=160, height=128)

splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 128, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

bg_sprite = displayio.TileGrid(
    color_bitmap,
    pixel_shader=color_palette,
    x=0, y=0,
)
splash.append(bg_sprite)

The display never turns on. I've used similar code with the Circuit Playground Bluefruit and the TFT Gizmo and it has worked just fine.

I'm very new to the Adafruit technology and this kind of hardware so if I've just made a mistake I would appreciate pointers.

makermelissa commented 4 years ago

Sounds like the init codes are not correct. Maybe try the ST7735R driver.

ladyada commented 4 years ago

@reversefold when you got the hardware did the display light up and display anything ever?

reversefold commented 4 years ago

@makermelissa I tried ST7735R as well with the same effect.

@ladyada Yes, the display worked fine when I got it and if I put the original UF2 file on it or build and upload the M4_Eyes project through the Arduino IDE it still works fine. I'm just unable to get it to display anything with CircuitPython.

ladyada commented 4 years ago

hmm should 'just work' - @makermelissa wanna it next week?

caternuson commented 4 years ago

@reversefold Any reason why you aren't using the display instance provided by the firmware? This is a special case for firmware builds for boards with built-in displays, like PyPortal and Hallowing: https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus#boards-with-built-in-displays-6-17

This worked for me with a Hallowing M4 and CP 4.1.2:

import board
import displayio

display = board.DISPLAY

splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 128, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

bg_sprite = displayio.TileGrid(
    color_bitmap,
    pixel_shader=color_palette,
    x=0, y=0,
)

splash.append(bg_sprite)
reversefold commented 4 years ago

I had notices board.DISPLAY but it was always None until the code to initialize the display had run. For example, here's some testing code:

import board
import displayio
from adafruit_st7735 import ST7735

print(repr(board.DISPLAY))

# Release any resources currently in use for the displays
displayio.release_displays()

display = board.DISPLAY

spi = board.SPI()
tft_cs = board.TFT_CS  # D5
tft_dc = board.TFT_DC  # D6
reset = board.TFT_RESET  # D9

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=reset)
display = ST7735(display_bus, width=160, height=128)
print(repr(board.DISPLAY))

And here's the output:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
None
<Display>
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
<Display>
<Display>

Oddly when I save my code.py I get two reloads. The first run there is nothing in board.DISPLAY until the display is created manually. On the second run the board.DISPLAY is set both times. Neither run shows anything on the screen, though.

This all may be an artifact of my code having run first, though. I noticed today that on a reset of the board the display came up for less then a second then went dark. Trying your code by putting it in code.py and saving then failed to show anything. After resetting the board I see that the display has come up and shows the CircuitPython output but I don't see the red rectangle I'm expecting.

Trying some simple turtle code does display as I expect, though:

import board
from adafruit_turtle import turtle

display = board.DISPLAY
turtle = turtle(display)
turtle.goto(-75, 0)
turtle.setheading(90)
turtle.pendown()
turtle.forward(150)
makermelissa commented 4 years ago

Hi @reversefold,

I got your original script working by taking out the unnecessary stuff:

import board
import displayio

display = board.DISPLAY

splash = displayio.Group(max_size=10)
display.show(splash)

color_bitmap = displayio.Bitmap(128, 128, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000

bg_sprite = displayio.TileGrid(
    color_bitmap,
    pixel_shader=color_palette,
    x=0, y=0,
)
splash.append(bg_sprite)

while True:
    pass

I tested using CP 5.0 Beta 3. I added the loop at the end so it would continue to show the red square.

Regarding you needing to load twice, you have a lot of unnecessary code in there:

import board
import displayio
print(repr(board.DISPLAY))

# Release any resources currently in use for the displays
displayio.release_displays()

display = board.DISPLAY

spi = board.SPI()
tft_cs = board.TFT_CS  # D5
tft_dc = board.TFT_DC  # D6
reset = board.TFT_RESET  # D9

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=reset)
display = ST7735(display_bus, width=160, height=128)
print(repr(board.DISPLAY))

I ran the following:

import board

print(repr(board.DISPLAY))

and here was my output:

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
<Display>

I got the same results on CP 4 and CP 5. Regardless, the TFT on the HalloWing M4 is the ST7789 display, so this is the wrong driver anyways.

makermelissa commented 4 years ago

Closing due to this being the incorrect driver for the HalloWing M4. If you have anything else to add, please let us know.