Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

cannot run example "display_text_pyportal.py"
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

cannot run example "display_text_pyportal.py"

by butchalline on Sun Mar 29, 2020 6:26 pm

Mu ver. 1.0.2 CP, libs and examples are Ver. 5
I am trying to run the example "display_text_pyportal.py" which was ‎created on Friday, ‎January ‎17, ‎2020, ‏‎5:20:24 PM
Example loads into Mu. Check reveals "line too long..."
Save produces nothing on PyPortal, no errors or feed back of any kind.
Resetting PyPortal does not help.
What am I doing wrong?
Are there any "known good" examples that I can try?
Thanks for any and all help...

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Re: cannot run example "display_text_pyportal.py"

by dastels on Mon Mar 30, 2020 9:10 am

Are you saving to the PyPortal? Or just back where you loaded the code from?

Dave

dastels
 
Posts: 2829
Joined: Tue Oct 20, 2015 3:22 pm

Re: cannot run example "display_text_pyportal.py"

by butchalline on Mon Mar 30, 2020 6:55 pm

I open the Mu editor and press "load" which brings up CIRCUITPY(F:)
Then I select examples > display_text_pyportal
The code appears in the editor. I make no changes to the code.
Then I tap "save" because the tutorial says " Save the file. That's it! Your code changes are run as soon as the file is done saving."
When I tap "save" nothing happens.

If I look at F:\code, I see a previous example, but not display_text_pyportal

If I reset the PyPortal the display shows code.py output:
If I tap save in the editor, the display shows the following twice:
Code done running. Waiting for reload.
soft reboot
code.py output
:

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Re: cannot run example "display_text_pyportal.py"

by dastels on Mon Mar 30, 2020 7:27 pm

A couple questions.

Which tutorial?

When you click "save" what does it say at the bottom of the window? Starting with "Saved file:"

Dave

dastels
 
Posts: 2829
Joined: Tue Oct 20, 2015 3:22 pm

Re: cannot run example "display_text_pyportal.py"

by butchalline on Tue Mar 31, 2020 11:53 am

I am trying to follow the Adafruit tutorial here:
https://learn.adafruit.com/adafruit-pyportal/creating-and-editing-code

Upon saving, bottom line very briefly displays:
saved file: F:\examples\display_text_pyportal.py

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Re: cannot run example "display_text_pyportal.py"

by dastels on Tue Mar 31, 2020 12:43 pm

OK, you need to save it as F:/code.py since anything else (other than as detailed at the very end of the page you linked) won't be loaded and run. In your case F;/examples/display_text_pyportal.py will be completely ignored. You need to copy that file to F;/code.py AND make sure you have the required libraried in F:/lib

Dave

dastels
 
Posts: 2829
Joined: Tue Oct 20, 2015 3:22 pm

Re: cannot run example "display_text_pyportal.py"

by butchalline on Tue Mar 31, 2020 6:14 pm

Thanks for hanging in with me Dave.
You said " you need to save it as F:/code.py since anything else (other than as detailed at the very end of the page you linked) won't be loaded and run. In your case F;/examples/display_text_pyportal.py will be completely ignored"

I understand this concept, but I do not see how it can be done in the Mu editor (which is supposed to be simple to use in Adafruit mode)
On this page of the Mu tutorial: https://codewith.mu/en/howto/1.0/create_load_save , it says that "If you want to create a newly named copy of the current file you can rename it by clicking on the filename in the file's tab in Mu." This does not happen for me. I cannot figure out how to save the currently displayed file under another name.

I got out of Mu and went to f:\... and and delete the contents of code.py then copy the contents of display_text_pyportal.py into the empty code.py file.
if I open Mu and load the new code.py and "save" it, I get a lot of display flashing (which I assume is the tutorial). If I radically change the sleep times, I get the same display flashing.
So...

1. Do you use Mu? If so, how do you rename the currently displayed file?

2. Do I really have to copy every example code into code.py ? Shouldn't examples run on their own like the Arduino IDE?

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Re: cannot run example "display_text_pyportal.py"

by dastels on Tue Mar 31, 2020 7:01 pm

I do not use Mu. It's handy for editing a python file and saving it back where it came from. So you can drag & drop a file onto CIRCUITPY (F: in your case) and rename it to code.py. Then you can load it in Mu, work on it, and save it back. The downside of that is that the only copy of your code is on the board. I advise copying it somewhere else as a backup.

I believe clicking on the tab lets you rename the file, but not change where it is stored. I.e. where it will be saved to when you click Save.

The big difference between working in Arduino and CircuitPython is that you compile your program to a single machine code file when you use Arduino and it replaces "everything" (except the bootloader) on the board. CircuitPython, on the other hand lets you copy source code files (and precompiled mpy files for libraries) onto the flash file system. When the board powers on, gets reset, or you force it to reload by pressing CTRL-D at the REPL prompt, it looks for a file named code.txt, code.py, main.txt and main.py. The first one it finds is loaded, compiled, and executed. If it can't find any of those, it does nothing.

Now. when you do load code.py from CIRCUITPY (or F:), edit it a bit, and save it back to CIRCUITPY (or F:), CircuitPython notices and restarts. I.e. it looks for a file to load (as above), loads and executes one it it finds it. So you can edit and save and it will automatically get reloaded and rerun. At that point to have similar functionality to using Arduino. As I said, the catch is that you don't have code stored somewhere "safe". If the board file system gets corrupted you loose your code. That's why it's a good idea to make a copy every so often.

I work the other way. around I have the code on by workstation's harddrive, edit and save it there, then copy it to CIRCUITPY when I want to run it.

To run examples, yes, they have to be copied to CIRCUITPY/code.py.

Also, be sure you only have one of those 4 files (listed above) on CIRCUITPY so there's no confusion about what will get loaded.

Dave

dastels
 
Posts: 2829
Joined: Tue Oct 20, 2015 3:22 pm

Re: cannot run example "display_text_pyportal.py"

by butchalline on Wed Apr 01, 2020 10:16 am

Thanks for your help, Dave, but I am giving up and going back to the "devil I know" - Arduino ;-(

When the example is loaded into Mu and I make NO changes and I:
1. Tap check, I get two "Line too long..." errors. Which I understand from other sources is not a critical error.
2. Tap save, on the display I get ...traceback... ValueError: max_size must be >=1
3. The neopixel flashes many colors but I do not see any code that would do this.
4. I do NOT see any different fonts or display fading which the code suggests to me.

This is more and exercise in frustration than an example...

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Re: cannot run example "display_text_pyportal.py"

by dastels on Wed Apr 01, 2020 12:08 pm

The "flashing many colors" indicates a runtime error either in compiling or running the code. The sequence of flashes/colors indicate the line the error occurred on.

So what's max_size set to? That seems to be the problem. Does it say what line?

Dave

dastels
 
Posts: 2829
Joined: Tue Oct 20, 2015 3:22 pm

Re: cannot run example "display_text_pyportal.py"

by butchalline on Wed Apr 01, 2020 4:24 pm

Yes, I know that the flashing neopixel indicates an error.

My point is that an example should work without error.

Thanks for your help, but I am no longer using the PyPortal.
case closed.

butchalline
 
Posts: 32
Joined: Sat Oct 13, 2012 6:21 pm

Please be positive and constructive with your questions and comments.