Pico MicroPython with networking over USB

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
HermannSW
Posts: 180
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Pico MicroPython with networking over USB

Post by HermannSW » Tue Apr 20, 2021 9:03 pm

Code currently is too bad for commit+push to my fork.
But running Pico Micropython on core0 and lwip networking plus webserver on core1 just works for the first time. You can download firmware.uf2 and try out yourself, see this posting for details:
https://www.raspberrypi.org/forums/view ... 1#p1854481

Webpage hosted on Pico 192.168.7.1 (left) in Pi4B (192.168.178.2) browser.
UART minicom session turning on Pico led (right).
16MP smartphone photo: https://stamm-wilbrandt.de/en/forum/mp/ ... 220347.jpg
Scaled to 15%:
Image
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

HermannSW
Posts: 180
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Pico MicroPython with networking over USB

Post by HermannSW » Wed Apr 21, 2021 6:21 pm

I am done with cleanup and commited+pushed the changes to my micropython fork with this commit (it shows nicely what all needed to be changed and where):
https://github.com/Hermann-SW/micropyth ... 192ab2a123


In case you just want to try without building MicroPython yourself, here is prebuilt firmware.uf2:
https://github.com/Hermann-SW/micropyth ... rmware.uf2


For building MicroPython for the Pico with USB networking from source
https://datasheets.raspberrypi.org/pico ... pdf#page=5

lwip submodule needs to be inited as well:
git submodule update --init -- lib/pico-sdk lib/tinyusb lib/lwip

I added fork mission statement as well:
https://github.com/Hermann-SW/micropyth ... -statement
Image


Pi4B with official display Screenshot:
Image
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

kevinkk525
Posts: 925
Joined: Sat Feb 03, 2018 7:02 pm

Re: Pico MicroPython with networking over USB

Post by kevinkk525 » Wed Apr 21, 2021 8:49 pm

This looks like a lot of development effort and it's great that it works, but I can't find a reason for this? Maybe you can explain it to me. What's the point of forwarding the network of a PC to the Pico? I could just do anything on the PC directly and any PC would be an expensive network adapter.

Why not use an Esp32 for the network?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

User avatar
pythoncoder
Posts: 5145
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pico MicroPython with networking over USB

Post by pythoncoder » Thu Apr 22, 2021 7:08 am

I may be wrong but my understanding of this project is that the Pico/ESP8266-01 combination hosts an HTTPS website on one core while running arbitrary Python code on the other. The Python side supports a REPL over UART for debugging. This could have plenty of applications.

As you say, I imagine you could do similar on an ESP32 using threading. The Pico solution may offer higher performance with processing shared between two cores and the ESP8266. The MicroPython architecture on ESP32 means that much of the work would be done on one core.
Peter Hinch

HermannSW
Posts: 180
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Pico MicroPython with networking over USB

Post by HermannSW » Thu Apr 22, 2021 7:15 am

kevinkk525 wrote:
Wed Apr 21, 2021 8:49 pm
Why not use an Esp32 for the network?
I connected ESP01 to Pico for enabling Pico to do HTTPS GET requests over ESP01's Wifi -- but that was not real networking between Pico and ESP01. See thread pointed to in my signature.
kevinkk525 wrote:
Wed Apr 21, 2021 8:49 pm
This looks like a lot of development effort and it's great that it works, but I can't find a reason for this? Maybe you can explain it to me. What's the point of forwarding the network of a PC to the Pico?
The point is to give Pico MicroPython networking, so that any usocket code will work on it as is.

The webserver is only there (as of now) as 3rd layer of testing [ ifconfig usb / ping 192.168.7.1 / curl http://192.168.7.1 ] .

When I will have usocket running with lwIP over USB, I will revisit the connected ESP01 and get hopefully "real" Wifi networking for the Pico.
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

User avatar
pythoncoder
Posts: 5145
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Pico MicroPython with networking over USB

Post by pythoncoder » Thu Apr 22, 2021 7:19 am

HermannSW wrote:
Thu Apr 22, 2021 7:15 am
...
The point is to give Pico MicroPython networking, so that any usocket code will work on it as is.
...
When I will have usocket running with lwIP over USB, I will revisit the connected ESP01 and get hopefully "real" Wifi networking for the Pico.
Light dawns :D
Peter Hinch

HermannSW
Posts: 180
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Pico MicroPython with networking over USB

Post by HermannSW » Thu Apr 22, 2021 7:48 am

pythoncoder wrote:
Thu Apr 22, 2021 7:19 am
Light dawns :D
I hope so :D

Can you help on MicroPython networking client examples (with and without ssl) only working with google. com?
viewtopic.php?f=15&t=10318
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

kevinkk525
Posts: 925
Joined: Sat Feb 03, 2018 7:02 pm

Re: Pico MicroPython with networking over USB

Post by kevinkk525 » Thu Apr 22, 2021 10:39 am


HermannSW wrote:
When I will have usocket running with lwIP over USB, I will revisit the connected ESP01 and get hopefully "real" Wifi networking for the Pico.
Awesome, that was the long term goal I was hoping for!
Would be great if you get lwip over uart using an esp01/esp8266/Esp32 working.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

HermannSW
Posts: 180
Joined: Wed Nov 01, 2017 7:46 am
Contact:

Re: Pico MicroPython with networking over USB

Post by HermannSW » Thu Apr 22, 2021 11:28 am

HermannSW wrote:
Thu Apr 22, 2021 7:48 am
Can you help on MicroPython networking client examples (with and without ssl) only working with google. com?
viewtopic.php?f=15&t=10318
I identified root cause -- Micropython network http[s] examples are too sloppy, most webservers need "Host" header presented.

I committed and pushed fix for both examples on my fork, for details see commit:
https://github.com/Hermann-SW/micropyth ... cf85fbb86d

Both examples now work with MicroPython Unix port as well as python3:
mp_corrected_examples.png
mp_corrected_examples.png
mp_corrected_examples.png (80.08 KiB) Viewed 470 times
Pico (USB) reboot/reflash tool
https://gist.github.com/Hermann-SW/ca07 ... 6d81de01a7

Pico HTTPS GET through ESP01 serial2wifi
viewtopic.php?f=21&t=10122

Wireless Pico Micropython REPL
viewtopic.php?f=21&t=10109

hippy
Posts: 15
Joined: Sat Feb 20, 2021 2:46 pm
Location: UK

Re: Pico MicroPython with networking over USB

Post by hippy » Tue May 04, 2021 1:12 pm

kevinkk525 wrote:
Thu Apr 22, 2021 10:39 am
Would be great if you get lwip over uart using an esp01/esp8266/Esp32 working.
Ultimately it will be great when 'lwip' is running on a Pico alongside MicroPython with the REPL available via USB Virtual Serial Port, supporting network interfacing via USB, ENC28J60 NIC, LAN8720 RMII PHY, UART+ESP and UART+SLIP - Ideally all, configurable at build time.

Currently there is proof of concept for all of that, nothing perfectly integrated with MicroPython so far, but I am sure it will come.

Post Reply