Open
Description
Hello i just installed CircuitPython on my Teensy 4.0. Im trying to use a Adafruit AirLift FeatherWing - ESP32 WiFi Co-Processor. Following the guide i installed all the dependencies/ libraries and have the Wifi Co-Processor up to date. Using the ScanNetwork Arduino sketch it runs fine and i can see available networks. As soon as i use CircuitPython i get this error.
code.py output:
ESP32 SPI hardware test
Traceback (most recent call last):
File "code.py", line 20, in <module>
File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 342, in status
File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 332, in _send_command_get_response
File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 299, in _wait_response_cmd
File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 278, in _wait_spi_char
TimeoutError: Timed out waiting for SPI char
I saw a similar problem arise and followed the outlined steps but i still have the problem.
If anyone has any recommendations id much appreciate it.
Best,
W
Example code:
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
print("ESP32 SPI hardware test")
esp32_cs = DigitalInOut(board.D5)
esp32_ready = DigitalInOut(board.D9)
esp32_reset = DigitalInOut(board.D6)
esp32_gpio0 = DigitalInOut(board.D10)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0)
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])
for ap in esp.scan_networks():
print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))
print("Done!")
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
wiseac commentedon Jul 10, 2022
At this point in time I have it running which is great. I changed the baud rate of 8000000 (Which isn't very common, or common at all) to common values such as 115200 or the highest common 921600 and it worked.
154: self._spi_device = SPIDevice(spi, cs_dio, baudrate=921600)
I did run into some scanning network problems for CircuitPython 8 alpha for the Teensy4.0 but the 7.3.1 version works great!
This is a bit of self closure but Im interested in why the baudrate is set so high? Might just be a teensy thing and it not understand that number means more limitless and needs a defined common rate.
Im going to leave this open a tad bit longer to see if I run into any other problems and to see if my question gets answered.
Best,
W
dhalbert commentedon Jul 20, 2022
This the the SPI clock frequency -- it's not a UART baud rate, so it can be much higher. However, it's interesting that reducing the SPI clock rate improved things for you.
HowdyMoto commentedon Dec 18, 2022
Hi there,
I've been having this problem with my Pyportal Titano for the last year. It will crash randomly after making network requests - sometimes on the first try, sometime after many hours of working smoothly. I have the latest Nina 1.7.4 firmware installed, and I've tried 6.x, 7.x and all the newest 8.x CP builds and libraries as well. I have tested three different Titanos, and they all do this, so it doesn't seem to be a problems that's unique to one of them.
I'm a novice programmer, so it's not been easy trying to figure out how to fix this, and I'm trying to make gadgets that will work reliably and indefinitely without crashing. Are there any resolution to this problem in the works for future released? AFAICT, it looks like I need to compile my own version of adafruit_esp32spi with a baud rate change to fix this. I would be so happy to have this officially resolved, so that I can distribute my gadgets in a way where future updates won't always require custom hacked libs.
anecdata commentedon Dec 18, 2022
@HowdyMoto When you say "crash", does that mean: the PyPortal becomes completely unresponsive until reset? the PyPortal gets a hardfault? the PyPortal exits your code with an exception? Depending on which behavior, there are a number of things to try.
Under normal circumstances, it should not be necessary to reduce the SPI frequency. Generally, the PyPortal devices and typical libraries are stable under 7.3.3, and even under the 8.0.0-betas.
It is expected that networking code will get exceptions, so the
try:
/except:
construct in Python code is essential around networking calls. When failures occur, you can skip, retry, reset the ESP32, reload the code, or reset the PyPortal (somewhat in that order if things continue not to work). There is also debugging that can be turned on for the ESP32SPI library, and separately for the NINA firmware on the ESP32 chip - these sometimes provide more clues on unusual issues.https://adafru.it/discord is a great place to go for support questions.
HowdyMoto commentedon Dec 20, 2022
Thanks for this! When I say "crash", I mean that I get the this error:
File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 278, in _wait_spi_char TimeoutError: Timed out waiting for SPI char
which halts the program. I tried try/catch blocks, and tried resetting the esp with esp.reset(), followed by re-initializing it and re-conecting to Wifi, but after that error is thrown, it never seem to be able to recover until I reboot the device.
My program is based on this:
https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PyPortal_Google_Calendar/code.py
However, as I got frustrated from these crashes, I re-wrote the entire thing just to expose the esp.reset() function, which I seem to recall isn't exposed when you're using the Pyportal libs.
Here's my new code. Unfortunately, worldtimeapi.org went down last week. so it won't run anymore -
https://github.com/HowdyMoto/PyPortal_Google_Calendar/blob/main/code-no-portal-libs.py
Here's one piece of code that generated this error - when it happens, I try to reset the esp and re-inititialize it, and reconnect to wifi, but it doesn't work (and unfortuantely it won't run at all right now, and I forget what exactly the error is)
anecdata commentedon Dec 20, 2022
btw, you can init the esp separately, then pass it in to the PyPortal https://docs.circuitpython.org/projects/pyportal/en/latest/api.html#adafruit_pyportal.PyPortal, then you have access to
esp.reset()
and other esp functions while still using the PyPortal library.It is unusual that
esp.reset()
doesn't recover. More detail on what's happening there would help. Discord is a great place for that level of discussion.esp.reset()
is a bit severe. but otoh it only takes a second (I add a delay after that call to make sure the firmware is fully up before any subsequent operations), and if the code timing can handle it, then do it as often as you like.slootsky commentedon Aug 8, 2023
I'm also getting this timeout error with my PyPortal.
I just updated my nina fw to 1.7.5
I'm running circuitpython 8.2.2
my_minimqtt is adafruit_minimqtt with modifications (primarily moving SUBACK to _wait_for_msg and adding a code to MMQTTException that can be checked)
I tried adjusting the baudrate as above, but it still ocurred
I was able to get around the issue with the following code block in my main loop
the connectNeeded is an indicator to reconnect to wifi & mqtt, etc
HowdyMoto commentedon Aug 13, 2023
Hi all, here is a solution to this problem. I can confirm that my device now runs forever without crashing with this approach.
You can see my approach here on line 93:
https://github.com/HowdyMoto/PyPortal_Google_Calendar/blob/46a144875846bf7863fddd073166bc494ca535be/code.py#L93
In short, you'l need to do the following:
Voila! Works perfectly. Good luck, friends!
eloekset commentedon Sep 25, 2023
@HowdyMoto are you still sure your application runs forever without freezing? Referring to the issue I linked to above, my PyPortal Titano still freezes after doing the same error handling as you do. I even bought a new device in case it was hardware related. The new device ran 1120 iterations reloading API data before freezing, which is way more than my first device. But that might be a coincidence.
Console log between iteration 1120 and 1121:
Connecting to AP GID12A_Serverskapet
indicates that thepyportal.network.connect()
line has executed before the next refetch, which means the except block was executed right before the freeze. I searched the console log as far back as it got, iteration 1098, and iteration 1120 was the first timeConnecting to AP
was executed among those.HowdyMoto commentedon Oct 16, 2023
I found that the problem went away completely, but I suppose it's possible that a different version of CircuitPython/different libraries could cause you problems.
This is the app I made that seemed to work fine, if you want to try it out:
https://github.com/HowdyMoto/PyPortal_Google_Calendar/tree/46a144875846bf7863fddd073166bc494ca535be
timeout
andTimeoutError
intended to be different? #197