Disconnect ESP32 Wi-Fi of PyPortal

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
jhoropopo
 
Posts: 9
Joined: Thu Jun 24, 2021 3:24 pm

Disconnect ESP32 Wi-Fi of PyPortal

Post by jhoropopo »

Hi,

is it possible to turn off or disconnect the ESP32 Wi-Fi coprocessor of the PyPortal? I don't need it for my project and I would like to save some energy this way. I couldn't find any information related to this.

Thanks in advance!

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

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by tannewt »

You can use the ESP_RESET pin to hold the ESP in reset. In ESP chips, this actually disables the power regulator so it should be a good way to save energy.

User avatar
jhoropopo
 
Posts: 9
Joined: Thu Jun 24, 2021 3:24 pm

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by jhoropopo »

Thanks @tannewt for the reply!

Do you mean something like this?

Code: Select all

esp32_reset = DigitalInOut(board.ESP_RESET)
esp32_reset = Direction.OUTPUT
esp32_reset = True
I changed my mind in the meantime and I would like to now use the wifi, but very occasionally only. This means querying some stuff, then wifi off for several hours and then on again. Could I hold the ESP reset for as long as I don't need it, then set it again to False, do my query and back to True again for several hours?

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

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by tannewt »

Something like that yes. You should be able to reconnect after holding it low for a while.

I highly recommend a power monitor if you don't have one already: https://www.adafruit.com/product/5048 (Hopefully in stock elsewhere.)

User avatar
jhoropopo
 
Posts: 9
Joined: Thu Jun 24, 2021 3:24 pm

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by jhoropopo »

Nice! Thanks for the answers and for the power monitor advice!

User avatar
jhoropopo
 
Posts: 9
Joined: Thu Jun 24, 2021 3:24 pm

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by jhoropopo »

I have been trying to access directly the ESP reset pin of the PyPortal board but so far I was not successful. Just this:

Code: Select all

esp32_reset = DigitalInOut(board.ESP_RESET)
throws this ValueError:

Code: Select all

Traceback (most recent call last):
  File "code.py", line 36, in <module>
ValueError: ESP_RESET in use
I have been looking into the source code of PortalBase and PyPortal in github to see whether I have some other "entry point" or way to access this variable. I also don't really know what the problem here is, but I guess that this object is already somehow assigned otherwise and therefore the error.

Any help how to solve this is highly appreciated :)

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

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by tannewt »

I think the reset line use is buried pretty deep in the pyportal objects. You could use the lower level classes or dig into the portal object to find it. To dig, its probably easiest to create PyPortal from the REPL and then use dir() to find the objects it could be on. Sorry its not super accessible, this is a niche thing you are doing. We assumed with pyportal that it'd be connected to power due to the power consumption of the display backlight.

User avatar
jhoropopo
 
Posts: 9
Joined: Thu Jun 24, 2021 3:24 pm

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by jhoropopo »

Ok, I finally got the solution:

Code: Select all

pyportal.network._wifi.esp._reset.value = False
This resets the ESP32. Thanks again for your help!

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

Re: Disconnect ESP32 Wi-Fi of PyPortal

Post by tannewt »

Nice work! Thanks for the update

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

Return to “Adafruit CircuitPython”