User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Pico HTTPS GET through ESP01 serial2wifi

Tue Mar 23, 2021 1:11 pm

Yesterday I published simple serial to Wifi forwarder for ESP01 (smallest ESP8266 module):
https://gist.github.com/Hermann-SW/e945 ... c679f48b03
(description of Pico to ESP01 connection in 1st gist comment)


Today I tried to use it to let Pico do HTTPS GET request aginst the internet.
It turned out that in current Pico MicroPython the UART read buffer is limited to 32 bytes.
I asked in Micropython forum in a related thread, and @robert-hh already had done a pull request to fix that:
https://forum.micropython.org/viewtopic ... 283#p56283

I just cloned his rp2_uart_buffer branch and built and flashed Micropython with uart buffer fix this way:

Code: Select all

cd ~/pico
mkdir robert-hh
cd robert-hh
git clone -b rp2_uart_buffered https://github.com/robert-hh/micropython.git
cd micropython
git submodule update --init -- lib/pico-sdk lib/tinyusb
make -C mpy-cross -j4
cd ports/rp2
time make -j4
flash build/firmware.uf2

And it works!
The response size of first URL I tested was bigger than 256 bytes default rxbuf.
So I created a bigger one with "uart=UART(0, 115200, rxbuf=512)".
As you can see the Pico can access my personal website on the internet easily.
In case you do not have a ESP01 module, you can buy together with USB programmer for less than 2$.
Have fun with Pico internet access.
Peek_2021-03-23_12-32.gif
Peek_2021-03-23_12-32.gif
Peek_2021-03-23_12-32.gif (118.34 KiB) Viewed 1656 times
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
andypiper
Posts: 9
Joined: Thu Sep 08, 2011 11:57 am
Location: UK
Contact: Website

Re: Pico HTTPS GET through ESP01 serial2wifi

Wed Mar 31, 2021 10:53 pm

This looks great! Would you be willing to do a slightly more detailed write-up - I currently have a an ESP-01S module on a MakerPi, but I think if I'm understanding your Gist sketch, I'd need to independently flash that to the ESP as well, plug it back together on the MakerPi base, and run the MicroPython code for the fetching? I've used the ESP8266 and ESP32 variants, but this is my first attempt with the 01 board, so I'm inferring more than I probably should, here.

User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Pico HTTPS GET through ESP01 serial2wifi

Thu Apr 01, 2021 5:47 pm

andypiper wrote:
Wed Mar 31, 2021 10:53 pm
but I think if I'm understanding your Gist sketch, I'd need to independently flash that to the ESP as well, plug it back together on the MakerPi base,
No.
I don't know MakerPi, I use simple USB programmer to flash the ESP01S:
Image

I did install Arduino IDE on my Pi400 and then flashed the gist sketch to the ESP.

After that the ESP01S needs to be connected directly with 5 cables to the Pi Pico, as detailed in 1st gist comment:
Just connect Pico 3V3/GND/GP0/GP1/3V3 to ESP01 3V3/GND/RX/TX/EN.
20210321_180703.10%.jpg
20210321_180703.10%.jpg
20210321_180703.10%.jpg (22.13 KiB) Viewed 1415 times

Finally you have to follow the instructions to build Micropython with @robert-hh's UART buffer fix according the detailed instructions in previous posting in this thread. See animation of previous posting on what to do in minicom session (write a HTTPS URL appended with '\n' to uart, and then read response from uart) for letting Pico access the internet.


Late P.S:
Instead of Pico Micropython now C-SDK can be used as well with the ESP01:
https://github.com/Hermann-SW/C-SDK_HTT ... esp01-wifi
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Pico HTTPS GET through ESP01 serial2wifi

Tue Apr 13, 2021 8:08 am

@robert-hh's pull request was worked on and merged 20h ago.
No need to build Micropython for robert-hh's configurable rx/tx buffers anymore.
Latest rp2 dailybuild from now on contains configurable UART buffers, here is latest:
https://micropython.org/resources/firmw ... ffda17.uf2

Code: Select all

>>> 
MPY: soft reboot
MicroPython v1.14 on 2021-04-13; Raspberry Pi Pico with RP2040
Type "help()" for more information.
>>> from machine import UART
>>> uart=UART(0, 115200, rxbuf=512)
>>> 

https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

gregwa
Posts: 31
Joined: Tue Feb 02, 2021 10:15 am

Re: Pico HTTPS GET through ESP01 serial2wifi

Wed Apr 14, 2021 7:20 am

@andypiper...
If you are referring to the Maker Pi Pico, then I believe you are correct. You would have to flash the ESP-01 with the code from the github repository first. Then you would plug that into the Maker Pi Pico.

Now here is the important bit. The Maker Pi Pico uses GP17 and GP16 for the pins for the UART instead of pins mentioned above. Therefore, you should use the following line to initialize the UART...

Code: Select all

uart = UART(0, rx=Pin(17), tx=Pin(16), baudrate=115200,rxbuf=512)
I just ordered a USB programmer for the ESP-01 and it should be here sometime on April 15. I should have a firm answer for you sometime on April 15 or April 16.

I hope this helps.

Greg

gregwa
Posts: 31
Joined: Tue Feb 02, 2021 10:15 am

Re: Pico HTTPS GET through ESP01 serial2wifi

Thu Apr 15, 2021 11:29 pm

I can verify that to use the newly programmed ESP-01 on a Maker Pi Pico that the UART definition line would be:

Code: Select all

uart = UART(0, rx=Pin(17), tx=Pin(16), baudrate=115200,rxbuf=512)
Follow the code in the animated images above. You can use the REPL in Thonny if you wish.

Return to “MicroPython”