Shop OBEX P1 Docs P2 Docs Learn Events
Nwebie Propeller Quickstart question — Parallax Forums

Nwebie Propeller Quickstart question

jujugoboomjujugoboom Posts: 6
edited 2013-11-07 16:33 in Propeller 1
Hello,

I just bought my parallax propeller quickstart 40000 today from radioshack. Ive worked for a while with arduino and decided, why not try out the propeller. I downloaded the drivers and propeller tool and loaded up the touch example. I do not have any external peripherals right now so i just decided to mess around with using multiple cores and printing to the serial terminal. I used this code
CON

  _CLKMODE = XTAL1 + PLL16X
  _CLKFREQ = 80_000_000




OBJ


  Buttons          : "Touch Buttons"
  PST              : "Parallax Serial Terminal"


PUB Main
  cognew(Touch(_CLKFREQ/100), @stack[0])                       






PUB Touch


  dira[23..16]~~                                        ' Set the LEDs as outputs
  repeat
    outa[23..16] := Buttons.State
'
to try to get it to start in a new cog. It gives me the error stating that it expected a , at touch in the cognew command. I was also wondering which way is the best way to have it read which button i press and output it to pst? Such as "Button 0 Pressed","Button 1 Pressed" etc etc. Thanks for any help

Justin

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-11-03 20:55
    jujugoboom wrote: »
    It gives me the error stating that it expected a , at touch in the cognew command.
    That's to be expected because the Touch method doesn't take any parameters. Either use cognew(Touch, @stack[0]) or change Touch to accept a parameter, e.g. PUB Touch(delay). You'll also have to define a stack array somewhere.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-03 21:55
    I tried to keep a list of QuickStart related links and demos in this thread.

    My QuickStart servo tester uses the buttons to set the servo parameters. I gave Joe some instructions on how to use the touchpads as selection buttons starting in post #15 of his QuickStart BOE-Bot thread.

    Post #3 of my index has links to various Propeller tutorials.

    You might have a hard time going back to the Arduino once you see how useful parallel processing can be on the Propeller.
  • jujugoboomjujugoboom Posts: 6
    edited 2013-11-04 17:45
    Duane Degn wrote: »
    I tried to keep a list of QuickStart related links and demos in this thread.

    My QuickStart servo tester uses the buttons to set the servo parameters. I gave Joe some instructions on how to use the touchpads as selection buttons starting in post #15 of his QuickStart BOE-Bot thread.

    Post #3 of my index has links to various Propeller tutorials.

    You might have a hard time going back to the Arduino once you see how useful parallel processing can be on the Propeller.

    Thats alot of great resources. Thanks. I am a slow learner though. When i run this code
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 80_000_000
    
    
    
    
    OBJ
    
    
      Buttons          : "Touch Buttons"
    
    
    
    
    PUB Main
      cognew(touch(clkfreq/100), @stack)
      
    PUB touch(delay)
    
    
      dira[23..16]~~                                        ' Set the LEDs as outputs
      repeat
        outa[23..16] := Buttons.State                       ' Light the LEDs when touching the corresponding buttons 
    

    I get an error stating it was expecting a variable at
    @stack
    
  • kuronekokuroneko Posts: 3,623
    edited 2013-11-04 21:33
    jujugoboom wrote: »
    I get an error stating it was expecting a variable at
    @stack
    
    Correct, all you have to do is define one so it can be used, e.g.
    VAR
      long  stack[32]
    
    It's advisable to start with a generously sized stack and adjust it later if necessary.
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2013-11-06 14:55
    I'd try this out with the tutorials or examples in the help menu of the ide. Its hard to go back from parallel processing once you've started. Get an activity board next to try the cool stuff and have fun.
  • jujugoboomjujugoboom Posts: 6
    edited 2013-11-06 19:38
    Alright so ive been doing some looking around and came up with this.
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 80_000_000
    
    
    VAR
      long stack[60]
      
    OBJ
    
    
      Buttons          : "Touch Buttons"
      PST              : "Parallax Serial Terminal"
      NUM              : "Numbers"
    PUB Main
      cognew(touch(clkfreq/100), @stack[0])
      cognew(terminal, @stack[30])
    
    
    PUB touch(delay)
    
    
      dira[23..16]~~                                        ' Set the LEDs as outputs
      repeat
        outa[23..16] := Buttons.State                       ' Light the LEDs when touching the corresponding buttons 
    
    
    PUB terminal
      PST.start(115200)
      
      
      repeat
        PST.clear
        
        PST.dec(Num.ToStr(Buttons.State, Num#DDEC)- 16)
        waitcnt(clkfreq / 10 + cnt)
    

    of course if you compile and run this you will see that it doesn't work, at all. I was able to get the buttons to work in a seprerate cog but then adding PST broke it. Any help would be appreciated.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-11-06 19:57
    I'm still staring at your code in the attempt to figure out what broke... Haven't spotted it yet, perhaps MikeG or someone will beat me to the punch...

    In the meantime, you may find the Programs on this link useful. IIRC, there is a game or two that used both the Serial Terminal and the Touchbuttons.

    Jeff
  • kuronekokuroneko Posts: 3,623
    edited 2013-11-06 20:08
    jujugoboom wrote: »
    ... of course if you compile and run this you will see that it doesn't work, at all. I was able to get the buttons to work in a seprerate cog but then adding PST broke it. Any help would be appreciated.
    The Touch Buttons objects I know of need to be started (e.g. Buttons.Start(rate)). I can't find this call in your example. Also, depending on how the State method is written the terminal cog and the display cog may get into each others way.

    Also, what's the idea behind PST.dec(Num.ToStr(Buttons.State, Num#DDEC)- 16)?
  • dgatelydgately Posts: 1,630
    edited 2013-11-06 22:55
    jujugoboom wrote: »
    Alright so ive been doing some looking around and came up with this.
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 80_000_000
    
    VAR
      long stack[60]
      
    OBJ
    
      Buttons          : "Touch Buttons"
      PST               : "Parallax Serial Terminal"
      NUM              : "Numbers"
    
    PUB Main
    
      cognew(touch(clkfreq/100), @stack[0])
      cognew(terminal, @stack[30])
    
      repeat                                         ' <==  need this repeat to keep the HUB running
    
    PUB touch(delay)
    
      Buttons.start(delay)                        ' <== need to start the Buttons object
    
      dira[23..16]~~
      repeat
        outa[23..16] := Buttons.State              ' Light the LEDs when touching the corresponding buttons 
    
    PUB terminal
    
      PST.start(115200)
      
      repeat
        PST.clear
        
        PST.bin(Buttons.State,8)             ' <== use "bin" as it will show a binary representation of the button state (8 bits worth!)
        waitcnt(clkfreq / 100 + cnt)           ' <== need to give a little time for PST to keep up with this tight loop!
    

    There are still issues with how quickly the two loops run. The display of the button states to PST flicker and the LEDs of non-pressed buttons light unless your touch is very light.


    dgately
  • jujugoboomjujugoboom Posts: 6
    edited 2013-11-07 07:22
    dgately wrote: »
    CON
    
      _CLKMODE = XTAL1 + PLL16X
      _CLKFREQ = 80_000_000
    
    VAR
      long stack[60]
      
    OBJ
    
      Buttons          : "Touch Buttons"
      PST               : "Parallax Serial Terminal"
      NUM              : "Numbers"
    
    PUB Main
    
      cognew(touch(clkfreq/100), @stack[0])
      cognew(terminal, @stack[30])
    
      repeat                                         ' <==  need this repeat to keep the HUB running
    
    PUB touch(delay)
    
      Buttons.start(delay)                        ' <== need to start the Buttons object
    
      dira[23..16]~~
      repeat
        outa[23..16] := Buttons.State              ' Light the LEDs when touching the corresponding buttons 
    
    PUB terminal
    
      PST.start(115200)
      
      repeat
        PST.clear
        
        PST.bin(Buttons.State,8)             ' <== use "bin" as it will show a binary representation of the button state (8 bits worth!)
        waitcnt(clkfreq / 100 + cnt)           ' <== need to give a little time for PST to keep up with this tight loop!
    

    There are still issues with how quickly the two loops run. The display of the button states to PST flicker and the LEDs of non-pressed buttons light unless your touch is very light.


    dgately

    I dont have my propeller with me right now but this looks like it should work. Are you saying that it just needs some delays because i can easily add that in. So all i needed to do was start buttons? Thanks
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-07 07:39
    jujugoboom wrote: »
    So all i needed to do was start buttons?

    And you were using the Numbers object incorrectly. PST has some built in methods for dealing with numbers so you don't need the "Numbers" object at all.

    I think you'd get a better looking display if you didn't clear the screen with each loop but instead use the PST Position method to print the same line over the same location. I think the clear screen command will make the screen flicker a bit.
  • dgatelydgately Posts: 1,630
    edited 2013-11-07 09:30
    Duane Degn wrote: »
    And you were using the Numbers object incorrectly. PST has some built in methods for dealing with numbers so you don't need the "Numbers" object at all.

    I think you'd get a better looking display if you didn't clear the screen with each loop but instead use the PST Position method to print the same line over the same location. I think the clear screen command will make the screen flicker a bit.

    Yes, I was quickly trying to solve his issue and wasn't really thinking about why the flicker. Always best to just update by setting the X,Y position of the cursor, especially when the output is a known number of characters.

    Thanks Duane! As usual, great advice from a sage Propeller dude :thumb:


    dgately
  • jujugoboomjujugoboom Posts: 6
    edited 2013-11-07 16:17
    dgately wrote: »
    Yes, I was quickly trying to solve his issue and wasn't really thinking about why the flicker. Always best to just update by setting the X,Y position of the cursor, especially when the output is a known number of characters.

    Thanks Duane! As usual, great advice from a sage Propeller dude :thumb:


    dgately

    And, sorry to ask so many questions, without putting in into the code, how would you propose doing that? Thanks
  • dgatelydgately Posts: 1,630
    edited 2013-11-07 16:25
    jujugoboom wrote: »
    And, sorry to ask so many questions, without putting in into the code, how would you propose doing that? Thanks

    You can check-out all of Parallax Serial Terminal's functions/methods in its .spin file... But, here's an example...

    I dont remember of the .Position method is ZERO-based or not, so try one of these in place of 'PST.clear':
        PST.Position(0, 0)
    
    OR
    
        PST.Position(1,1)
    

    dgately
  • jujugoboomjujugoboom Posts: 6
    edited 2013-11-07 16:33
    dgately wrote: »
    You can check-out all of Parallax Serial Terminal's functions/methods in its .spin file... But, here's an example...

    I dont remember of the .Position method is ZERO-based or not, so try one of these in place of 'PST.clear':
        PST.Position(0, 0)
    
    OR
    
        PST.Position(1,1)
    


    dgately

    Yes using
    PST.Position(0,0)
    
    is the proper one to use
Sign In or Register to comment.