dhylands / rshell

Remote Shell for MicroPython
MIT License
913 stars 130 forks source link

Add install/setup/troubleshooting instructions for Windows and WSL 2 #189

Open fabianmuehlberger opened 2 years ago

fabianmuehlberger commented 2 years ago

I recently picked up a Pi Pico and started programming in Thonny. Having my development environment in Windows 10 and WSL2 Ubuntu2204 I soon tried to move from Thonny, resulting in a few hours of troubleshooting.

To get rshell to run under Windows Terminal, I had to install pyreadline3, because of

AttributeError: module 'collections' has no attribute 'Callable'

when running rshell --port COM6.

On WSL 2, I ran into a few issues:

  1. accessing the COM Port is not natively supported under WSL 2. This can be done via usbipd
    • the port will show up as /dev/ttyACM* in my case ttyACM0 or ttyACM1
    • It is important that chmod a+rw /dev/ttyACM[x] is set
  2. Unplugging the device loses the connection in WSL and it has to be attached again, including setting the correct permissions.
  3. running rshell in WSL 2 resulted in:
    rshell
    Connecting to /dev/ttyACM0 (buffer-size 128)...
    Trying to connect to REPL Traceback (most recent call last):
    File "/home/fabian/.local/bin/rshell", line 8, in <module>
    sys.exit(main())
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/command_line.py", line 4, in main
    rshell.main.main()
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/main.py", line 3099, in main
    real_main()
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/main.py", line 3065, in real_main
    autoscan()
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/main.py", line 332, in autoscan
    connect_serial(port[0])
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/main.py", line 1415, in connect_serial
    dev = DeviceSerial(port, baud, wait)
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/main.py", line 1734, in __init__
    data = pyb.read_until(1, b'>>> ', timeout=0.1)
    File "/home/fabian/.local/lib/python3.10/site-packages/rshell/pyboard.py", line 165, in read_until
    data = self.serial.read(min_num_bytes)
    File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 595, in read
    raise SerialException(
    serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

    this issue seems to originate from running Thonny before using WSL to access the device. This can be resolved by connecting to the Pico with rshell using Powershell one time before handing over the COM port to WSL with usbipd .

I hope this helps others get the rshell run on Windows and WSL2 quicker.

Best Fabian

mister-samsonite commented 3 months ago

Thank you Fabian. I was getting the AttributeError you mentioned and your solution helped me out.