Example code for the new Feather ESP32 S2 with TFT

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

Hi, I just received my two shiny new Feather ESP32 S2 with TFT boards. It came up running the battery demo Lady Ada showed in the New Products announcement. I cannot find the source to that demo. I have put CircuitPython 7.1.0 on it. It started up with the typical "Hello world" code.py. Where can I find documentation and/or sample programs for this board? I would love to see the code for the simple battery monitor.

I realize that the board is similar to the previous Feather ESP32 S2 board with the addition of the TFT. Would love to see a simple example, or a Learn guide, that showed how to get WiFi setup and use the screen. I am sure I can figure this all out (or assume I could) but I've gotten spoiled with all the great learn guides and example code and hoping for a similar jump start.

If there isn't any code like that yet, are there any tricks or technical details I should know about before diving in? Thanks in advance. If I end up answering this myself I will post my findings in reply to this message,

User avatar
anecdata
 
Posts: 10
Joined: Wed Jan 05, 2022 5:57 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by anecdata »

The guide is in the works. The board operates generally like other ESP32-S2 boards. Keep in mind that there is a NeoPixel power pin to enable NeoPixel Power, and an I2C / TFT Power pin to enable TFT Power. Use dir(board) to get the actual pin names.

Simple ESP32-S2 wifi example:
https://github.com/adafruit/Adafruit_Ci ... tpython.py

TFT is an ST7789, so this guide applies (substitute board pin names):
https://learn.adafruit.com/adafruit-1-1 ... t-breakout
Plus all of the displayio guides.

I think you are on Discord, plenty of folks there would be happy to give more suggestions.

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

Thanks. I discovered a nice network demo under the Metro ESP32-S2 that worked well to provide an example of connecting over a network and using web service calls. This unblocks me. I'll check out the link you provided.

The little TFT on this new Feather ESP32-S2 w/TFT is gorgeous. Next I will go in search of examples how to use this color screen.

User avatar
adafruit_support_carter
 
Posts: 29161
Joined: Tue Nov 29, 2016 2:45 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by adafruit_support_carter »

Yep - nothing to add other than what has already been said. The Learn Guide for that product is in works and will be out soon. If possible, it'll contain the source code for the demo as well. Keep an eye out for the Learn Guide to go live.

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

Thank you all. Prompt and helpful as always!

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

I may need a new post. I am still having a few problems. I can't get the TFT to work in CircuitPython using displayio. If I just boot the board and print to the serial console I see that text. But if I try to initialize the ST8879 using board TFT_CS and TFT_DS in the initialization, I can't get any output on any of the samples I've tried. I suspect there may be an extra step required here that isn't needed in the examples I've try to borrow from. Here is one of the examples. It's straight out of github readme for ST7789 with only the TFT CS and DC parameters changed to refer to board.TFT_CS and board.TFT_DC.

Thoughts? It produces no errors. I believe I have all the proper modules in the lib folder. On this board I am using CP 7.1.0 but will try the latest build tonight too.

Code: Select all

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

"""
This test will initialize the display using displayio and draw a solid green
background, a smaller purple rectangle, and some yellow text.
Pinouts are for the 1.14" Mini PiTFT and should be run in CPython.
"""
import board
import terminalio
import displayio
from adafruit_display_text import label
from adafruit_st7789 import ST7789

# First set some parameters used for shapes and text
BORDER = 20
FONTSCALE = 2
BACKGROUND_COLOR = 0x00FF00  # Bright Green
FOREGROUND_COLOR = 0xAA0088  # Purple
TEXT_COLOR = 0xFFFF00

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

spi = board.SPI()
tft_cs = board.TFT_CS
tft_dc = board.TFT_DC

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
display = ST7789(
    display_bus, rotation=90, width=240, height=135, rowstart=40, colstart=53
)

# Make the display context
splash = displayio.Group()
display.show(splash)

color_bitmap = displayio.Bitmap(display.width, display.height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = BACKGROUND_COLOR

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

# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(
    display.width - BORDER * 2, display.height - BORDER * 2, 1
)
inner_palette = displayio.Palette(1)
inner_palette[0] = FOREGROUND_COLOR
inner_sprite = displayio.TileGrid(
    inner_bitmap, pixel_shader=inner_palette, x=BORDER, y=BORDER
)
splash.append(inner_sprite)

# Draw a label
text = "Hello World!"
text_area = label.Label(terminalio.FONT, text=text, color=TEXT_COLOR)
text_width = text_area.bounding_box[2] * FONTSCALE
text_group = displayio.Group(
    scale=FONTSCALE,
    x=display.width // 2 - text_width // 2,
    y=display.height // 2,
)
text_group.append(text_area)  # Subgroup for text scaling
splash.append(text_group)

