Shop OBEX P1 Docs P2 Docs Learn Events
FlexGUI 4.0.4 + MicroPython: assistance loading upython.binary into the P2 board — Parallax Forums

FlexGUI 4.0.4 + MicroPython: assistance loading upython.binary into the P2 board

Ken GraceyKen Gracey Posts: 7,392
edited 2019-11-27 21:35 in Propeller 2
READme.txt says the following:

=====
This is a basic port of MicroPython to the Parallax P2 Eval board.

To run it, load the upython.binary file into the P2 board. It will
talk on the standard serial line at 230400 baud. It will also try to
talk to a VGA board based at pin 48 and a USB keyboard based at pin 16
(using the standard P2 eval A/V and serial host expansion boards). The
USB driver used is garryj's excellent single COG keyboard/mouse driver
(although I haven't implemented mouse support yet).
=====
How do I load the upython.binary file into the P2 board? Using a terminal program, like PST, or some other method? Are there any total-noob instructions out there?

Thanks,

Ken Gracey
Parallax Inc.
«1

Comments

  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2019-11-27 21:47
    I believe you need to use something like loadp2 (which comes with the FlexGui package).
    You may also be able to use Chip's pnut.exe
  • ersmithersmith Posts: 6,053
    edited 2019-11-27 21:49
    Launch flexgui.exe, then go to the "Special" menu and select "Run uPython on P2". That should open up a terminal window connected to micropython.

    If you also want VGA and USB you'll have to follow the directions in README.txt.
  • Another way to start upython.binary (or any other P2 binary) is to click on the "Run Binary" button and then use the file selector to find the program to run (e.g. samples/upython/upython.binary). But since micropython is such a commonly requested binary I added an entry to the Special menu just for it.
  • ersmith wrote: »
    Launch flexgui.exe, then go to the "Special" menu and select "Run uPython on P2". That should open up a terminal window connected to micropython.

    If you also want VGA and USB you'll have to follow the directions in README.txt.

    Success on loading upython.binary using these instructions. Not interested in VGA/keyboard stuff just yet.

    After I compose some MicroPython code, like this:

    from pye import pyb
    p = pyb.Pin(56)
    p.off()
    p.toggle()
    

    . . how do I get this loaded into the P2?

    Thanks,

    Ken Gracey
  • You should be able to load uPython via the Special menu in FlexGUI
    663 x 239 - 6K
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2019-11-27 22:09
    My understanding is that the Special menu in FlexGUI menu has two uses: (1) loading the upython.binary MicroPython language interpreter onto cog2 in the P2 and (2) loading MicroPython code written in FlexGUI to the P2. Is this correct?

    After the upython.binary is loaded, we can use the same menu to load MicroPython code, right?

    Is there a need to use REPL to get MicroPython code running?

    Thanks,

    Ken Gracey
  • ersmithersmith Posts: 6,053
    edited 2019-11-27 22:17
    You type python commands into the terminal window. An easy way to do that is via cut & paste. Micropython has a "paste mode" activated by CTRL-E. That makes this easier. Type CTRL-E, then paste the text you want into the terminal window, then type CTRL-D to exit paste mode.

    micropython is an interactive interpreter, so you can just type commands at it and try them out. If you find a sequence you like, you can save it to an SD card. The pye editor makes it possible to do this entirely within micropython.

    FlexGUI doesn't really understand anything about micropython, it's just being used for the terminal window and ability to download the binary. Chip's PNut could also be used for the download, if you then open a terminal window for the interaction with the P2 interpreter.
  • BTW, you don't want "from pye import pyb" in your example above, it's just plain "import pyb". "pyb" is a built in module (it stands for "python board" which has definitions for things like pin toggling and waiting.
  • ersmithersmith Posts: 6,053
    edited 2019-11-27 22:19
    Ken Gracey wrote: »
    My understanding is that the Special menu in FlexGUI menu has two uses: (1) loading the upython.binary MicroPython language interpreter onto cog2 in the P2 and (2) loading MicroPython code written in FlexGUI to the P2. Is this correct?
    No, it's just used to run the interpreter on the P2. After that the interaction is all through the terminal window.

    BTW the FlexGUI terminal window does understand ANSI escape sequences, so while typing commands at micropython you can use the cursor keys, Home, and End to move around the line you're typing. Cursor up and down scroll through previous commands that you typed.
  • ersmith wrote: »
    Ken Gracey wrote: »
    My understanding is that the Special menu in FlexGUI menu has two uses: (1) loading the upython.binary MicroPython language interpreter onto cog2 in the P2 and (2) loading MicroPython code written in FlexGUI to the P2. Is this correct?
    No, it's just used to run the interpreter on the P2. After that the interaction is all through the terminal window.

    OK, got the usage straight from your three messages above. Thanks!

    Will report back.

    Ken Gracey

  • ersmith wrote: »
    You type python commands into the terminal window. An easy way to do that is via cut & paste. Micropython has a "paste mode" activated by CTRL-E. That makes this easier. Type CTRL-E, then paste the text you want into the terminal window, then type CTRL-D to exit paste mode.

    micropython is an interactive interpreter, so you can just type commands at it and try them out. If you find a sequence you like, you can save it to an SD card. The pye editor makes it possible to do this entirely within micropython.

    FlexGUI doesn't really understand anything about micropython, it's just being used for the terminal window and ability to download the binary. Chip's PNut could also be used for the download, if you then open a terminal window for the interaction with the P2 interpreter.

    Is the process like this?

    (1) Type code into FlexGUI, like this:
    import pyeb
    
    p = pyb.Pin(56)
    p.off()
    p.toggle()
    

    (2) Select all, copy
    (3) Special => Terminal only window
    (4) ctrl-E to enter paste mode
    (5) ctrl-V to paste? This creates a [?] character in the terminal. Expected that my program would show up.

    This is where I am stuck.

    Thanks,

    Ken Gracey
  • Ken Gracey wrote: »
    Is the process like this?

    (1) Type code into FlexGUI, like this:
    import pyeb
    
    p = pyb.Pin(56)
    p.off()
    p.toggle()
    

    (2) Select all, copy
    (3) Special => Terminal only window
    (4) ctrl-E to enter paste mode
    (5) ctrl-V to paste? This creates a [?] character in the terminal. Expected that my program would show up.

    Close. You can't use ctrl-V to paste, that just sends the ctrl-V character to the terminal. Instead select the little terminal icon next to "Propeller Output" on terminal window title bar, then go to Edit > Paste. Ignore the accelerator key there that says Ctrl-V, that doesn't work.
  • WhitWhit Posts: 4,191
    @"Ken Gracey" and all,

    So excited to see this thread. Just what I will need to start playing. I received my P2 Evaluation Board shipping notice today.
  • Here is my blink code:
    import pyb
    import os
    
    def sleep(n):
        end = pyb.millis() + n
        while pyb.millis() < end:
            pass
    
    def blink(pin, n):
        p = pyb.Pin(pin)
        for i in range(n):
            p.toggle()
            sleep(500)
    
    blink(56, 10)
    
  • Ken GraceyKen Gracey Posts: 7,392
    edited 2019-11-27 23:43
    SUCCESS!

    Questions:

    (1) Is only processor 1 available to MicroPython (if possible, I'd rather use the word "processor" for the audience, should it become one)?
    (2) When I reset the P2 Eval Board the program does not run again. Is it stored in RAM only? Is this where the SD card comes in?

    And I'm curious about the extent of reusability of other MicroPython code, too. Any general comments there?

    Thanks Eric, David and Roy!

    Ken Gracey
  • RaymanRayman Posts: 14,646
    Ken's got me curious too...

    I assume you can program the uPython binary to SD or flash.
    But, can you have it run some Python code you want at startup?
  • Eric, nice work. You've enabled something new here!

    Ken Gracey
  • Ken Gracey wrote: »
    SUCCESS!

    Questions:

    (1) Is only processor 1 available to MicroPython (if possible, I'd rather use the word "processor" for the audience, should it become one)?
    (2) When I reset the P2 Eval Board the program does not run again. Is it stored in RAM only? Is this where the SD card comes in?

    And I'm curious about the extent of reusability of other MicroPython code, too. Any general comments there?

    Thanks Eric, David and Roy!

    Ken Gracey
    Whatever code you put into main.py on the SD card will be run when Python starts.

  • Yes I've successfully run Eric's riskV MicroPython v8 from uSD card. That just worked.

    For some reason I haven't had the same luck with Roger's Native P2 MicroPython. I've tried 4 different cards and they all behave slightly differently during boot

    I need to get back to that and dig deeper. I have already tried padding out the images to a 512 byte sector boundary and that didn't do it. Perhaps it made things worse (checksum etc)

    Regardless, the process is nominally simple, just take the binary and put it in the root directory of the SD card, renaming it to _BOOT_P2.BIX

    You can also put programs (eg the Pye editor) in that directory, for subsequent import into micropython
  • How do you boot from an SD card? I don't see anything in the P2 documentation that says how to do that.
  • Yeah it needs to go into the docs.

    It involves copying the compiled binary (from Pnut, Flexgui etc) onto a uSD card as "_BOOT_P2.BIX"


  • Tubular wrote: »
    Yeah it needs to go into the docs.

    It involves copying the compiled binary (from Pnut, Flexgui etc) onto a uSD card as "_BOOT_P2.BIX"

    A ".BIX" file extension? Don't you know that BIX stands for the BYTE Information eXchange? I'm sure a few of you here remember BYTE magazine if not BIX. Anyway, thanks for letting me know how to name the file to boot from the SD card.
  • You may need to set some DIP switches on the P2-EVAL board too. I've not done this myself yet either.
  • Tubular wrote: »
    Yeah it needs to go into the docs.

    It involves copying the compiled binary (from Pnut, Flexgui etc) onto a uSD card as "_BOOT_P2.BIX"



    Okay, that's working for me. Now how to I invoke loadp2 to just connect to the serial port without downloading anything? I tried this and it gave me the dreaded "Could not find a P2".
    loadp2 -t -b 230400
    
  • This is where it gets a bit messy. Depending on the brand and type of SD card it might be interfering with rebooting (hence the not found message)

    What uSD card are you using David?

  • Tubular wrote: »
    This is where it gets a bit messy. Depending on the brand and type of SD card it might be interfering with rebooting (hence the not found message)

    What uSD card are you using David?
    Looks like some no-name SD 2GB SD card that I used to use for the P1.

  • David Betz wrote: »
    Tubular wrote: »
    Yeah it needs to go into the docs.

    It involves copying the compiled binary (from Pnut, Flexgui etc) onto a uSD card as "_BOOT_P2.BIX"

    A ".BIX" file extension? Don't you know that BIX stands for the BYTE Information eXchange? I'm sure a few of you here remember BYTE magazine if not BIX. Anyway, thanks for letting me know how to name the file to boot from the SD card.

    Ah yes its all coming back

    We have a double bookcase as work chocked full with interesting old mags David. Some are yours. Byte, Dr Dobbs, Circuit Cellar, wireless world, edn. Too good to throw away. I think the PC Mags have long since been turfed
  • I always use a seperate terminal if I want to do that
    on linux 'screen' works

    For what it is worth: https://forums.parallax.com/discussion/comment/1472297/#Comment_1472297

    have not worked on it or anything propeller related since forever, real life work is consumming every hour of my life at the moment. Thought I had a git repo with my changes but unfortunately not :(
    changes were mainly to replace fixed 115200 baudrate to 230400

  • Ken and David (and others)

    If you want to get the Pye editor up under MicroPython, this is what I found I needed to do (detailed list of instructions)

    https://forums.parallax.com/discussion/comment/1473775/#Comment_1473775
  • Tubular wrote: »
    Ken and David (and others)

    If you want to get the Pye editor up under MicroPython, this is what I found I needed to do (detailed list of instructions)

    https://forums.parallax.com/discussion/comment/1473775/#Comment_1473775
    I already have the pye editor working. In fact, the blink program I posted was written entirely on the P2 using the pye editor.
Sign In or Register to comment.