Shop OBEX P1 Docs P2 Docs Learn Events
Micropython for P2 - Page 7 — Parallax Forums

Micropython for P2

145791013

Comments

  • come on @"David Betz" indentation. Pfft.

    Do you really write Code without?
    if (something) {
    do;
    some;
    stuff;
    }else{
    do;
    some;
    other;
    stuff;
    }
    
    instead of
    if (something) {
       do;
       some;
       stuff;
    }else{
       do;
       some;
       other;
       stuff;
    }
    

    Mike
  • msrobots wrote: »
    come on @"David Betz" indentation. Pfft.

    Do you really write Code without?
    if (something) {
    do;
    some;
    stuff;
    }else{
    do;
    some;
    other;
    stuff;
    }
    
    instead of
    if (something) {
       do;
       some;
       stuff;
    }else{
       do;
       some;
       other;
       stuff;
    }
    

    Mike
    No, of course not. One of my biggest objections to using indentation for block structure was the non-standardized size of tabs. I think Python can be configured to not allow tabs in source code. That pretty much solves the problem for me.

  • I've updated the first post with a new micropython binary. This one detects the hardware available at run time and adjusts the USB and VGA drivers accordingly, so the same binary should work correctly with all features on both the original P2-ES silicon and on the new boards which are being made now. The pye.py editor included in the .zip file can run on the P2 itself, so you can use it from within micropython to edit files which micropython then loads. I put pye.py on an SD card and then at run time do:
      from pye import pye
      pye('myfile.py')
    
    Enter the python code you want to run, save with Control-S and quit with Control-Q, then enter:
    execfile('myfile.py')
    
    to run it. This can all be done on the P2 itself using the USB keyboard and an attached VGA monitor (the USB board should be on pin group 16, the VGA on pin group 48). The file is saved on the SD card, so you don't have to re-enter it. If you set the upython.binary up as a boot file on your SD, or put it into the flash and configure to boot from flash, then you'll have a stand-alone development system.

    The micropython sources used to build this are checked in to my github repository.
  • Oh, one thing to watch out for on the new P2 boards -- make sure the "ACC HDR 5V" jumper is installed (it's near the PC USB connector). If it isn't then the USB keyboard won't work.
  • Cluso99Cluso99 Posts: 18,066
    edited 2019-11-05 19:39
    Excellent work Eric. I’ll take a look as soon as i get some spare time. Been so busy at work lately :(
    FWIW I’ve mostly been programming in Python at work for the past few months so micropython should be a breeze ;)
  • Is it possible to use micro python over a serial link to the P2 or is it only setup for VGA/keyboard?
  • David Betz wrote: »
    Is it possible to use micro python over a serial link to the P2 or is it only setup for VGA/keyboard?

    Yes, Erics code also supports serial @230400 baud.
  • David Betz wrote: »
    Is it possible to use micro python over a serial link to the P2 or is it only setup for VGA/keyboard?

    As Brian has mentioned serial is supported at 230400 baud (input comes from both serial and USB, and output goes to both serial and VGA). I've updated the first post with a brief description of how to get started, although that is also covered in the README.
  • ersmith wrote: »
    David Betz wrote: »
    Is it possible to use micro python over a serial link to the P2 or is it only setup for VGA/keyboard?

    As Brian has mentioned serial is supported at 230400 baud (input comes from both serial and USB, and output goes to both serial and VGA). I've updated the first post with a brief description of how to get started, although that is also covered in the README.
    Thanks! I'll give it a try on my P2-Eval board. It's nice that it supports VGA and USB keyboard but I don't have enough space on my desk for another monitor and keyboard.

  • Cluso99Cluso99 Posts: 18,066
    edited 2019-11-06 19:56
    David Betz wrote: »
    ersmith wrote: »
    David Betz wrote: »
    Is it possible to use micro python over a serial link to the P2 or is it only setup for VGA/keyboard?

    As Brian has mentioned serial is supported at 230400 baud (input comes from both serial and USB, and output goes to both serial and VGA). I've updated the first post with a brief description of how to get started, although that is also covered in the README.
    Thanks! I'll give it a try on my P2-Eval board. It's nice that it supports VGA and USB keyboard but I don't have enough space on my desk for another monitor and keyboard.
    You need a bigger desk :wink:

    I know what you mean tho. I have 3 24” monitors on my desk plus a keyboard mouse and speakers. At least the PC is on the floor.

    Never had that problem in the old house as I had a home made desk 4ft (1.2m) deep and 20ft (6m) long - we built the house with a “big” home office in ‘83. The computer was in one of the garages - it was the length of the garage with its own a/c. Those were the days... :smiley:

    Back to topic...
    I just have to give micropython a try. Need more time :(
    Maybe when we go to metric time - 100 hours/day, 100 minutes/hour???
  • Cluso99 wrote: »
    You need a bigger desk :wink:
    I have a bigger desk but it is in the basement. I've gotten spoiled using my small desk in the family room.
  • evanhevanh Posts: 15,126
    edited 2019-11-06 20:54
    Cluso99 wrote: »
    Maybe when we go to metric time - 100 hours/day, 100 minutes/hour???
    That always has been a pointless endeavour. The calender is suited to Earth's spin and orbit. The day changes length as the planet spin slows down - solely from tidal drag I think - pushing the moon further away in the process. The number of days in a year is not only at odds with any attempts to square it up but is also going to be a reducing number as the days get longer.

    Funnily, the length of the year, on average, is a lot more constant than the day.
  • Cluso99Cluso99 Posts: 18,066
    evanh wrote: »
    Cluso99 wrote: »
    Maybe when we go to metric time - 100 hours/day, 100 minutes/hour???
    That always has been a pointless endeavour. The calender is suited to Earth's spin and orbit. The day changes length as the planet spin slows down - solely from tidal drag I think - pushing the moon further away in the process. The number of days in a year is not only at odds with any attempts to square it up but is also going to be a reducing number as the days get longer.

    Funnily, the length of the year, on average, is a lot more constant than the day.
    Yes, the catch is that the day would need to be 100 hours to make it work properly. And then all our scientific calculations based on the second would be a disaster.

  • evanhevanh Posts: 15,126
    edited 2019-11-06 22:05
    The "second" could have been any period, but there is always going to be leap seconds to fit the calendar. And, eventually, there is going to be more than 86401 seconds per day.
  • Back to MicroPython:

    I downloaded the latest release and it is working on my P2-Eval board. Thanks, Eric!
  • David Betz wrote: »
    Back to MicroPython:

    I downloaded the latest release and it is working on my P2-Eval board. Thanks, Eric!

    Great, glad it's working for you!

    I've thought of putting a "run micropython" button in flexgui, but I'm not sure how useful it would be. Maybe a different GUI (based on some of the other micropython runners) would be helpful though?
  • Cluso99 wrote: »

    Never had that problem in the old house as I had a home made desk 4ft (1.2m) deep and 20ft (6m) long

    Wow now that's what I need. My desk/bench is 2.4m wide and I somehow have 6 monitors (2x24"LCD + 1x30"LCD + 1*21" CRT + two laptops) plus a scope on it. It's chockers. Cable nightmare. I need to go vertical.
    :lol:
  • I can't remember who it was here but someone had the idea of a 'slow desk conveyor' - you'd need to keep moving your relevant projects across to the right... anything neglected for too long would automatically fall off the left edge of the desk conveyor, thus keeping everything on top of the desk relevant
  • Is it possible to stop a Python program from running from the shell? I tried control-c but that didn't seem to work.
  • David BetzDavid Betz Posts: 14,511
    edited 2019-11-07 02:37
    I plugged the LED matrix module into my P2-Eval board at the P56 position and after that I was unable to load MicroPython. When I removed the module I was able to load successfully. Any idea why that might have happened? Is there a jumper I need to change to use one of the expansion modules?

    Edit: Duh! I just happened to choose the only pin group that won't work since those pins are also used by the loader. Dumb!
  • Any idea what OS error 19 is?
    >>> sd=pyb.SDCard()
    >>> os.mount(sd, '/sd')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: 19
    
  • Sorry for all the beginner questions but how do I exit the pye editor? The doc says I type control-q but that doesn't seem to do anything.
  • ersmith wrote: »
    David Betz wrote: »
    Back to MicroPython:

    I downloaded the latest release and it is working on my P2-Eval board. Thanks, Eric!

    Great, glad it's working for you!

    I've thought of putting a "run micropython" button in flexgui, but I'm not sure how useful it would be. Maybe a different GUI (based on some of the other micropython runners) would be helpful though?

    Probably not the best place for this but a simple gui loader with many different options would be cool. One thing I've been pondering is using the WX module to connect and program the P2Eval. On the P1 I find myself wanting to build a simple gui to send a file to the SD using Ymodem protocol and then run said file. Another would be transfer an archive file to the sd card and then unpack. I've thought about installing visual studio again but still fighting trying to get touch info out of the display.

    This got me thinking a gui that could do a few simple utilities (such as run micropython or drop into taq-oz or cluso's debugger) might actually be handy. A serial term with a few buttons, make sure there are options for DTR/RTS and run/program eeprom and solid gold IMHO.
  • evanhevanh Posts: 15,126
    If you really want X/Y/Z modem features in the downloader then don't need a special terminal program, just use a BBS package. The extra support needed is all in the prop2. You get ANSI colour and cursor support for free.
  • evanh wrote: »
    If you really want X/Y/Z modem features in the downloader then don't need a special terminal program, just use a BBS package. The extra support needed is all in the prop2. You get ANSI colour and cursor support for free.

    The one feature I really find myself wanting (although iirc not helpful on the ES) would be programming via WX module. I've found myself using Simple IDE for my p1 development a lot lately with it's wifi loading.

    I've been using ExtraPUTTY for all my terminal needs since it handles pretty much everything and also allows SOME configuration of DTR/RTS. Setting flow control to none(dtr/rts disabled) allows me to load via serial and then open the terminal without disturbing the program. The only problem here is sending BREAK no longer resets the board.

    I was just advocating for the run mycropython button because buttons are nice and I like pushing them :smiley:
  • roglohrogloh Posts: 5,122
    edited 2019-11-07 06:59
    The one feature I really find myself wanting (although iirc not helpful on the ES) would be programming via WX module.

    I think we will get there eventually on the P2. With custom hacks and some external scripts etc a while ago I was able to do some wireless ESP8266 downloads with PropellerIDE to the P1 (with reset) and it was rather nice, especially for portable devices. I'd love something like that on the P2 at some point. The key here is having the P2 serial pins remain accessible/overridable and then wireless modules like the ESP8266 can be plugged in and affect the boot sequence. You can then telnet in to get a serial prompt too and theoretically support file transfers into local P2 filesystems as well (though I didn't get that far).

    Something like this for developing mobile/robot applications would be handy, and you can walk alongside it with a laptop and download/try ideas out without cabling it up at all times...
  • Cluso99Cluso99 Posts: 18,066
    I use Visual Studio Code (VS Code not Visual Studio which has no relationship) to edit my python code (for work) with the python extension. It does a great job at coloring the code and also finds many errors during edit (when you save).
  • David Betz wrote: »
    Any idea what OS error 19 is?
    >>> sd=pyb.SDCard()
    >>> os.mount(sd, '/sd')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: 19
    

    I think that's "invalid parameter". I don't know what it means in this context, maybe something about your SD card's format is making upython unhappy?
    David Betz wrote: »
    How do I exit the pye editor? The doc says I type control-q but that doesn't seem to do anything.

    It looks like loadp2's terminal mode is eating ^S and ^Q (flow control must be on). I thought I had fixed that, but it looks like it's back, sorry. Try using a different terminal program for now.
  • ersmith wrote: »
    David Betz wrote: »
    How do I exit the pye editor? The doc says I type control-q but that doesn't seem to do anything.

    It looks like loadp2's terminal mode is eating ^S and ^Q (flow control must be on). I thought I had fixed that, but it looks like it's back, sorry. Try using a different terminal program for now.

    I've updated the loadp2 source code (https://github.com/totalspectrum/loadp2) and I think the ^s/^q problems should be fixed on Linux and MacOS.
  • ersmith wrote: »
    ersmith wrote: »
    David Betz wrote: »
    How do I exit the pye editor? The doc says I type control-q but that doesn't seem to do anything.

    It looks like loadp2's terminal mode is eating ^S and ^Q (flow control must be on). I thought I had fixed that, but it looks like it's back, sorry. Try using a different terminal program for now.

    I've updated the loadp2 source code (https://github.com/totalspectrum/loadp2) and I think the ^s/^q problems should be fixed on Linux and MacOS.
    Thanks, Eric! I'll check it out after work. I'll also try a different SD card. The one I was using was an ancient 2GB card I used on the P1 back when it couldn't handle higher density cards.

Sign In or Register to comment.