~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
lclev
Posts: 3
Joined: Fri Nov 15, 2019 7:30 pm

~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

Post by lclev » Sat Nov 16, 2019 3:22 am

I am trying to migrate from Arduino to pyboard 1.1, which I bought frm adafruit with micropython already installed. I am on Ubuntu 18,04 and am using python3.6.8, which is also new to me. I need to turn on and off two leds in a progressive sequence. This requires a simple for loop with one button to start loop and another to stop it. I have been able to get similar code to work by putting it in the main.py file.
However when i attempt to use $python pyboard.py flash.py I get the following message:~$ python pyboard.py flash1.py
python: can't open file 'pyboard.py': [Errno 2] No such file or directory. I do not see how to obtain this file.

In another approach, I created flash.py and copied it to the pyboard. Using os.listdir(), I can see the file on the pyboard. In the file is a finction with 4 time parameters, e. g. flasher(w,x,y,z,). My plan is to use repyl to import the flash.py file and to use flash.flasher(w,x,y,z) to control the leds with the variable time parameters. However, after importing machine and pyb, I tried to import flash.py I got the following message: File "<stdin>", line 1SyntaxError: invalid syntax.
any help would be appreciated.

lclev

User avatar
Roberthh
Posts: 1737
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

Post by Roberthh » Sat Nov 16, 2019 7:15 am

You can find pyboard.py here: https://github.com/micropython/micropyt ... ster/tools
And if the file flash.py exists on your device, you can load and start that with:

import flash

Since you purchased you device from Adafruit and it came with Python loaded, it is most likely their dialect, called circuitpython. That may behave a little bit different. With Micropython, you can as well type: import flash.py.

lclev
Posts: 3
Joined: Fri Nov 15, 2019 7:30 pm

Re: ~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

Post by lclev » Wed Nov 20, 2019 3:09 am

Thank you very much for your reply. I am still stuck with importing files from the pyboard into repl. Essentially, using os.listdir('/flash') I can see the file on the pyboard. When I try to import it, the file is not found. Here is the code from my terminal.

(base) william@william-HP-Compaq-Elite-8300-USDT:~$ rshell
Connecting to /dev/ttyACM0 (buffer-size 512)...
Trying to connect to REPL . connected
Testing if sys.stdin.buffer exists ... Y
Retrieving root directories ... /flash/
Setting time ... Nov 19, 2019 20:28:05
Evaluating board_name ... pyboard
Retrieving time epoch ... Jan 01, 2000
Welcome to rshell. Use Control-D (or the exit command) to exit rshell.
/home/william> cp vol.py '/flash/'
/home/william> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.11 on 2019-05-29; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>>
>>> import os
>>> os.listdir('/')
['flash']
>>> os.listdir('/flash')
['boot.py', 'main.py', 'pybcdc.inf', 'README.txt', 'myflash.py', 'myflash6.py', 'vol.py']
>>> import vol.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'vol.py'
>>> import machine
>>> import vol.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'vol.py'

vol.py contains a function definition for the volume of a sphere, which works ok in idle.
Any help on this problem would be greatly appreciated as it is critical for what we want to do, namely to control the board by passing parameters to a function using repl. Eventually, I would like to have a GUI programatically doing this.

Regarding pyboard.py, I have to learn how to download files from github. However, once I get the file, how and where do I copy the file to the pyboaard? Same as for vol.py above?

Finally, sometimes I cannot use rshell to connect to the board. The only way I have been able to fix this is to restart Ubuntu. Is this normal?

Thanks again for your help.

lclev

User avatar
jimmo
Posts: 883
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: ~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

Post by jimmo » Wed Nov 20, 2019 5:20 am

In Python (MicroPython and regular Python), if you have a file named foo.py, you import it with "import foo" (no .py on the end).

So you should be able to write "import vol".

pyboard.py is like rshell, it runs on your PC (they do a similar thing). But it looks like rshell is working for you, so maybe stick with that for now.

lclev
Posts: 3
Joined: Fri Nov 15, 2019 7:30 pm

Re: ~$ python pyboard.py flash1.py python: can't open file 'pyboard.py': [Errno 2] No such file or directory

Post by lclev » Thu Nov 21, 2019 5:48 pm

Thanks very much. The code is now working and I am racing forwards to the next bottleneck!

Cheers,

lclev

Post Reply