I can't get my ESP32-S2 with TFT to work with my LoRa RFM95 featherwing. I can get the display to initialize and show a "hello world", but the display stops working as soon as I try to initialize the RFM95. I have tried initializing the SPI with busio, and board.SPI(). The CS for the RFM95 and the display should not conflict. Please some help. Thanks.
`#basic working Feather esp32-s2 w/ TFT display demo with and w/out RFM9x simpletest
import board
import terminalio
import displayio
from adafruit_display_text import label
import time
import adafruit_rfm9x
import digitalio
import busio
set some parameters used for shapes and text
BORDER = 20
FONTSCALE = 2
FOREGROUND_COLOR = 0x00ff00 # Bright Green
BACKGROUND_COLOR = 0xAA0088 # Purple
TEXT_COLOR = 0x000000 #black
#This sets up the RFM9x LoRa featherwing, the "Hello World" only displays when this is commented out.
I don't have to initalize the SPI bus when only using the display.
RADIO_FREQ_MHZ = 905.5
CS = digitalio.DigitalInOut(board.D13)
RESET = digitalio.DigitalInOut(board.D12)
#spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) #This spi init only works for the display only
spi = board.SPI()
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
rfm9x.tx_power = 23
#End of the Radio stuff
#This sets up the built-in display on the ESP32-S2 TFT
tft_cs = board.D5 #This CS should not conflict with the CS for the RFM9x, which is D13
tft_dc = board.D6
display = board.DISPLAY
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:
packet = rfm9x.receive()
if packet is None:
print("Received nothing! Listening again...")
text_area.text = "Received nothing! Listening again..."
display.show(splash)
else:
print("Received (raw bytes): {0}".format(packet))
text_area.text = "Received (raw bytes): {0}".format(packet)
display.show(splash)
time.sleep(0.1)
packet_text = str(packet, "ascii")
print("Received (ASCII): {0}".format(packet_text))
text_area.text = "Received (ASCII): {0}".format(packet_text)
display.show(splash)
time.sleep(1)
rssi = rfm9x.last_rssi
print("Received signal strength: {0} dB".format(rssi))
text_area.text = "Received signal strength: {0} dB".format(rssi)`