Shop OBEX P1 Docs P2 Docs Learn Events
A lot of the tutorials are done in C. Why not also in SPIN? Is it on the way out? (spin) — Parallax Forums

A lot of the tutorials are done in C. Why not also in SPIN? Is it on the way out? (spin)

Clock LoopClock Loop Posts: 2,069
edited 2020-08-26 21:19 in Propeller 1
I was looking over all the "Parallax WX Wi-Fi Module for Prop C"
https://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c

IS spin on the way out, as far as support and example code?

I guess it is a proprietary language, but I still like it.

And I thought it would be good to see all these done in SPIN.
Or am I just old skool, as I learned spin before prop c even existed.

I can switch to prop C, but so many objects in the github obex are in spin, or are they being ported over to prop C also?
Should I abandon spin, and code in prop C from now on?
I can do that if that is where everything is going.

Or is it time, to make identical copies of tutorials like the ones listed in "Parallax WX Wi-Fi Module for Prop C" but for SPIN?

I am trying to make links to example code for the propeller and the wx esp8266 wifi device in my
"ParallaxWX ESP8266 / RaspberryPi / Debian / Esp-open-sdk / SimpleIDE / Openspin / Proploader / DEVEL" thread.
Which helps users COMPILE the esp8266 code in linux/raspberryPI, that parallax developed for their WX device.
http://forums.parallax.com/discussion/169250/parallaxwx-esp8266-raspberrypi-debian-esp-open-sdk-simpleide-openspin-proploader-devel/p1

I thought it would be good to include links to example code, on how to use the wx device webpages to communicate and accomplish tasks with the propeller.

