I am currently attempting to transmit images to a display via SPI communication on Jetson Nano.
The current setup involves installing Ubuntu 20.04 on Jetson Nano using an image downloaded from GitHub - Qengineering/Jetson-Nano-Ubuntu-20-image: Jetson Nano with Ubuntu 20.04 image.
The display being used is the adafruit PiTFT Plus 480x320 3.5" TFT+Touchscreen for Raspberry Pi (PiTFT Plus 480x320 3.5 TFT+Touchscreen for Raspberry Pi : ID 2441 : Adafruit Industries, Unique & fun DIY electronics and kits). The connection is established using jumper cables as follows:
Jetson’s Pin – Display Pin
- pin12 – Backlight Control
- pin18 – RT Interrupt
- pin19 – SPI0 MOSI
- pin21 – SPI0 MISO
- pin22 – TFT Data/Command
- pin23 – SPI0 SCLK
- pin24 – TFT Chip Select
- pin26 – RT Chip Select
I am currently referencing the repository at GitHub - JetsonHacksNano/SPI-Playground.
The issue I’m encountering is that while I was able to control the backlight with Jetson.GPIO, I encountered problems when attempting to use the adafruit_rgb_display.hx8357 display module for image transmission. Following the referenced repository, I’m using the digitalio and board modules, but not only am I unable to transmit images, but I’m also unable to adjust the backlight.
I’m seeking solutions or recommendations for displays compatible with smooth SPI communication on Jetson Nano.
The key points of my troubleshooting are as follows:
Executing the following code correctly applies voltage to pin 12 and successfully changes the display backlight:
import time
import Jetson.GPIO as GPIO
import spidev
from PIL import Image
def pin_init(i, interval_time):
target_num = i
GPIO.setmode(GPIO.BOARD)
GPIO.setup(target_num, GPIO.OUT, initial=GPIO.LOW)
print(f" {i} is LOW")
time.sleep(interval_time)
def pin_test(i, interval_time):
target_num = i
GPIO.setmode(GPIO.BOARD)
GPIO.setup(target_num, GPIO.OUT, initial=GPIO.LOW)
print(f" {i} is LOW")
time.sleep(interval_time)
GPIO.output(target_num, GPIO.HIGH)
print(f" {i} is HIGH")
time.sleep(interval_time)
GPIO.output(target_num, GPIO.LOW)
print(f" {i} is LOW")
time.sleep(interval_time)
print(f" {i} is nomal.")
print("GPIO pin test start")
spi = spidev.SpiDev()
spi.open(0, 0)
print("Current GPIO mode:", GPIO.getmode())
if False:
pin_test(12, 1)
else:
for i in range(1, 41):
try:
pin_init(i, 1)
except Exception as e:
print(f"{i} is errer. {e}")
continue
pin_test(12,1)
GPIO.cleanup()
spi.close()
However, using the following code with what I believe is pin 12 (board.D12) does not change the backlight at all:
import time
import digitalio
import board
backlight_pin = digitalio.DigitalInOut(board.D12)
backlight_pin.direction = digitalio.Direction.OUTPUT
backlight_pin.value = True
print("Backlight ON")
time.sleep(2)
backlight_pin.value = False
print("Backlight OFF")
time.sleep(2)
backlight_pin.value = True
print("Backlight ON")
time.sleep(2)
backlight_pin.value = False
print("Backlight OFF")
time.sleep(2)
If possible, I’d like to perform image transmission. However, I’m currently unsure of how to find the pin numbers corresponding to board.##
My ultimate goal is to successfully transmit images generated with PIL to the display, as shown in the following code:
import digitalio
import board
from PIL import Image, ImageDraw
import adafruit_rgb_display.hx8357 as hx8357
cs_pin = digitalio.DigitalInOut(board.CE0)
dc_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D12)
BAUDRATE = 24000000
spi = board.SPI()
disp = hx8357.HX8357(spi, rotation=180, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)
# Create blank image for drawing.
# Make sure to create image with mode 'RGB' for full color.
if disp.rotation % 180 == 90:
height = disp.width # we swap height/width to rotate it to landscape!
width = disp.height
else:
width = disp.width # we swap height/width to rotate it to landscape!
height = disp.height
image = Image.new('RGB', (width, height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
# Draw a black filled box to clear the image.
draw.rectangle((0, 0, width, height), outline=0, fill=(0, 0, 0))
disp.image(image)
image = Image.open("./shark.jpg")
# Scale the image to the smaller screen dimension
image_ratio = image.width / image.height
screen_ratio = width / height
if screen_ratio < image_ratio:
scaled_width = image.width * height // image.height
scaled_height = height
else:
scaled_width = width
scaled_height = image.height * width // image.width
#image = image.resize((scaled_width, scaled_height), Image.BICUBIC)
image = image.resize((scaled_width, scaled_height))
# Crop and center the image
x = scaled_width // 2 - width // 2
y = scaled_height // 2 - height // 2
image = image.crop((x, y, x + width, y + height))
# Display image.
disp.image(image)
Any help would be greatly appreciated.
I hope this helps! Let me know if you need further assistance.