PyGamer w/SD Card + AirLift not working

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
StevieRayCorn
 
Posts: 8
Joined: Wed Sep 11, 2019 8:09 pm

PyGamer w/SD Card + AirLift not working

Post by StevieRayCorn »

Hello all,
I have the PyGamer with the AirLift ESP32 feather wing, and together they work fine. I noticed an issue where if I insert a SD card (with no code change) in the PyGamer, the ESP32 no longer works. Below is the error in the terminal:
code.py output:
ESP32 SPI webclient test
Traceback (most recent call last):
File "code.py", line 59, in <module>
File "adafruit_esp32spi/adafruit_esp32spi.py", line 335, in status
File "adafruit_esp32spi/adafruit_esp32spi.py", line 325, in _send_command_get_response
File "adafruit_esp32spi/adafruit_esp32spi.py", line 292, in _wait_response_cmd
File "adafruit_esp32spi/adafruit_esp32spi.py", line 271, in _wait_spi_char
RuntimeError: Timed out waiting for SPI char
If I mount the SD card, I can read the files from it no problem (*.wav files shown below), but the ESP32 throws a slightly different error:
code.py output:
ESP32 SPI webclient test
['snare.wav', 'hat.wav', 'kick.wav']
Traceback (most recent call last):
File "code.py", line 59, in <module>
File "adafruit_esp32spi/adafruit_esp32spi.py", line 335, in status
File "adafruit_esp32spi/adafruit_esp32spi.py", line 325, in _send_command_get_response
File "adafruit_esp32spi/adafruit_esp32spi.py", line 293, in _wait_response_cmd
File "adafruit_esp32spi/adafruit_esp32spi.py", line 277, in _check_data
RuntimeError: Expected A0 but got 80
Is there some conflict between the SPI devices? I am using all example code from Adafruit:

Code: Select all

# If you have an AirLift Featherwing or ItsyBitsy Airlift:
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# spi = board.SPI()
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)

sdcard = sdcardio.SDCard(spi, board.SD_CS)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")
I tried all sorts of combinations, different order, etc. Ejecting the SD card makes the ESP32 work. Has anyone else had this issue? I see other products like the PyPortal and MagTag that have 3 SPI devices all on board (TFT, SD, ESP32), so I assume it's possible to have all 3 work at the same time, using different CS pins.

I am on CircuitPython 7, and tried reverting back to 6.3, same results on both.

Thanks very much!

User avatar
jepler1
 
Posts: 50
Joined: Mon Oct 28, 2013 4:16 pm

Re: PyGamer w/SD Card + AirLift not working

Post by jepler1 »

When an SD card shares an SPI bus with other devices, folk wisdom states that the SD card must be initialized first. Do you get a different result if you move the initialization of the SD card prior to the initialization of ESP32SPI? See e.g., this page that I often refer to for SD card information: http://elm-chan.org/docs/mmc/mmc_e.html#spibus (the display is on an independent SPI bus from the SD card). If the SD card gets confused, it needs to actually be powered off (or reinserted) before it will behave properly.

Note that the SD card library is supposed to take care of the need for writing a dummy byte after the SD CS is deasserted, so you shouldn't need to worry about that.

The built in display on the pygamer is independent of the SPI bus used by the SD card and on the expansion header, so it is not a concern here.

User avatar
StevieRayCorn
 
Posts: 8
Joined: Wed Sep 11, 2019 8:09 pm

Re: PyGamer w/SD Card + AirLift not working

Post by StevieRayCorn »

Hello, and thanks for the reply. I don't think my point got across...the issue is when I put in a SD Card, the AirLift wing stops working and throws those errors. Even if there is NO CODE at all for the SD Card, the AirLift still throws the error "Timed out waiting for SPI char". When adding code for the SD Card, the order seems to not matter.

Do you have this hardware on hand? PyGamer + AirLift ESP32 Feather Wing + SD Card? Connect them and put this in code.py and see what you get (please supply your own secrets.py)...

Code: Select all

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

import time
import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

print("ESP32 SPI webclient test")

JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"

# If you have an AirLift Featherwing or ItsyBitsy Airlift:
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# spi = board.SPI()
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
requests.set_socket(socket, esp)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["password"])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ", e)
        continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))

for i in range(1):
    print(i)
    r = requests.get(JSON_URL)
    data = r.json()
    print (data)
    r.close()

print("Done!")

User avatar
jepler1
 
Posts: 50
Joined: Mon Oct 28, 2013 4:16 pm

Re: PyGamer w/SD Card + AirLift not working

Post by jepler1 »

Short version, yes, I think that an uninitialized SD card can interfere with other activities on the same "SPI bus", because it not yet in SPI mode when it is powered on.
There is an important thing needs to be considered that the MMC/SDC is initially NOT the SPI device. Some bus activity to access another SPI device can cause a bus conflict due to an accidental response of the MMC/SDC. Therefore the MMC/SDC should be initialized to put it into the SPI mode prior to access any other device attached to the same SPI bus.
(fromhttp://elm-chan.org/docs/mmc/mmc_e.html#spibus

User avatar
StevieRayCorn
 
Posts: 8
Joined: Wed Sep 11, 2019 8:09 pm

Re: PyGamer w/SD Card + AirLift not working

Post by StevieRayCorn »

I tried setting up the SD Card right at the top of the app, similar results as before with the ESP32 throwing "expected A0 but got 80". It's doing it on the line where it checks the status property.

User avatar
jepler1
 
Posts: 50
Joined: Mon Oct 28, 2013 4:16 pm

Re: PyGamer w/SD Card + AirLift not working

Post by jepler1 »

From my understanding, this should work. I've filed an issue on github: https://github.com/adafruit/circuitpython/issues/5644 -- if you use github, you can follow this issue to get updates about it. I'll do a bit more checking around and find out whether this is expected to work. I apparently don't own any airlift boards of my own for testing this.

User avatar
StevieRayCorn
 
Posts: 8
Joined: Wed Sep 11, 2019 8:09 pm

Re: PyGamer w/SD Card + AirLift not working

Post by StevieRayCorn »

Yes, I use Gothub, so I'll follow on there. Please let me know what else you may find. Thanks

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

Return to “Adafruit CircuitPython”