Outils pour utilisateurs

Outils du site


issue197:micro-ci_micro-la

Ceci est une ancienne révision du document !


Greetings yet again, my fellow beings. I come to you again, beaming across the Ether.

For a few months now, I've been wanting to discuss a program called rshell written by Dave Hylands, or better known to the MicroPython community as dhylands. Back in 2015, he released the very first version of rshell to connect to the pyboard microcontroller. In his words “rshell allows you to copy files to and from the pyboard's file system, show the contents of files, and to use the repl.”

There is a lot that this little program can do, and I use it off and on – mainly to do bulk file copies to and from my various Microcontrollers. So far, I've used it on ESP8266, ESP32, Wio Terminal and of course my RPi Pico/Pico-W boards. It's a really easy way to move files back and forth and you can do a whole lot more.

So, let's look at rshell in the real world.

First, you need to install it, and since it's written in Python, we can use pip/pip3.

pip3 install rshell

Once we have rshell installed, we'll use it to back up one of our Microcontrollers, in my case one of my RPi Pico-W boards.

In a terminal (you can use the same one that you use to install rshell), you need to go to your Micropython backup folder. Don't have one yet? So make one. I have one for each of my main board types. In my case, it's on my desktop as “Pico-W”. I create a sub-folder each time I back up a board by date, and if I need to back up different boards on the same day, I create additional folders within that day's folder.

Now, connect your board to your usb port and make sure you know where it is. Use

ls /dev/tty*

to find it.

So, shown above, mine is on /dev/ttyACM0, which is where any of my RPi Pico boards almost always show up.

Now startup rshell (shown below).

Now we are connected. Let's verify what's on the Pico. Notice that rshell displays the root directory when you get connected, but I like to use the “ls” command just to verify. When you start up rshell, the microcontroller you are connected to is mounted as /pyboard. So we need to use the command ‘ls /pyboard’ (previous page, top).

Now we are in the REPL shell. You can run Micropython commands directly from the shell, one line at a time. We’ll type in a short program that will allow us to toggle the onboard LED.

from machine import Pin
led = Pin(“LED”, Pin.OUT)
led.toggle()
led.toggle()

To leave the REPL, type <Ctrl>X.

^X

/home/greg/Desktop/Pico-W/backoffs/PicoW09092023>

If you are not in the REPL, you can use cat to view the contents of a file (next page, bottom right).

Now go back to the REPL and we can update the MicroPython version with the “latest and greatest” version. You have to download the newest version from the MicroPython.org site. The latest nightly build, as I'm writing this, is v1.20.0-450 built on 2023-09-06. Save it somewhere convenient and go back to the REPL in your terminal. You can use the REPL command “machine.bootloader()” to put the board into the bootloader mode. Note that your terminal might seem to “freak out”, but that’s normal. I’ve reformatted the terminal output for ease of viewing (top right).

Once you have this, press <Enter> in the terminal and you will receive the original prompt again.

serial port /dev/ttyACM0 closed

/home/greg/Desktop/Pico-W/backoffs/picoW_sep06_2023>

Then re-enter the REPL (middle right).

That's it. You've successfully updated your MicroPython version without having to go through the normal “unplug | hold down the bootsel button | plug in” process.

If you don't want to keep using “pyboard” as the name of your board, you can name your board whatever you wish.

/home/greg/Desktop> echo 'name=“pico”' > /pyboard/board.py

/home/greg/Desktop>

You have to use <Ctrl>C to disconnect and then reconnect rshell to get this to take effect (next page, top right).

From now on (as long as the board.py file exists on the microcontroller), you can use “pico” to refer to the board instead of “pyboard”.

What’s in the “magical” board.py file? Actually, very little. We’ll use cat to look at the file contents.

/home/greg/Desktop/Pico-W/backoffs/PicoW09092023> cat /pico/board.py

name=“pico”

I prefer to keep the mount point at /pyboard, since I use rshell with my RPi Pico boards (both plain and W), my ESP8266 boards, my ESP32 boards, and my WIO terminal. Trying to remember to use a different board name each time is a bit beyond the capabilities of my old brain.

If you need to edit a file on the microcontroller (now named pico in my case), you can use the command “edit /pico/{filename}”. We’ll try editing the ‘i2cscan.py’ file.

We are now in a vim editor. Any changes that you want to save, press <esc> then “:wq”. If you didn’t make changes, you can exit by pressing <esc> then “:qa”.

Finally, to quit rshell, use <Ctrl>C.

That’s about it. You can go to the rshell github repository (https://github.com/dhylands/rshell) to find all the possible commands you can use.

Until then, as always; stay safe, healthy, positive and creative!

issue197/micro-ci_micro-la.1696088550.txt.gz · Dernière modification : 2023/09/30 17:42 de auntiee