I was trying to figure out how to make code persist on the pico and stumbled upon ampy. When trying to flash my pico, I was met with an error (exact output below). I'm guessing it might be something permission related but I really don't know if that's the case. For clarity, I'm using git bash as my shell on Windows 11 and I write my code with VScode (in case it makes any difference). I flashed the pico with a .uf2 from this site beforehand.
First, (after installing circuitpython) I used ampy -p COM4 ls
to see if 1. circuitpython is correctly installed and 2. if it connects to my PC properly. I got the following output:
$ ampy -p COM4 ls
/.Trashes
/.fseventsd
/.metadata_never_index
/System Volume Information
/boot_out.txt
/code.py
/lib
/settings.toml
It seemed like it did at least something,so I figured it was alright. Then I wrote this simple script to see if the installation truly succeeded.
import board, time
import digitalio as Pin
led = Pin.DigitalInOut(board.LED)
led.switch_to_output()
while(1):
led.value = True
time.sleep(0.25)
led.value = False
time.sleep(0.25)
Afterwards I used ampy -p COM4 run main.py
and it worked flawlessly. I was quite happy at that point but my enthusiasm was very short lived. That's for I tried ampy -p COM4 put main.py
in order to achieve my goal of persistent code. The command returned the following:
$ ampy -p COM4 put main.py
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Scripts\ampy.exe\__main__.py", line 7, in <module>
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1157, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\ampy\cli.py", line 264, in put
board_files.put(remote, infile.read())
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\ampy\files.py", line 214, in put
self._pyboard.exec_("f = open('{0}', 'wb')".format(filename))
File "C:\Users\Dell\AppData\Local\Programs\Python\Python311\Lib\site-packages\ampy\pyboard.py", line 279, in exec_
raise PyboardError('exception', ret, ret_err)
ampy.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 1, in <module>\r\nOSError: [Errno 30] Read-only filesystem\r\n')
I know the serial port is correct and isn't used by anything else, since the run
command, did in fact run. It also can't be a circ-python installation issue for the same reason (unless it is then something is must be only partially borked). It's not the cable either for the exact same reason. (I know it might be obvious but I want to be sure I included everything I could)
I couldn't find anything about it online (that would help), nor do I understand this error message. Any and all help will be appreciated. I will also try to provide any further information if required.
Turns out that for me the solution is as simple as copying my code as code.py
directly onto the board (the automatically connecting CIRCUITPY drive) instead of using ampy.