Controlling Multiple Devices With SPI & Circuit Python

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
chagrincyclist
 
Posts: 30
Joined: Sun Jun 07, 2020 10:03 am

Controlling Multiple Devices With SPI & Circuit Python

Post by chagrincyclist »

First thanks for supporting Adafruit customers, you are a terrific help !! It keeps me coming to your site buying your products and spending days studying your examples.

I'm using a Feather M4 Express to control an ePaper display (epd) and an Airlift wifi board (esp32)... an IOT project. I've wired up the boards and can run a program for the display successfully and a separate program for the wifi successfully. Now I'm trying to marry the two programs so I can display stuff from the internet.

I understand I need to use the Chip Select CS part of SPI to turn the EPD and ESP high and low depending on when they are needed. However, I'm having trouble with the pin set up and SPI bus set up in the code. I've copied the first part of my program below which is throwing the error. I'm getting the error message "type error: expect a Pin" referencing the last line of code below (displaly_bus =....). Thanks in advance for your assistance.

Code: Select all

# IMPORT MODULES
import board
import busio
import digitalio
import displayio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
from secrets import secrets
import time
import adafruit_il0373
import terminalio
from adafruit_display_text import label
from adafruit_display_shapes.line import Line

# DEFINE VARIABLES

epd_dc = board.D10
epd_cs = digitalio.DigitalInOut(board.D9)
epd_cs.direction = digitalio.Direction.OUTPUT
epd_cs.value = True
# If you have an AirLift Shield:
esp32_cs = digitalio.DigitalInOut(board.A5)
esp32_cs.direction = digitalio.Direction.OUTPUT
esp32_cs.value = False
esp32_ready = DigitalInOut(board.A4)
esp32_reset = DigitalInOut(board.A3)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

displayio.release_displays()
display_bus = displayio.FourWire(
    spi, command=epd_dc, chip_select=epd_cs, baudrate=1000000) 

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by tannewt »

displayio needs a Pin rather than a DigitalInOut because it must be a native pin. So, pass in chip_select=board.D9 instead.

User avatar
chagrincyclist
 
Posts: 30
Joined: Sun Jun 07, 2020 10:03 am

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by chagrincyclist »

Thanks for your reply. If I set the chip select as a pin instead of digitalio, then how to I turn it high and low to control the display vs. The airlift?

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by tannewt »

You shouldn't need to do it manually. Each driver should assert cs when it needs it.

User avatar
chagrincyclist
 
Posts: 30
Joined: Sun Jun 07, 2020 10:03 am

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by chagrincyclist »

Ah OK thanks, I'll try it.

User avatar
chagrincyclist
 
Posts: 30
Joined: Sun Jun 07, 2020 10:03 am

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by chagrincyclist »

Thanks for your help, I got it all working !!!! It's awesome. The Magtag wifi has terrible range due to an antenna problem - but by using the 2.9" monochrome e-ink display and the airlift I've got exactly what I need. Thanks again.

User avatar
tannewt
 
Posts: 3315
Joined: Thu Oct 06, 2016 8:48 pm

Re: Controlling Multiple Devices With SPI & Circuit Python

Post by tannewt »

Awesome! I'm glad you got it working.

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

Return to “Adafruit CircuitPython”