Shop OBEX P1 Docs P2 Docs Learn Events
MicroPython on P2 - Can't get sample program to work — Parallax Forums

MicroPython on P2 - Can't get sample program to work

wmosscropwmosscrop Posts: 409
edited 2022-08-21 19:27 in Propeller 2

https://parallax.com/propeller-2/get-started/micropython/

Using the terminal emulator works, I can turn on the led.

Trying to use the mu application, I can't get anything to run.

Mode is set to ESP MicroPython, as per the sample image.

The sample program won't work on my P2, all I get is (edited for clarity):

#

Native P2 MicroPython
Heap Size: 128 kB

#

Heap ptr = 0x434d9, Stack ptr = 0x7f760
MicroPython v1.13-8-g4b51b34d8-dirty on 2020-10-28; P2 BOARD with Propeller2 P2X8C4M64P
Type "help()" for more information.
...
raw REPL; CTRL-B to exit
OK
exit

This project looks like it might be out of date, maybe it's a dead end?

Comments

  • Thats odd, if it works in the terminal but not Mu. What version of Mu?
    I'll have a look at it today Walt

  • Mu 1.1.1 stable (latest build)

    Thanks

  • TubularTubular Posts: 4,705
    edited 2022-08-21 23:23

    I fired up Mu and this is the program from the live stream demo on the LM334/335Z. Mu version is 1.1.0.alpha.2 I would have thought that would be close enough
    Even without the temp sensor hardware this should run OK but just show flatline values

    # P2 "Hello LM335Z" MicroPython demo, by Team-oz 1 DEC 2020
    # Connect LM335Z between ground and Pin 16.   10k trimmer potentiometer optional.
    # P2 is configured to provide 1mA pull-up current source.  LM335Z outputs ~10mv per K (2.98v at 25 C room temp)
    
    import machine                                                          # machine contains P2 specific functions, eg Pin for I/O pin access
    import time                                                             # time contains time delay routines (sleep)
    
    p=machine.Pin(16)                                                       # our LM335Z is connected between pin 16 and GND
    p.wrpin(p.P_HIGH_1MA | p.P_ADC_1X| p.P_COUNT_HIGHS | p.P_TT_01  )       # bias the LM335Z with a 1mA current source. Use ADC in 1x gain to observe
    p.wxpin(1000000)                                                        # each ADC bucket accumulates for 1 million clocks (~252 Hz)
    p.on()                                                                  # start the current source and observations
    time.sleep_ms(300)                                                      # give it time to get first readings
    
    r=range(101)                                                            # plot 100 readings to Mu plot window
    baseline=p.rdpin()
    print('baseline=' , baseline)                                           # record a baseline ('zero point')
    for i in r:
        print('(',p.rdpin()-baseline+4000,',',p.rdpin()-baseline+200,',',p.rdpin()-baseline+400,',',p.rdpin()-baseline+600,',',p.rdpin()-baseline+800,',',
          p.rdpin()-baseline+1000,',',p.rdpin()-baseline+1200,',',p.rdpin()-baseline+1400,',',p.rdpin()-baseline+1600,',',p.rdpin()-baseline+1800,',',
          p.rdpin()-baseline+2000,',',p.rdpin()-baseline+2200,',',p.rdpin()-baseline+2400,',',p.rdpin()-baseline+2600,',',p.rdpin()-baseline+2800,',',
          p.rdpin()-baseline+3000,',',p.rdpin()-baseline+3200,',',p.rdpin()-baseline+3400,',',p.rdpin()-baseline+3600,',',p.rdpin()-baseline+3800,',',')')                                   # Mu plot needs values in normal braces to work.  Offset so that 0 = baseline
        time.sleep_ms(100)                                                  # take around 6 readings per second (expt lasts 30 seconds)
    
    p.pinfloat()                                                            #turn off current source, we're done.
    # Write your code here :-)
    
  • Walt what sample code are you trying to run? Is it intended for ESP32? Or some sample code team-oz used?

  • Tubular, thanks for your help. Tried a few things, found this:

    My code works with 1.1.0.alpha.2 (after I changed machine.pin to machine.Pin). But even after this change it doesn't work with 1.1.1.

    So there's some change between your version and the latest version that breaks things.

    To answer your question, my code is homegrown, based on a Python book I found (from 2009). So it should be generic code, looks like a subset of your code.

    import machine
    import time

    p = machine.Pin(56)
    p.off()

    while 1 == 1:
    p.on()
    time.sleep_ms(500)
    p.off()
    time.sleep_ms(500)

  • Ok its good we have a working reference point. I'll load the new Mu version and see if it breaks that demo code

Sign In or Register to comment.