Skip to content

chip select issue with multiple screens #95

Closed
@kmtm

Description

@kmtm

Hi, I'm trying to control two 2.2 TFT screens, both on SPI 0 using the two chip selects (CE0 and CE1).

Whenever I display to the first screen on CE0, it's fine (i.e. only displays on the first screen), but displaying to the second screen (CE1) pushes the same image to both screens. I can't seem to figure out why. Trying to manually throw CE0 high hasn't appeared to work.

Here's the implementation (adjusted from the sample code):

import digitalio
import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_rgb_display.ili9341 as ili9341
import time

# First define some constants to allow easy resizing of shapes.
BORDER = 0
FONTSIZE = 24

# Configuration for CS and DC pins (these are PiTFT defaults):
cs_pin = digitalio.DigitalInOut(board.CE0)
cs2_pin = digitalio.DigitalInOut(board.CE1)
dc_pin = digitalio.DigitalInOut(board.D25)
dc2_pin = digitalio.DigitalInOut(board.D25)
reset_pin = digitalio.DigitalInOut(board.D24)
reset_pin2 = digitalio.DigitalInOut(board.D24)

# Config for display baudrate (default max is 24mhz):
BAUDRATE = 24000000

# Setup SPI bus using hardware SPI:
spi = board.SPI()
print('spi set up')

# pylint: disable=line-too-long
# Create the display:
disp = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs_pin,
    dc=dc_pin,
    rst=reset_pin,
    baudrate=BAUDRATE,
)

disp2 = ili9341.ILI9341(
    spi,
    rotation=90,  # 2.2", 2.4", 2.8", 3.2" ILI9341
    cs=cs2_pin,
    dc=dc2_pin,
    rst=reset_pin2,
    baudrate=BAUDRATE,
)
# pylint: enable=line-too-long

# 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))

if disp2.rotation % 180 == 90:
    height2 = disp2.width  # we swap height/width to rotate it to landscape!
    width2 = disp2.height
else:
    width2 = disp2.width # we swap height/width to rotate it to landscape!
    height2 = disp2.height 

image2 = Image.new("RGB", (width2, height2))
print('width2:', width2, 'height2:', height2)

# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
draw2 = ImageDraw.Draw(image2)

# Draw a white filled box as the background
draw.rectangle((00, 0, disp.width+100, disp.height+100), fill=(225, 225, 225))
disp.image(image)

input('draw blue box on second screen only')

#Draw a blue box only on the second screen
draw2.rectangle((0, 0, disp2.width+100, disp2.height+100), fill=(0, 225, 225))
disp2.image(image2)

Essentially the blue box appears on both screens instead of just the second one!

I'm not sure if I'm doing something wrong with the chip selects/setup, or if this library just can't support multiple SPI devices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions