Wireless Pico Micropython REPL

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

Wireless Pico Micropython REPL

Post by HermannSW » Sun Mar 21, 2021 8:52 pm

Details and animations in this thread:
https://www.raspberrypi.org/forums/view ... 6&t=307527

Basically ESP01 with flashed WiFiTelnetToSerial ESP8266 Arduino demo allows for wireless telnet session into Pico REPL:
Image


Sample telnet session:
Image
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

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

Re: Wireless Pico Micropython REPL

Post by HermannSW » Mon May 03, 2021 11:01 am

There was a problem with the solution, at the time I posted the up/down keys for accessing MicroPython history did not seem to work.

I have Pi4B and Pico here in hospital, but no ESP[01].
So I looked for another network to serial code that could be run on Pi4B for testing.
I did find that code (to be run with python3) from pyserial repo:
https://github.com/pyserial/pyserial/bl ... edirect.py

This is how to start on default port 7777:

Code: Select all

$ python3 tcp_serial_redirect.py /dev/serial0 115200
--- TCP/IP to Serial redirect on /dev/serial0  115200,8,N,1 ---
--- type Ctrl-C / BREAK to quit
Waiting for connection on 7777...

I tried netcat (nc) command, but that did not work.
After "sudo apt install telnet", telnet did work:

Code: Select all

$ telnet 127.0.0.1 7777
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.


>>> import os
import os
>>> os 
os
<module 'uos'>
>>> 

MiocroPython REPL worked fine, besides the fact that input was echoed on first response line:

Code: Select all

>>> os.listdir()
os.listdir()
['catalan.py', 'string.mpy']
>>> 

Next I tried "up" key and it worked as well (one time as well as pressed two times), as can be seen by echoed line:

Code: Select all

>>> ^[[A   
os.listdir()
['catalan.py', 'string.mpy']
>>> ^[[A^[[A
os
<module 'uos'>
>>> 

Even down key works, in example after two "up" keys does last command again:

Code: Select all

>>> ^[[A^[[A^[[B
os
<module 'uos'>
>>> 

So it is not that history commands don't work, but that:
  1. input gets echoed on next line
  2. only after pressing enter, not on pressing up/down keys

Next need to see how to see echoed input on pressing up/down keys, and how to make sure that cursor will be at correct place (after REPL prompt).


P.S:
Left cursor key works as well:

Code: Select all

>>> ^[[A
os
<module 'uos'>
>>> ^[[A^[[D^[[Du
uos
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'uos' isn't defined
>>> 
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

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

Re: Wireless Pico Micropython REPL

Post by HermannSW » Sun Nov 14, 2021 7:19 pm

I learned today that the problem cause is telnet running in linemode by default.
Needed is character mode.
Sequence is
  1. telnet esp8266IPaddress
  2. ENTER
  3. CTRL+ALT+]
  4. "mode character"+ENTER (this ends in REPL raw mode)
  5. CTRL-B
After that WifiToSerial.ino on ESP8266 does what it should, with working cursor keys!
Peek_2021-11-14_15-20.gif
Peek_2021-11-14_15-20.gif
Peek_2021-11-14_15-20.gif (130.27 KiB) Viewed 8910 times

Why did I look into this after some time?
For remote MicroPython REPL of my RP2040 Pimoroni Tiny2040 microcontroller on top of Tiny2040bot:
https://forums.raspberrypi.com/viewtopi ... 0#p1937856
Image
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

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

Re: Wireless Pico Micropython REPL

Post by HermannSW » Sun Dec 05, 2021 9:55 pm

I have built more bots, top from left: Tiny2040bot, Picobot, Toycarbot
bottom from left: Pico4MLcbot, Tinier2040bot (not completed, will be 19.7×14.8×18.6mm w×l×h):
20211205_220712.15%.jpg
20211205_220712.15%.jpg
20211205_220712.15%.jpg (25.35 KiB) Viewed 8670 times

Tiny2040bot and Picobot have ESP8266 model ESP-01 with WifiToSerial.ino example for wireless RP2040 MCU MicroPython REPL access. Pico4MLcbot has ESP8285 model ESP-1 (similar to ESP-01, here without headers) for same purpose.

It is clumsy to connect the RP2040 MCUs with micro USB for uploading new MicroPython files. And with wireless REPL access, wireless put/get of RP2040 MCU files should be possible.

I learned that Python telnetlib allows to access the Picos via the ESP8266/ESP8285. Tried to see how webrepl does file upload, but that has a server component. So I looked at ampy, that I know for file transfer over USB or serial. I was really surprised to see telnetlib used in ampy. I learned that ampy decides to use telnet for a "port" that starts and ends with a digit, and has exactly 3 dots. Fine, but that did not work. Reason was that ampy passes username and password into the telnet session for login. There is no login in WifiToSerial.ino nor on Pico MicroPython. So I did fork ampy, removed the username and password code, updated README.md with fork mission statement and install command:
https://github.com/Hermann-SW/ampy#fork ... eplacement


After ampy now works for ESP8266/ESP8285 WifiToSerial.ino requirements, there is no need to use USB port anymore. Because of that I was able to superglue red DRV8833 motor controller board on Pico4MLcbot back as it was planned initially, although now the short cables from the motors to motor controller now make it impossible to connect USB-C cable to Pico4ML MCU.
Pico-W Access Point static file webserver:
https://github.com/Hermann-SW/pico-w

Tiny MicroPython robots (the PCB IS the robot platform)
viewtopic.php?f=5&t=11454

webrepl_client.py
https://github.com/Hermann-SW/webrepl#webrepl-shell

Post Reply