while True:
    pass

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

forgot to mention... @anecdata, I am on discord (same username). This is Rich Sadowsky. Last time I posted a question about a topic like this on cp help channel in Discord, they recommended I post here instead! My algorithm is simple: if I need help urgently I try real time chat first. If I am just curious I post here.

On a related topic, I presume the little battery display that was installed by default on this new Feather ESP32 S2 w/TFT was written in Arduino since I didn't see a CIRCUITPY drive until I flashed it with CP 7.1.0. If you need a volunteer, I'd be willing to port it to CP as soon as I work through my initial clumsiness with this new board. It's my first time using networking or the ST8879.

The Adafruit Learn guides are so good I seem to have become overly reliant on them. They certainly didn't have resources like that when I started coding in the 1970s!

User avatar
anecdata
 
Posts: 10
Joined: Wed Jan 05, 2022 5:57 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by anecdata »

I think the "displayio.release_displays()" line could be causing your issue. I won't have a board to test until tomorrow, but in general, that line isn't needed on devices with built-in displays _unless_ you actually want to not use the display (and maybe use something else, or only use it later in execution).

On the other hand, you do re-init the display, I'm not sure why that wouldn't work.

What happens if you don't have the "release..." line, and also don't have all of the ST7789 setup code (I know I suggested that, sorry), and just use something like: "display = board.DISPLAY"?

There's display init code in the core / UF2:
https://github.com/adafruit/circuitpyth ... ft/board.c
so it should just come up with "display = board.DISPLAY" like a FunHouse or any other built-in display.
Last edited by anecdata on Tue Jan 11, 2022 2:45 am, edited 1 time in total.

User avatar
anecdata
 
Posts: 10
Joined: Wed Jan 05, 2022 5:57 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by anecdata »

One more thing... there's a power control pin that you probably need to set high to enable power to I2C and the TFT (there's a similar pin for the NeoPixel).

So, something like:

Code: Select all

i2c_tft_power_ctrl = digitalio.DigitalInOut(board.I2C_TFT_POWER)
i2c_tft_power_ctrl.direction = digitalio.Direction.OUTPUT
i2c_tft_power_ctrl.value = True
(don't forget to import digitalio)
(I _think_ it's active-high, but if that doesn't work, try setting the `value` to `False`.)

User avatar
danhalbert
 
Posts: 4652
Joined: Tue Aug 08, 2017 12:37 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by danhalbert »

One more thing... there's a power control pin that you probably need to set high to enable power to I2C and the TFT (there's a similar pin for the NeoPixel).
We made this on by default in 7.2.0-alpha.1 and later.

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

Hi guys, it is so nice to hear from members of the core CircuitPython dev team! Duh, I didn't think to try display = board.DISPLAY. I don't currently have any other boards with built-in displays so it wasn't something I thought of.

Before I saw this reply, I had tried the 7.2.alpha build last night but no change. I will double check my work and try these suggestions. The power enabling sounds right because the board is clearly not powered since it remains black as night. I will post later with results.

I frequently find myself using products before the learn guide is available or example code available. I watch most of the live YouTube shows and order anything that interests me. I may need to join "Microcontrollers Anonymous" for my maker electronics addiction!

User avatar
richsad
 
Posts: 60
Joined: Wed Mar 19, 2014 8:58 am

Re: Example code for the new Feather ESP32 S2 with TFT

Post by richsad »

Closing the loop, the advice above led to the solution. First I updated to CP 7.2.alpha.1. I removed the release_displays() call and added display = board.DISPLAY. I removed the SPI code and creation of the display via the ST7789 driver code. So about 10 lines collapsed into just:

Code: Select all

display = board.DISPLAY
Left of the code unchanged. A colorful Hello World greeted me on the TFT. I did not add the power on code since you mentioned this is on by default in this alpha version. Thanks to you both and also Kattni who discussed this with me on Discord live-broadcast-chat after JP's show today. She is working on the Learn guide as we speak.

User avatar
adafruit_support_carter
 
Posts: 29161
Joined: Tue Nov 29, 2016 2:45 pm

Re: Example code for the new Feather ESP32 S2 with TFT

Post by adafruit_support_carter »

The guide is now up:
https://learn.adafruit.com/adafruit-esp ... ft-feather

There's a UF2 available to return the board to shipped state:
https://learn.adafruit.com/adafruit-esp ... -3107942-2

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”