How can I put python files on a raspberry pi pico without using software like thonny - micropython

Is there a way for me to put python files (micropython to be specific) on the raspberry pi pico without using software like thonny where it does it for you, Is there a way to do it with bootsel?

With bootsel button you will not reach the storage for python scripts.
Using rshell will help. Inside rshell you will also reach REPL.

Related

HOW to setup Windows 10 + VSCode + pymakr for Python programming + Micropython + ESP-IDF for esp32?

I started several attempts to get this complex working. As mentioned in so many other discussions the micropython modules are not recognized, e.g. machine. Python modules like numpy were also not found.
I think, the python environment is not working correctly and the modules are there but not found. But, there is no recommendation or tutorial that really solves this. How can I set this up?
What I did so far:
manually installed all components according to tutorials
another way: installed the pything coding pack which contains a lot of stuff.
The Windows paths have the correct folder paths to the components.
I set the obviously correct python interpreter in vscode
connection/communication with board is working. I can set up codes which dont contain micropython modules.
in other IDE's like thonny/mu the modules are found.
I also installed a python venv: I could install numpy inside this venv and later it was found in vscode (wasn't found before) when I used the venv python as interpreter in vscode. But I wasn't succesful with micropython in venv.
PS: I can use the micropython modules like machine or network and upload the sketch to the esp32 board. It is working on the board. But I cant run any of the sketches in vscode. I think that Vscode uses cpython instead of micropython but shouldn't this be working after the installations I mentioned?
It sounds like you're confusing modules you install on the machine running Visual Studio Code and modules you install in Micropython on the ESP32.
They're totally separate.
Python on your Windows machine can use venv.
MicroPython doesn't use venv at all (there apparently is a clone of venv for MicroPython but it's not readily apparent what it does or why or how you'd use it). It is a completely separate instance of Python from the one on your Windows machine, and it doesn't operate the same way. Modules you install under venv won't be visible or usable by MicroPython. Numpy in particular is not available for MicroPython.
Many modules need to be written specially to work with MicroPython. MicroPython isn't running in a powerful operating system like Windows, MacOS or Linux. It's running in a highly constrained environment that lacks much of the functionality of those operating systems, and that has extremely little memory and storage compared to them. You can't expect that a module written for regular Python will just work on MicroPython (and likewise, many MicroPython modules use hardware features like I2C or SPI access that may not be available on more powerful, general purpose computers).
Only modules available with upip will be available for MicroPython. They'll need to be installed in the instance of MicroPython running on the ESP32, not in the instance of Python running under Windows. They're two, totally separate instances of Python.

Raspberry Pi Pico - How to install libraries using rshell and command line

I would like to use a DHT11 and I have downloaded the git repository for the library from Adafruit. I know how to add libraries using Thonny, but I am coding my Pico on a headless pi zero over ssh so I need a way to install libraries from the command line or rshell.
Do any of you know how to do this?
thanks!
The answer is to run rshel on the host rshell -p /dev/ttyACM0 --buffer-size 512 and then just copy the module to /pyboard/lib/. Then run repl and do a CTL + d to soft reboot the Pico.

Raspberry pi pico usb debbuging on Windows

I recently bought raspberry pi pico and I follow the How to get started with raspberry pico in C/C++ tutorial, but I have only windows computer. I want to debug my pico with usb. I compiled the example hello world project with cmake usb configuration (as shown in tutorial) and draged a usb/hello_usb.uf2 file to pico. Also there is a elf file for debugger, but I have no idea, what to do with it. Only thing about connecting pico usb stdout to computer, that I found in tutorials and datasheets is this command for minicom:
$ minicom -b 115200 -o -D /dev/ttyACM0
Unfortunately minicom is only available for Linux, but I found out what different parts of that command means:
Port: /dev/ttyACM0
Baud rate: 115200
-o means that minicom doesn't initial setup (I don't exactly know what it is)
And I tried to enter these informations to puTTY:
I tried a lot of other combinations of values that are not specified in that command (On screenshot is config for some arduino board, that I found), but I always just heard windows fail tone. All stuff I do and describe here might be wrong, I am a beginner, but I didn't found a good source of information about this.
Should I use something else (not puTTY)?
EDIT:
I got it! I did some mistakes during sdk setup and tinyUSB didn't work, so I couldn't even see pico in device manager. I did the whole setup again and everything works now. I also found video, how to connect pico via putty: https://youtu.be/BjGc60Mmwz8 . Also as aMike said, you have to type just com port to puTTY, not /dev/ttyACM0.
Thats not really debugging. Putty is just a serial monitor for getting printf() from your Pico device. For real debugging abilities (breakpoints, variable watch etc..) and to understand how those .elf files work, check this project.

