Shop Learn
P2 Learning Path — Parallax Forums

P2 Learning Path

Hello all,

I recently became interested in the P2 (have only tried P1 in a Quickstart board from Radio Shack like 6 years ago) and got a hold on Jon Mac's board and P2 Edge. I am very excited to learn about P2, but upon heading to propeller.parallax.com I noticed that there are quite a good amount of technical documents about the architecture and about the Spin2 language, and another seemingly plethora of software tools to use or try. So being a newbie (this is very different from my Arduino and ESP32 experiences) my question is:

What is the best way to start learning P2 for a newbie such as me?

Do I learn P1 first and then try to come over to the new kid on the block, or do I dive right into the P2 world?

Is there a kind of "Getting Started on the P2" book or document available now or will it be in the near future?

Which of the tools is the recommended approach for a newbie? (I installed the propeller tool 2.3.0.0 alpha)

Is the debug functionality available in Propeller Tool or just on the PNut tool?

Sorry for all the questions at once. I reckon most people here are flying well above me, but I suppose the easier the learning path the more adepts will come and stay.

Comments

  • Cluso99Cluso99 Posts: 17,455
    First, P1 is not being replaced by P2.

    If you are concentrating on spin, then either P1 or P2. Spin is a little different on P2.

    If you’re wanting to program in C then there are a few things to think about. P1 has a good set of learning examples from what I understand. There’s not much C for P2 yet, although there is Catalina and flexprop compilers. Both can target P1 and P2.

    If you’re wanting to learn assembly (pasm) then P2 is almost a superset of P1. You can dive in to P2 and just use the base instructions easily. However, pasm examples will no doubt be using the more powerful instructions but more obscure instructions. Pasm is reserved mostly for smaller and faster little programs that run in it’s own cog (core or cpu). Generally they will be a driver for a particular interface eg VGA, keyboard, LCD, sensors, etc.

    The advantage of spin is that it’s a high level program that makes writing programs easier. You just use pasm drivers written by others mostly more experienced than yourself. This way exposes you to pasm without actually needing to learn it. You can inspect the code to see how it works, and modify it to do some more functions. It’s a great way to learn.
  • jrullanjrullan Posts: 56
    edited 2020-11-09 11:49
    @Clusso99,

    Thanks for your input. In terms of Spin1 vs Spin2, is there a guide that explains the differences between them?

    I have a Kindle version of the book: "Programming The Propeller with Spin" that I bought when I was trying to learn the Propeller 1. I suppose I could use that as a reference to some extent, but so far from the examples I see that Spin2 seems to have more friendly named methods (pinwrite... etc). So without having put too much effort yet, I wonder if the differences are too significant.

    For example, I saw an example that have the syntax pinwrite(56 addpins 7,...). I couldnt find the explanation for addpins, and the concept of pinfield mentioned in the documentation.

    Update:
    Ok... I found out some guidance here: Parallax Spin2 Documentation v34u

    My understanding is that pinfield can be one of the following: either a specific pin number or a group of pins specified using one of two syntaxes: [63..56] OR [56 addpins 7]
  • RaymanRayman Posts: 11,835
    edited 2020-11-08 22:42
    I wish there was a guide for porting Spin1 to Spin2...
    I've made some notes here: http://www.rayslogic.com/Propeller2/PortingP1toP2.htm

    Be sure to check out https://propeller.parallax.com/

    Getting started, I would recommend the new PropTool and the examples from PNut and what you can find in the new OBEX.

    Another great way to go is with FlexProp (used to be called FlexGui) that lets you program in Spin1, Spin2, C, BASIC and combinations of these.

    If you're a C purist, the Catalina might be the way to go.

    Also, I'd recommend getting the P2 Eval board, of course...
  • Rayman wrote: »
    I wish there was a guide for porting Spin1 to Spin2...
    I've made some notes here: http://www.rayslogic.com/Propeller2/PortingP1toP2.htm

    Be sure to check out https://propeller.parallax.com/

    Getting started, I would recommend the new PropTool and the examples from PNut and what you can find in the new OBEX.

    Another great way to go is with FlexProp (used to be called FlexGui) that lets you program in Spin1, Spin2, C, BASIC and combinations of these.

    If you're a C purist, the Catalina might be the way to go.

    Also, I'd recommend getting the P2 Eval board, of course...

    Thank you for your input Rayman.
  • I am a long time programmer on the P1 in C.

    I find switching over to the P2 a difficult task as the instructions are different the implementation is different and it not as simple as just porting the code over and your ready to go.

    I see you mentioned Arduino and ESP32 which are both good C products so if you are looking to stay in C then I would look at FlexProp and learn the C flavor rather then try to learn a new language like SPIN.

    There still is a steep learning curve as there is not much developed yet to drive different products in C.

    Mike
  • I’ve been a long time Spin programmer using the P1 so when the P2 came out I was looking to continue using the ‘new’ version of spin. Right now I’m finding that the objects available are sparse for my needs so I bit the bullet and decided to look into using C under FlexSpin. I used the excellent C tutorials that Parallax has for the P1, that got me familiar with the syntax and it was off to the races. I’m not very good at it yet but it’s easier than I expected for this old brain to learn a new language.
  • RaymanRayman Posts: 11,835
    I was just thinking about all the P1 GCC stuff. Sounds like the tutorials are still good. Maybe a lot of the drivers and code can work with P2 too...
  • Since the C compiler is produced by someone else none of the current tutorial will work on the P2. The functions available on the P2 are different including the instruction set so you will have to learn those new functions to get code to work properly.

    Mike
  • Well I just got done working on several devices that I used on the P1 and worked on moving them over to the P2.

    I found that 90% of the code I built on the P1 works on the P2 with little or no change.

    Thanks to some heavy aliasing on the P2's flexC compiler most things moved over. I did however have to change some inline assembly code and found that the assembly language is a little easier to write then on the P1.

    In any case I was able to get everything so far to work with little or no changes.

    I did however have to learn how to move my custom libraries over to the flexprop compiler. Since this compiler is a single stage compiler with no linker all the code is compiled at one time. So I was able to setup a custom include area with all of my libraries and they compile in just fine.

    No need SPINning my wheels rewriting code.

    Mike
  • jrullanjrullan Posts: 56
    edited 2020-11-29 02:45
    Hi, a couple of weeks have passed since I started this thread. I'm very grateful for all the help and support I have received in this forum, and recognizing that learning the Propeller 2 from scratch is not a trivial effort (specially for Arduino-like people like me) today I wanted to share a program that summarizes my learning experience so far in this case with PASM.

    I decided to head on to PASM as I found that the propeller ecosystem relies heavily on using a combination of Spin + PASM. Although this program is "another blinky leds" project, it forced me to learn several aspect of PASM along the way that I think are essential for becoming more proficient. This code is probably very inefficient and there are probably better ways of doing what I did but I'll share it anyway in the hopes that someone might find it useful as an example.
    {
      My second documented PASM program.
      What it does: light up consecutive leds in a sequence starting with P0
      Sequence:
            start with first led and cycle it on and off,
            then first and second leds,
            then first through third, and so on..
    
      Learning Lessons:
      1. Passing variables from main program in hub
      2. Using CT1 to create delays
      3. Using loops and jumps (JMP, DJZ)
      4. Testing bits (TESTB) and comparing (CMP)
      5. Using modifiers (wc,wz)
      6. Using conditionals (if_c, if_z)
      7. Using special address literal #$ (here)
      8. Accomodating data at the end putting the RES'd ones last
    
      Jose Rullan @ Nov 29, 2020
    }
    CON
      DELAY_MS = 500
      LEDS = 8
    
    VAR
      long delay
      long maxleds
    
    PUB main()
      maxleds := LEDS
      delay := clkfreq/1000 * DELAY_MS
      COGINIT(COGEXEC_NEW,@_blink,@delay)
    
    DAT     ORG   0
    
    _blink
            '----------- Setup Variables ---------------------------
            RDLONG  delayms, PTRA  'Read delay from hub RAM @ address passed in Coginit()
            MOV     r1,PTRA
            ADD     r1,#4
            RDLONG  maxlimit,r1    'Get next long variable (4 bytes ahead) maxleds
    
            ADD     maxlimit,#1    'Increase limit by one for comparisons later on
            MOV     mask, #1       'Create a mask for the pin that we want
            OR      DIRA, #$FF     'Set the direction of the first 8 pins to Output
    
            { Get the global system counter value and
              set CT1 event to trigger on CT = countvalue + delayms
              (also adds delayms into countvalue)}
            GETCT   countervalue
            ADDCT1  countervalue,delayms
    
    _Loop   '----------- Main loop ---------------------------------
            WAITCT1                        'Pause cog until counter reaches ct1
            ADDCT1   countervalue,delayms  'set ct1 target again
            XOR      OUTA, mask            'toggle masked pin
            SHL      mask,#1               'shift mask left
            TESTB    mask,ledslimit wc     'check if mask reached last led limit
    if_c    JMP      #_Restart             'then jump to _Restart
            JMP      #_Loop                'otherwise jump to _Loop
    
    _Restart
            MOV   mask,#1          'reset mask to 1
            DJZ   cycles,#_Addled  'decrement cycles and if reached zero jump to _Addled
            JMP   #_Loop           'jump to _Loop
    
    _Addled
            ADD   ledslimit,#1           'increase limit by 1
            CMP   ledslimit,maxlimit wz  'check if limit reached maxlimit
    if_z    MOV   ledslimit,#1           'then reset limit to 1
            MOV   cycles,#2              'reset cycles to 2 (on, off)
            JMP   #_Loop                 'jump to _Loop
    
    { The #$ literal means the address of this instruction
      so JMP #$ will make it stay in this place forever
      otherwise the cog will start from the top again
      (not actually using it here, but good for debugging)}
    _End
            JMP   #$
    
    '------------------------------------------
    { Important note: reserved memory with RES
      must go at the end of all other memory
      if not unexpected consequences could happen
      See Propeller 1 Manual }
    delayms       long      0
    ledslimit     long      1
    cycles        long      2
    maxlimit      RES       1
    countervalue  RES       1
    mask          RES       1
    r1            RES       1
    FIT 496
    
Sign In or Register to comment.