EduardH
Posts: 63
Joined: Fri Sep 04, 2015 8:10 am

How to pass a few parameters to a pico

Tue Aug 16, 2022 1:49 pm

Good afternoon,

Is there a way to input a few parameters into the pico without recompiling the program? Perhaps by means of a .txt file that can be uploaded to the pico?

In this application the program never changes. In one year a few parameters have to be updated at most 2 times. Mostly no update should be necessary. The end user has no or little programming skills. De pico has no display and neither a keyboard. Uploading a file from a pc by means of the button on the pico is possible.

Is there an easy solution to this question?

Sincerely,

Eduard

bgolab
Posts: 405
Joined: Sat Jan 30, 2021 12:59 pm
Location: Krakow, Poland

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 2:11 pm

USB? And periodically check the USB input for the command from PC-USB to initiate the process of entering the required data to update?

Papa G
Posts: 15
Joined: Thu Oct 18, 2012 5:21 pm
Location: Dallas, TX

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 4:00 pm

You mention recompile. Does that mean that your program is a C/C++ program?
If it is a MicroPython script, it would be easy to include the parameters that need to be periodically changed in a .txt file that is read when the program starts. Then it might be possible for the end user to drop an updated .txt file into the Pico using the REPL.

I'm not familiar enough with the UF2 binary format to know if you can add a .txt file to it without reformatting. If you can then the end user could load a new UF2 as you suggested with the button.

If it is practical to add a micro SD card to the Pico, that would solve the problem as the program could update itself from the SD card whenever needed.

MatSOBDev
Posts: 76
Joined: Wed Jul 06, 2022 7:25 am

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 4:29 pm

Prepare some program and add text you can find in *.uf2 file and open it in hex editor and search for it. Maybe it is possible to change it and uf2 has no build in feature to validate data. If yes, yoi can make changes not in *.uf2 but *.hex *.elf file and bake it with uf2 tool - inside project folder should be that program that is compiled when you make project. But that way it should be programmed to use this feature ex. you have string with max length and you put shorter text there so program should cut to desireg lenght so no garbage text ex. not aligned properly will be displayde on the screen and so on.

alastairpatrick
Posts: 349
Joined: Fri Apr 22, 2022 1:39 am
Location: USA

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 7:27 pm

It's relatively easy to interface a Pico to an SD card reader. You could put a configuration file on an SD card and have the Pico read it each time it boots. Bonus feature: you can configure the Pico remotely by means of sending an SD card to the user by snail mail.

Edit: As an an alternative approach, here's an example of implementing a USB mass storage device using TinyUSB.

sonnybalut
Posts: 29
Joined: Fri Apr 17, 2015 2:57 am

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 7:54 pm

Here is a link for i2c eprom, there is a micropython example on one of the tabs https://electricdollarstore.com/eprom.html

dthacher
Posts: 463
Joined: Sun Jun 06, 2021 12:07 am

Re: How to pass a few parameters to a pico

Tue Aug 16, 2022 9:17 pm

MCP2221 using I2C mode. Build host application using HID library. Given them USB adapter. I2C is nice for configuration because you can clock stretch. This is not possible UART. However, UART would also work with careful protocol design. Note you do not need to use MCP2221 for this.

In summary use I2C/UART adapter to host program. This host program should be portable so something like QT/Java/Groovy would be recommended.

With I2C you could potentially disconnect the configuration interface and there would be not complications. UART would also work the same. USB may be a little fickler, but I do not know that for sure. These interfaces will also interface with Pi, RP2040, etc.
There is more I could say here but I am going to leave it at this. Till the world is not a complete waste of time.

memjr
Posts: 2109
Joined: Fri Aug 21, 2020 5:59 pm

Re: How to pass a few parameters to a pico

Wed Aug 17, 2022 12:26 am

Can you use a pico W?

If so, you can have it so when a button is pressed, the pico starts an AP, the user connects to it and opens a web page where your parameters are entered and the pico then saves those parameters (so it can reuse them later if a restart is needed at some point) and start using them right away. It can the turn of AP mode until user presses button again.

EduardH
Posts: 63
Joined: Fri Sep 04, 2015 8:10 am

Re: How to pass a few parameters to a pico

Fri Aug 19, 2022 6:45 am

Good morning,

Thanks for your help. Because I don't like to add additional devices or use another board, the answer of MatsSOBDev was my first trial. Before modifying the uf2 file I have read some information on wikipedia about the uf2 format. Checksum is on optional feature. It looks like that feature isn't set on the pico. If you take an uf2 file and edit some hex values near the middle of the file with the Bless editor the file is stored as usual. It was not possible to add numbers but changing a lot of values is possible. I didn't touch the kernel of the program. After changing a lot of values, the blinking led on the pico still flashes as before.

Sincerely,

Eduard

Return to “General”