How can you make a micropython program on a raspberry pi pico autorun?

I have used the software Thonny to send programs to my raspberry pi pico. I am trying to make a specific program auto run when my pico is plugged in. At the moment another program which is on the pico auto runs but I want another program to run instead.
Name the program you want to run main.py
Tested on Rpi Pico W, Ubuntu 22.04 host.
Command line approach
Install the MicroPython firmware.
Download the latest prebuilt firmware, it is a UF2 file:
non-W: https://micropython.org/download/rp2-pico/
W: https://micropython.org/download/rp2-pico-w/
Plug the Pi USB to computer while holding the BOOTSEL button.
A filesystem should appear on host.
Copy the file into the filesystem. On Ubuntu it automounts something like:
cp ~/Downloads/rp2-pico-w-20221014-unstable-v1.19.1-544-g89b320737.uf2 /media/$USER/RPI-RP2/
When flashing ends, the filesystem automatically unmounts, leaving you in non-boot mode. The firmware has been installed.
Install your program as main.py on the board.
Ensure the board is not in boot mode:
after installing firmware, this happens automatically
otherwise just unplug the USB and plug it back in without holding the BOOTSEL button
Install rshell on host:
python3 -m pip install --user rshell
Copy your program to the board as main.py. Supposing you have a blinker program at blink.py in the current working directory, run:
rshell -p /dev/ttyACM0 --buffer-size 512 cp blink.py /pyboard/main.py
/pyboard is a magic path to rshell, not actually present on the host. Terrible API!!!
This is what I tested with:
import machine
import time
led = machine.Pin('LED', machine.Pin.OUT)
# For Rpi Pico (non-W) it was like this instead apparently.
# led = Pin(25, Pin.OUT)
while (True):
led.on()
time.sleep(.5)
led.off()
time.sleep(.5)
The main.py thing is documented e.g. at: https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/9
Unplug and replug the USB without holding BOOTSEL. Every time you do this, the main.py program starts running automatically.
After installing, you can also use rshell to check the contents of main.py with:
rshell -p /dev/ttyACM0 --buffer-size 512 cat /pyboard/main.py
Bibliography:
https://forum.micropython.org/viewtopic.php?t=3610
https://forum.micropython.org/viewtopic.php?t=6005
https://forums.raspberrypi.com/viewtopic.php?t=301927
Thonny editor UI approach
This is the procedure described on the official docs at: https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico/0
It does the same steps as the CLI approach, but as usual with UIs making it more obscure what is actually happening behind the scenes :-)
Install Thonny:
python3 -m pip install --user thonny
Install the MicroPython firmware
Plug the Pico while holding BOOTSEL
Open Thonny from the command line:
thonny
I tested with version 4.0.1.
Click Python version on bottom right of the screen (bad UI)
Install MicroPython
MicroPython variant: Raspberry Pi Pico (choose W vs non W)
Install
Unplug the Pico, close Thonny, replug the Pico without BOOTSEL, reopen Thonny
Install your program as main.py on the board
Paste our blink.py on the main Thonny editor window
File > Save (or Ctrl + S)
A popup opens, choose: "Raspberry Pi Pico" (instead of "This computer")
Save the file as main.py on the Pico
Unplug USB and replug. main.py starts running.

Raspberry Pi Pico - Flashing program using Macbook

I am trying to load a program on a Raspberry Pi Pico. Have loaded the standard blink program on it using USB connected to my Macbook and used Thonny to run and stop the program.
However if I disconnect the Raspberry Pi Pico, from the USB, the program disappears. I found this video (https://www.youtube.com/watch?v=IMZUZuytt7o) that shows how to make it work with a windows system, but if I try the same with Macbook does not work. It gets stuck at Trying to connect to REPL
Can someone suggest how we can flash the program on the Raspberry Pi Pico so that it stays whenever we connect it to power?
Here is the program I tried
import machine
import utime
led_onboard = machine.Pin(25, machine.Pin.OUT)
while True:
led_onboard.value(1)
utime.sleep(1)
led_onboard.value(0)
utime.sleep(.5)
I tried using the suggested RShell solution using pip install rshell. However it does not seem to work on macbook very well when it comes to copying the program to the pico. So I tried an alternate REPL writer called ampy
To install ampy follow the guide on https://github.com/scientifichackers/ampy
pip install adafruit-ampy
In your shell go to the folder where the program is stored. Keep the file name as main.py
Run ampy using the command
ampy -p /dev/cu.usbmodem0000000000001 put main.py
The format is
ampy –p [USB-Port] put [file to copy]
The file is now copied into the board.
Now if you unplug and re-plug the power source the program in main.py would execute.