Comments

  • I'd say if you're only programming for the Prop, then write it in Spin. However, if you need higher speed, or you're writing portable code, then write it in C.

    If you use FlexGUI you can combine both C and Spin files into one program, so that's another approach you could take.


  • Yea, I looked at FlexGUI! I didn't know it can combine languages, thats nice.

    And I just found out that FlexGUI WORKS with the parallax WX esp8266 devices, excellent.

    I suppose I personally could convert all the stuff at....
    https://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c

    ...into spin. I wouldn't need to touch the web/esp stuff.
  • Clock Loop wrote: »

    . . . . . .

    I suppose I personally could convert all the stuff at....
    https://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c

    ...into spin. I wouldn't need to touch the web/esp stuff.

    In OBEX is a post which translates some of the WXESP8266 C tutorials into SPIN;

    https://github.com/parallaxinc/propeller/blob/1c72a5e433b33dd3703178f71a57c45393ffcf95/libraries/community/p1/All/WX ESP8266 SPIN Get Started/README.md

  • Clock LoopClock Loop Posts: 2,069
    edited 2020-08-26 22:55
    macrobeak wrote: »
    In OBEX is a post which translates some of the WXESP8266 C tutorials into SPIN;

    HEY! THANKS!

    Here is the master link.
    https://github.com/parallaxinc/propeller/tree/master/libraries/community/p1/All/WX ESP8266 SPIN Get Started




  • That particular tutorial (and many in the same family) were produced for our educational customers - in schools, college, universities. We created those examples because these are paying customers who've kept the business going. . .and they spoke clearly in favor of C in education.

    Spin1/2 isn't going away by any means. Wait till you see JonnyMac's presentation today. It's our future, along with some Python, C, etc.

    Ken Gracey
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-08-26 23:58

    Ken Gracey wrote: »
    ...and they spoke clearly in favor of C in education.

    Spin1/2 isn't going away by any means. Wait till you see JonnyMac's presentation today. It's our future, along with some Python, C, etc.

    Ken Gracey

    I totally understand why C is priority.

    Can't wait to see more document links on googledrive! And the vid where ever they get posted.

    https://forums.parallax.com/discussion/171704/propeller-2-live-forum-early-adopter-series-topics-speakers-and-registration/p7


  • Clock LoopClock Loop Posts: 2,069
    edited 2020-08-27 01:21
    Ken Gracey wrote: »
    ...paying customers who've kept the business going. . .

    Ahem.
    This is just what I have within grabbing distance.... ;) (i know what you meant)
    DoYourPart.jpg


    091.gif

    PART... intended PUN.


    (im still bummed about my 60+ dip props that fell victim to abuse of RAID WARRANTS that leave everything on the floor in their haste to find ANYTHING to justify it.)
    (nope, I didn't spend a single hour (or minute) in jail either, we are victims of a broken system, and we are many, left in the dust, don't even get me started)

    800 x 453 - 112K
  • I am very unhappy with the split between C and Spin. I understand why Parallax felt they had to go with C because of the environment in their target field of education. But that said, I think the Propeller ecosystem has been crippled since there was not just one language you could depend on finding your example code in. If C is to be the future, particularly for the P2 which was actually designed to run C efficiently, then Spin needs to go away. How frustrating is it if I go to the Obex (assuming I can figure that out, without learning all about Git) and find that the example code I need for my $widget is in Spin instead of C or vice-versa.

    Spin is and should be the language of P1. P1 is a terrible platform for C and C is slow and hoggy on it. Getting P1 to run C code is like one of those hacks where you get a Z80 to boot Linux by emulating an 8086. Make a pot of coffee while it boots.

    C should probably be the language of P2, which has a stack frame and the other cruft you need to make C work efficiently that P1 doesn't have. Spin is a great teaching language but you can't use it to teach if the education system insists on C, so C it should be. Get us up to speed on that and don't waste our time on other things. Yes of course we users will get 150 other languages running on P2 but Parallax needs to pick one as the official development language and make sure all the official docs and example code are in that language so the n00bs will know what to study. The only thing worse than having an unpopular official dev language will be having more than one.
  • Thanks @"Clock Loop", indeed you're doing your part!

    @localroger I understand the concern, but the outcome of a C-only ecosystem for P2 isn't going to happen. Why should Chip forgo completing his vision of a language that matches the hardware he spent 14 years developing? You might say "business potential" which certainly piques my interest, but there's more than that as motovation.

    Ken Gracey
  • Cluso99Cluso99 Posts: 18,066
    edited 2020-08-27 21:45
    @localroger,
    Respectfully, I disagree. IMHO Parallax spent so much $$ on bringing the P2 to fruition there’s not enough left in the kitty to bring even one good language to P2. That sounds like a convincing argument for your case, but it’s not and here’s why.

    Languages are being done by the forum members, plus Chip. Chip will do spin2 regardless and he has every right to after all. IMHO it’s being done wrong but it is what it is. Other languages are being done, such as Catalina C (being the first C out of the gate), Eric’s fastspin (pasm, spin, basic, C, etc). There is microPython - now an education requirement which seems to have overtaken C in this arena.

    IMHO Parallax needs to spend it’s limited resources into a working OBEX so that the various languages are supported. GIT is a dogs breakfast for newcomers. It’s not a solution for OBEX without some major $$, so an alternative needs to be found YESTERDAY!!! Every day this gets delayed, the P2 gets more fragmented. Currently there is no way to adequately put up an object for P2 (in any language) and have it readily available for everyone to access simply. So the very few people here are wasting time developing their own versions of objects because they cannot see what’s being done elsewhere.

    IMHO Parallax also needs to get behind Eric’s fastspin. IMHO PropTool 2.x is a wasted effort. As was said by Parallax over the past 10 years, PropTool (for P1) was a dead product and would never have the extensions necessary (conditional compilation, macros, etc) as so bst and homespun were written to address these issues. Subsequently OpenSpin was written but never received the support necessary to get used much.

    However, things have moved on. These days, the compilers have been decoupled from the editors. Here is where Parallax needs attention. Arguably, VSC (Microsoft’s Visual Source Code, not to be confused with Visual Source whatever) has exploded. It is a very viable open source, cross platform editor. Others and myself have done a basic descriptor for VSC for editing pasm and spin files. VSC can call any compiler automatically but this hasn’t been done by anyone yet tho’ it’s supposed to be easy. VSC already supports C, Python, etc, etc.

    So, VSC coupled with fastspin would be a game-changer IMHO. Parallax has the opportunity right now!

    Fastspin is missing the ability to compile spin2 to spin bytecode. This could easily be done but I totally understand Eric not doing this. Spin2 is a moving target, changing at the wim of Chip. Anything Eric could do could (and most likely will, as history has shown) be obsoleted by Chip at any time. Why would he put effort into this? This is why Parallax needs to get seriously behind it, not a token “we support him”.

    Just my wasted 2c
  • Ken, I understand your position. Frankly I much prefer Spin and think it's a vastly better language for n00bs. C and even worse C++ are terrible learning languages (I know you probably saw my thread on how terrible the Arduino is in this respect). What do you do when the market demands you do something that is really clearly wrong? Sometimes you have to sell them what they want. Been there, done that. Sometimes you just walk away, but that can be very hard.

    I did not find out the P1 existed until I stumbled across an article about the YBox2. At that point I found a gloriously vibrant ecosystem and an Obex full of ready to go projects and components that everyone could run and to which anyone could contribute, confident that anyone could run what they wrote. I don't think it's an overstatement to say that the Obex helped to make the P1, since it became the equivalent of that catalog where you could order a UART, an ADC, a video adapter, or whatever other software-hardware you needed for your 32 pin project. I am just worried that P2 will not enjoy that advantage. I have already rewritten the base ENC28J60 code for P2, in FastSpin; does that translate to Spin2? Does it help someone who has adopted C? How many people will actually find it useful? Where do I even put it, except here in the forums? If I go on to do a better TCP stack for it, since Harrison's memory-saving tricks aren't needed on P2, will it find users? These open questions simply weren't a problem when P1 was new.

    I really appreciate all the work you, Chip, and the folks at Parallax have put into these products. I realize the commercial situation at the moment makes this a question with no "right" or maybe even "good" answer. All I can do is put my finger on the scale to say "please keep this force in mind when deciding." Ultimately Parallax will determine its way forward, and you guys have always done a pretty good job at that.
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-08-28 04:16
    Can't delete, posted to wrong spot.


    Since the forum won't let me delete, let me indulge....

    cop-pulled-me-577698eb46.jpg
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-09-18 12:04

    So this is what SPIN users see. (ill attach the image of the first page to save you the trouble.)

    https://github.com/parallaxinc/propeller/blob/master/libraries/community/p1/All/WX ESP8266 SPIN Get Started/WX_SPIN_Text_Page-To-Micro Iss1.pdf
    WX_SPIN_Text_Page-To-Micro%20Iss1.jpg


    And now compare that to what C users see.

    https://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c/send-web-page-event-info-propeller


    Any questions?

    "new laptop" and "old laptop" Is it trying to tell me I need TWO laptops to run this thing?

    Post edited. I am a willing participant... are YOU?
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-09-09 10:23
    So all the example code located here is BUGGED.

    1. HAS NO BREAK TO ENTER COMMAND MODE, thus FAILS.

    2. Has POLL with no COLON, thus FAILS. (i guess POLL doesn't need a colon, but I had problems at one point without it.)

    https://github.com/parallaxinc/propeller/tree/master/libraries/community/p1/All/WX ESP8266 SPIN Get Started

    DO YOUR PART!


    Did I find a command mode POLL bug?

    I figured out I kinda did, I called ser.str(string("POLL")) WITHOUT a COLON. :
    The module responds with a Reply: '=N,0,0'
    When it should respond with a Reply: '=E,1' ?



    Heres the poll command I sent in TEXT FORM.
      ser.tx(254)  'Begin marker
      ser.str(string("POLL"))   'Tell the module to listen to ANY protocol/path.
      ser.tx(13)    'End marker  
    


    Heres the poll command in TOKEN FORM.
      ser.tx(254)  'Begin marker
      ser.str(string($EC))   'Tell the module to listen to ANY protocol/path.
      ser.tx(13)    'End marker
    

    When in TEXT FORM, i get NO reply, but TOKEN FORM, I get a reply.
    Am I doing something wrong in TEXT FORM?

    You can use the html HERE to prove it. (upload this html to your ParallaxWX module --> https://github.com/parallaxinc/propeller/blob/master/libraries/community/p1/All/WX ESP8266 SPIN Get Started/val-from-micro.html

    Heres the full prop code in TEXT FORM
    CON 
      _CLKMODE=XTAL1 + PLL16X                   ' The system clock spec
      _XINFREQ = 5_000_000                                  ' Crystal
    
      Rx        = 31     'serial in from wx device
      Tx        = 30     'serial out to wx device
    
    OBJ
    
        ser: "FullDuplexSerial.spin"
    
    VAR
    
        long Stack1[100]
    
    Pub Main   
    
    cognew(Comms, @Stack1)
    
    Pub Comms | CommandMode
        
      ser.Start(RX, TX, 0, 115200)   'Cog #2 
      waitcnt(80_000_000 + cnt)   'wait 1 second fpr serial to start.
                              
      Repeat
        ser.str(string(27))     'Set ansi command mode in putty.
        ser.str(string("[2J"))  'Clear putty telnet screen. 
      
        If CommandMode == 1    'Turn command mode on in spin.
          
          ser.str(string(27))      'Set ansi command mode in putty.                 
          ser.str(string("[2;3f")) 'Set Position in putty.      
          ser.str(string("Command Mode is On. ")) 'Tell putty command mode is on.      
          ser.str(string(27))      'Set ansi command mode in putty.      
          ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
          
          
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to stop.
          ser.Stop              'Turn off serial to send break.
        
          dira[TX]~~          ' Set direction to output
          outa[TX]:= 0        ' Set TX low.                         
          waitcnt(80_000_000 + cnt)   'wait 1 second for command mode to start in the module.
          dira[TX]~           ' Set direction to input  
    
          ser.Start(RX, TX, 0, 115200)   'Cog #2                                  
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to start.
        
          ser.tx(254)  'Begin marker
          ser.str(string("LISTEN:HTTP,/tpfm"))   'Tell the module to listen to a specific path on http port 80.
          ser.tx(13)    'End marker  
          waitcnt(80_000_000 + cnt)   'wait 1 second 
        
        
          Repeat 5      
            
            ser.tx(254)  'Begin marker
            ser.str(string("POLL"))   'Tell the module to listen to a ANY protocol/path.    TEXT FORM DOESN'T WORK. Comment out to test token form.
            'ser.str(string($EC))   'Tell the module to listen to ANY protocol/path.     TOKEN FORM WORKS. Uncomment to test.
            ser.tx(13)    'End marker                        
            
    
    
    
    
    
            waitcnt(80_000_000 + cnt)   'wait 1 second                   
        
          ser.tx(254)  'Begin marker
          ser.str(string("SET:cmd-enable,0"))   'Turn command mode off in the WX module.  
          ser.tx(13)    'End marker
          CommandMode := 0  'Turn command mode off in spin.
          waitcnt(80_000_000 + cnt) 'Wait for 1 s  
        
        
        ser.str(string(27))      'Set ansi command mode in putty.
        ser.str(string("[2;3f")) 'Set Position in putty.
        ser.str(string("Command Mode is Off."))   'Tell putty command mode is off.                          '                                           
        ser.str(string(27))      'Set ansi command mode in putty.                         '                        
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
        
          
        
        Repeat 5
          waitcnt(80_000_000 + cnt) 'Wait for 1 s  
        
        CommandMode := 1   'Turn command mode on in spin.
    
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-09-10 15:28
    Here is a working val-from-micro.spin to go with val-from-micro.html.

    It includes the .side file to use with SimpleIDE.

    You can speed it up by getting rid of many of the 1 second pauses, but be careful, you need to give the FullDuplexSerial.spin time to stop and start. If you stop it too fast, the data you sent will not send everything, and if you start it and don't wait long enough, you may lockup the prop.


    ''*******************************************************
    ''*  Putty Telnet Wireless WX Val-From-Micro Demo       *
    ''*  Author: Clock Loop @ parallax forums               *
    ''*  Upload the webpage val-from-micro.html to your WX  *
    ''*  Visit http://192.168.4.1/files/val-from-micro.html *
    ''*  I did not make the html, parallax did?             *          
    ''*******************************************************
    
    
    CON 
      _CLKMODE=XTAL1 + PLL16X                   ' The system clock spec
      _XINFREQ = 5_000_000                                  ' Crystal
    
      Rx        = 31     'serial in from wx device
      Tx        = 30     'serial out to wx device
    
    OBJ
    
        ser: "FullDuplexSerial.spin"
    
    VAR
        byte   LoopCounter
        long   Stack1[100]
    
    Pub Main   
    
    cognew(Comms, @Stack1)
    
    Pub Comms | CommandMode, Reply1, Reply2, Reply3, Reply4, Reply5, Reply6, Reply7, ReplyStatus
        
      ser.Start(RX, TX, 0, 115200)   'Cog #2 
      waitcnt(80_000_000 + cnt)   'wait 1 second for serial to start.
                
      Repeat                'The main repeat loop.
        ser.str(string(27))     'Set ansi command mode in putty.
        ser.str(string("[2J"))  'Clear putty telnet screen. 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty
                                                               
        If ReplyStatus == 1     
          ser.str(string("Good reply."))   'If last reply was good, put it back up on putty which was cleared.                
        Else
          ser.str(string(" Bad reply."))    'If last reply was bad, put it back up on putty which was cleared.   
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty
        ser.str(string("Loop count number that should be shown on webpage: ")) '
        ser.dec(LoopCounter) 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
    
        If CommandMode == 1    'Check for command mode on in spin.
          
          ser.str(string(27))      'Set ansi command mode in putty.                 
          ser.str(string("[2;3f")) 'Set Position in putty.      
          ser.str(string("Command Mode is On. ")) 'Tell putty command mode is on.                       
          ser.str(string(27))      'Set ansi command mode in putty.      
          ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
          
          
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to stop.
          ser.Stop              'Turn off serial to send break.
        
          dira[TX]~~          ' Set direction to output
          outa[TX]:= 0        ' Set TX low.                         
          waitcnt(80_000_000 + cnt)   'wait 1 second for command mode to start in the module.
          dira[TX]~           ' Set direction to input  
    
          ser.Start(RX, TX, 0, 115200)   'Cog #2                                  
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to start.
                                 
          ser.tx(254)  'Begin marker
          ser.str(string("LISTEN:HTTP,/tpfm"))   'Tell the module to listen to a specific path on http port 80.
          ser.tx(13)    'End marker  
          waitcnt(80_000_000 + cnt)   'wait 1 second 
                         
          ReplyStatus := 0     'Set the reply to bad so it can recheck for a new reply.
        
          Repeat 10
            ser.rxflush
            ser.tx(254)  'Begin marker
            ser.str(string("POLL:"))   'Tell the module to listen to a ANY protocol/path.
            ser.tx(13)    'End marker
            Reply1 := ser.rxtime(1)   ' should be 254
            Reply2 := ser.rxtime(1)   ' should be =
            Reply3 := ser.rxtime(1)   ' should be G
            Reply4 := ser.rxtime(1)   ' should be ,
            Reply5 := ser.rxtime(1)   ' should be 5  (this could change)
            Reply6 := ser.rxtime(1)   ' should be ,
            Reply7 := ser.rxtime(1)   ' should be 1
            waitcnt(80_000_000 + cnt) 'Wait for 1 s 
                                      '
            If Reply1 == 254 And Reply2 == "=" And Reply3 == "G"
              ReplyStatus := 1     'Set the reply to good so it can be shown in putty.
              
              ser.tx(254)               'Begin marker
              ser.str(string("REPLY:")) 'Tell the module to send a reply to the poll response.
              ser.tx(Reply5)            'Should be a number.   An active connection handle; returned by POLL.
              ser.str(string(","))      'Required for a reply
              ser.str(string("200"))    'The desired HTTP response code for the reply.                         
              ser.str(string(","))      'Required for a reply
              
              If LoopCounter < 10
                ser.str(string("1"))      'Tell the module how many bytes? (or is this digits?) the reply is.
              
              Elseif LoopCounter > 9 AND LoopCounter < 100
                ser.str(string("2"))      'Tell the module how many bytes? (or is this digits?) the reply is.
              
              Else 
                ser.str(string("3"))      'Tell the module how many bytes? (or is this digits?) the reply is. 
                    
              ser.tx(13)                'End marker
              ser.dec(LoopCounter)      'Send 1 byte (which is up to 3 characters (in decimal) (254) of data to the module which then sends it to the webpage.
                  
          waitcnt(80_000_000 + cnt) 'Wait for 1 s 
          ser.tx(254)  'Begin marker
          ser.str(string("SET:cmd-enable,0"))   'Turn command mode off in the WX module.
          ser.tx(13)    'End marker
          CommandMode := 0  'Turn command mode off in spin.
                            '     
        ser.str(string(27))      'Set ansi command mode in putty.
        ser.str(string("[2;3f")) 'Set Position in putty.
        ser.str(string("Command Mode is Off."))   'Tell putty command mode is off.                                                                                                          
        
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty                                                                                         
    
        If ReplyStatus == 1      
          ser.str(string("Good reply."))  
                                                                          
        Else
          ser.str(string(" Bad reply.")) 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty
        ser.str(string("Loop count number that should be shown on webpage: ")) '
        ser.dec(LoopCounter)
        
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
        
        Repeat 5
          waitcnt(80_000_000 + cnt) 'Wait for 1 s 
                  
        CommandMode := 1   'Turn command mode on in spin.
        LoopCounter++
        If LoopCounter > 254  'Deal with rollover.
          LoopCounter := 0 
    
    {{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                  TERMS OF USE: MIT License
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
    // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    // Software is furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
    // Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      
    }}   
    
    
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-09-10 16:01
    Heres a version of the above code with Parallax Serial Terminal instead of FullDuplexSerial.

    WHY did the coder of Parallax Serial Terminal make rxcheck PRIVATE?????

    FullDuplexSerialPlus contained the best of both of these, and was ELIMINATED???

    So now Parallax Serial Terminal is missing RxCheck (because its private) and
    RxTime() <--that is so necessary!
    So technically Parallax Serial Terminal provides no way to get data without BLOCKING?

    BOOOOOOOOOOOOO!
    ''*******************************************************
    ''*  Putty Telnet Wireless WX Val-From-Micro Demo       *
    ''*  Author: Clock Loop @ parallax forums               *
    ''*  Upload the webpage val-from-micro.html to your WX  *
    ''*  Visit http://192.168.4.1/files/val-from-micro.html *
    ''*  I did not make the html, parallax did?             *          
    ''*******************************************************
    
    
    CON 
      _CLKMODE=XTAL1 + PLL16X                   ' The system clock spec
      _XINFREQ = 5_000_000                                  ' Crystal
    
      Rx        = 31     'serial in from wx device
      Tx        = 30     'serial out to wx device
    
    OBJ
    
        ser: "Parallax Serial Terminal.spin"
    
    VAR
        byte   LoopCounter
        long   Stack1[100]
    
    Pub Main   
    
    cognew(Comms, @Stack1)
    
    Pub Comms | CommandMode, Reply1, Reply2, Reply3, Reply4, Reply5, Reply6, Reply7, ReplyStatus
        
      ser.StartRxTx(RX, TX, 0, 115200)   'Cog #2 
      waitcnt(80_000_000 + cnt)   'wait 1 second for serial to start.
                
      Repeat                'The main repeat loop.
        ser.str(string(27))     'Set ansi command mode in putty.
        ser.str(string("[2J"))  'Clear putty telnet screen. 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty
                                                               
        If ReplyStatus == 1     
          ser.str(string("Good reply."))   'If last reply was good, put it back up on putty which was cleared.                
        Else
          ser.str(string(" Bad reply."))    'If last reply was bad, put it back up on putty which was cleared.   
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty to put cursor at 0 
        ser.str(string("Loop count number that should be shown on webpage: ")) '
        ser.dec(LoopCounter) 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
    
        If CommandMode == 1    'Check for command mode on in spin.
          
          ser.str(string(27))      'Set ansi command mode in putty.                 
          ser.str(string("[2;3f")) 'Set Position in putty.      
          ser.str(string("Command Mode is On. ")) 'Tell putty command mode is on.                       
          ser.str(string(27))      'Set ansi command mode in putty.      
          ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
          
          
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to stop.
          ser.Stop              'Turn off serial to send break.
        
          dira[TX]~~          ' Set direction to output
          outa[TX]:= 0        ' Set TX low.                         
          waitcnt(80_000_000 + cnt)   'wait 1 second for command mode to start in the module.
          dira[TX]~           ' Set direction to input  
    
          ser.StartRxTx(RX, TX, 0, 115200)   'Cog #2                                  
          waitcnt(80_000_000 + cnt)   'wait 1 second for serial to start.
                                 
          ser.char(254)  'Begin marker
          ser.str(string("LISTEN:HTTP,/tpfm"))   'Tell the module to listen to a specific path on http port 80.
          ser.char(13)    'End marker  
          waitcnt(80_000_000 + cnt)   'wait 1 second 
                         
          ReplyStatus := 0     'Set the reply to bad so it can recheck for a new reply.
        
          Repeat 10
            ser.rxflush
            ser.char(254)  'Begin marker
            ser.str(string("POLL:"))   'Tell the module to listen to a ANY protocol/path.
            ser.char(13)    'End marker
            waitcnt(80_000_000 + cnt) 'Wait for 1 s for rx buffer to fill.
            Reply1 := ser.rxcheck   ' should be 254
            Reply2 := ser.rxcheck   ' should be =
            Reply3 := ser.rxcheck   ' should be G
            Reply4 := ser.rxcheck   ' should be ,
            Reply5 := ser.rxcheck   ' should be 5  (this could change)
            Reply6 := ser.rxcheck   ' should be ,
            Reply7 := ser.rxcheck   ' should be 1
            waitcnt(80_000_000 + cnt) 'Wait for 1 s 
                                      '
            If Reply1 == 254 And Reply2 == "=" And Reply3 == "G"
              ReplyStatus := 1     'Set the reply to good so it can be shown in putty.
              
              ser.char(254)               'Begin marker
              ser.str(string("REPLY:")) 'Tell the module to send a reply to the poll response.
              ser.char(Reply5)            'Should be a number.   An active connection handle; returned by POLL.
              ser.str(string(","))      'Required for a reply
              ser.str(string("200"))    'The desired HTTP response code for the reply.                         
              ser.str(string(","))      'Required for a reply
              
              If LoopCounter < 10
                ser.str(string("1"))      'Tell the module how many bytes? (or is this digits?) the reply is.
              
              Elseif LoopCounter > 9 AND LoopCounter < 100
                ser.str(string("2"))      'Tell the module how many bytes? (or is this digits?) the reply is.
              
              Else 
                ser.str(string("3"))      'Tell the module how many bytes? (or is this digits?) the reply is. 
                    
              ser.char(13)                'End marker
              ser.dec(LoopCounter)      'Send 1 byte (which is up to 3 characters (in decimal) (254) of data to the module which then sends it to the webpage.
                  
          waitcnt(80_000_000 + cnt) 'Wait for 1 s 
          ser.char(254)  'Begin marker
          ser.str(string("SET:cmd-enable,0"))   'Turn command mode off in the WX module.
          ser.char(13)    'End marker
          CommandMode := 0  'Turn command mode off in spin.
                            '     
        ser.str(string(27))      'Set ansi command mode in putty.
        ser.str(string("[2;3f")) 'Set Position in putty.
        ser.str(string("Command Mode is Off."))   'Tell putty command mode is off.                                                                                                          
        
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty to put cursor at 0                                                                                               
    
        If ReplyStatus == 1      
          ser.str(string("Good reply."))  
                                                                          
        Else
          ser.str(string(" Bad reply.")) 
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty
        ser.str(string("Loop count number that should be shown on webpage: ")) '
        ser.dec(LoopCounter)
        
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
        
        Repeat 5
          waitcnt(80_000_000 + cnt) 'Wait for 1 s 
                  
        CommandMode := 1   'Turn command mode on in spin.
        LoopCounter++
        If LoopCounter > 254  'Deal with rollover.
          LoopCounter := 0 
    
    {{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                  TERMS OF USE: MIT License
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
    // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    // Software is furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
    // Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      
    }}   
    
    
  • Clock LoopClock Loop Posts: 2,069
    edited 2020-09-10 15:54
    Heres the "Motor control with sliders", IN SPIN. YEAH BOI.

    https://learn.parallax.com/tutorials/language/propeller-c/parallax-wx-wi-fi-module-prop-c/motor-control-sliders

    Its done with Parallax Serial Terminal.

    Don't make fun of my coding.

    BEWARE your PROP will restart if you change the servo pwm too fast.
    Tie the servo ground close to the power supply, not near the prop.
    Like as if the prop ground is on a different branch than the servo.
    That worked for me.
    ''*''**************************************************************
    ''*  Putty Telnet Wireless WX Page Controls Servo Host Demo    *
    ''*  Author: Clock Loop @ parallax forums                      *
    ''*  Upload the webpage page-controls-servo.html to your WX    *
    ''*  Visit http://192.168.4.1/files/page-controls-servo.html   *
    ''*  I did not make the html, parallax did?                    *          
    ''**************************************************************
    
    
    CON 
      _CLKMODE=XTAL1 + PLL16X                   ' The system clock spec
      _XINFREQ = 5_000_000                                  ' Crystal
    
      Rx        = 31     'serial in from wx device
      Tx        = 30     'serial out to wx device
      ServoPin  = 0
    
    OBJ
        SERVO : "Servo32v7.spin"
        ser: "Parallax Serial Terminal.spin"
    
    VAR
        byte   Angle, Handle, ReplyStatus
        long   Stack1[100]
    
    Pub Main   
    
    cognew(Comms, @Stack1)
    
    Pub Comms | CommandMode, ServoPwm, ServoPwm1, ServoPwm2
      
      ServoPwm := 0
      ReplyStatus := 0  
      
      dira[TX]~~          ' Set direction to output
      outa[TX]:= 0        ' Set TX low.                         
      waitcnt(10_000_000 + cnt)   'wait 1/10 second for command mode to start in the module.
      dira[TX]~           ' Set direction to input  
      
      ser.StartRxTx(RX, TX, 0, 115200)   'Cog #2 
      waitcnt(10_000_000 + cnt)   'wait 1/10 second for serial to start.
      SERVO.Start                 ' Cog 3 Start servo handler  
      
                           
      ser.char(254)  'Begin marker
      ser.str(string("LISTEN:HTTP,/servo"))   'Tell the module to listen to a specific path on http port 80.
      ser.char(13)    'End marker     
      
      ser.str(string(27))     'Set ansi command mode in putty.
      ser.str(string("[2J"))  'Clear putty telnet screen. 
          
      ser.str(string(27))      'Set ansi command mode in putty.                 
      ser.str(string("[2;3f")) 'Set Position in putty.      
      ser.str(string("Prop Started")) 'Tell putty command mode is on.                       
      ser.str(string(27))      'Set ansi command mode in putty.      
      ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0        
      Repeat 10  ' wait 10 seconds to help determine if servo reset prop.
        waitcnt(80_000_000 + cnt)   'wait 1 second 
            
      Repeat                'The main repeat loop.
        ser.str(string(27))     'Set ansi command mode in putty.
        ser.str(string("[2J"))  'Clear putty telnet screen. 
        
        ser.str(string(27))      'Set ansi command mode in putty.                 
        ser.str(string("[2;3f")) 'Set Position in putty.      
        ser.str(string("Command Mode is On. ")) 'Tell putty command mode is on.                       
        ser.str(string(27))      'Set ansi command mode in putty.      
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[4;3f")) 'Set Position in putty
                                                               
        If ReplyStatus == 1     
          ser.str(string("Good reply."))   'If last reply was good, put it back up on putty which was cleared.                
        Else
          ser.str(string("  No reply."))    'If last reply was bad, put it back up on putty which was cleared.   
    
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[5;3f")) 'Set Position in putty to put cursor at 0 
        ser.str(string("Angle that the webpage sent: ")) '
        ser.dec(Angle)
        
        ser.str(string(27))      'Set ansi command mode in putty.                                             
        ser.str(string("[6;3f")) 'Set Position in putty
        ser.str(string("Calculate Pwm Output: ")) '
        ser.dec(ServoPwm)
    
        ser.str(string(27))      'Set ansi command mode in putty.                                               
        ser.str(string("[1;1f")) 'Set Position in putty to put cursor at 0
    
                                  '           
        ReplyStatus := 0     'Set the reply to bad so it can recheck for a new reply.
          
        Reply[0] := 0  ' clear data
        Reply[1] := 0  ' clear data
        Reply[2] := 0  ' clear data
        Reply[3] := 0  ' clear data
        Reply[4] := 0  ' clear data
        Reply[5] := 0  ' clear data
        Reply[6] := 0  ' clear data
        Reply[7] := 0  ' clear data
          
        Repeat 10
            ser.rxflush
            ser.char(254)  'Begin marker
            ser.str(string("POLL:"))   'Tell the module to listen to a ANY protocol/path.
            ser.char(13)    'End marker
            waitcnt(10_000_000 + cnt) 'Wait for 1/10 s  Let buffer fill.
            Reply[0] := ser.rxcheck   ' should be 254
            Reply[1] := ser.rxcheck   ' should be =
            Reply[2] := ser.rxcheck   ' should be P
            Reply[3] := ser.rxcheck   ' should be ,
            Reply[4] := ser.rxcheck   ' should be 5 (this could change) The connection identifier to use for this request
            Reply[5] := ser.rxcheck   ' should be ,
            Reply[6] := ser.rxcheck   ' should be 1
            Reply[7] := ser.rxcheck   ' should be 13   
                                               
            
            If Reply[0] == 254 And Reply[1] == "=" And Reply[2] == "P" And Reply[7] == 13
                ReplyStatus := 1     'Set the reply to good so it can be shown in putty.
              
                Handle := Reply[4]  'Store connection identifier.
              
                Reply[0] := 0  ' clear data
                Reply[1] := 0  ' clear data
                Reply[2] := 0  ' clear data
                Reply[3] := 0  ' clear data
                Reply[4] := 0  ' clear data
                Reply[5] := 0  ' clear data
                Reply[6] := 0  ' clear data
                Reply[7] := 0  ' clear data                  
                
                ser.rxflush             
                ser.char(254)               'Begin marker
                ser.str(string("ARG:"))   'Retrieve HTTP GET/POST’s name argument (in query or body) on connection handle.
                ser.char(Handle)            'An active connection handle; returned by POLL
                ser.str(string(","))      'Required for a reply
                ser.str(string("angle"))  'The argument name to retrieve.   
                ser.char(13)                'End marker                                    
                waitcnt(10_000_000 + cnt) 'Wait for 1/10 s   Let buffer fill.
                Reply[0] := ser.rxcheck   ' should be 254
                Reply[1] := ser.rxcheck   ' should be =
                Reply[2] := ser.rxcheck   ' should be S
                Reply[3] := ser.rxcheck   ' should be ,
                Reply[4] := ser.rxcheck   ' should be argument value  (this could change) -1 no reply
                Reply[5] := ser.rxcheck   ' should be argument value  (this could change) -1 no reply. This could also be 13
                Reply[6] := ser.rxcheck   ' should be argument value  (this could change) -1 no reply. This could also be 13
                Reply[7] := ser.rxcheck   ' should be 13                                         
                        
                If Reply[0] == 254 And Reply[1] == "=" And Reply[2] == "S" 
                  If Reply[5] == 13  'The end marker
                    Reply[5] := 0    'Zero terminate the string so it can be converted to decimal.
                  
                  Elseif Reply[6] == 13  'The end marker
                    Reply[6] := 0    'Zero terminate the string so it can be converted to decimal.
                
                  Else                 'The end marker all other conditions the end marker is a byte 7
                    Reply[7] := 0     'Zero terminate the string so it can be converted to decimal.        
                  
                  Angle := ser.StrToBase(@word[@Reply[4]], 10)  ' store and convert string angle in byte variable angle.
                  ServoPwm1 := Angle + 30       'convert angle to pwm 
                  ServoPwm2 := ServoPwm1 / 2  'convert angle to pwm 
                  ServoPwm := 12 * ServoPwm1 + ServoPwm2  'convert angle to pwm 
                              
                  SERVO.Set(ServoPin, ServoPwm) 'Set angle of servo.                               
                  'BEWARE your PROP will restart if you change the servo pwm too fast.
                  'Tie the servo ground close to the power supply, not near the prop.
                  'Like as if the prop ground is on a different branch than the servo.                   
                   
                  ser.char(254)               'Begin marker
                  ser.str(string("REPLY:")) 'Tell the module to send a reply to the poll response.
                  ser.char(Handle)            'Should be a number.   An active connection handle; returned by POLL.
                  ser.str(string(","))      'Required for a reply
                  ser.str(string("200"))    'The desired HTTP response code for the reply.                         
                  ser.str(string(","))      'Required for a reply
                  ser.str(string("2"))      'Tell the module how many bytes? (or is this digits?) the reply is.
                  ser.char(13)                'End marker               
                  ser.str(string("OK"))     'Send OK to the webpage.
                  ser.char(13)    'End marker                                 
                  'waitcnt(80_000_000 + cnt) 'Wait for 1/2 s
    DAT
    
    Reply   byte  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    
    
    {{
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //                                                  TERMS OF USE: MIT License
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
    // files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
    // modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
    // Software is furnished to do so, subject to the following conditions:
    //
    // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
    // Software.
    //
    // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
    // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////      
    }}   
    

Sign In or Register to comment.