Shop OBEX P1 Docs P2 Docs Learn Events
serial comm with propeller — Parallax Forums

serial comm with propeller

realolman1realolman1 Posts: 55
edited 2016-12-02 15:36 in Propeller 1
I would like to communicate with the propeller using serial comms. It seems like everything I can find on the subject immediately jumps way past my skill set.

This is what I would like to do to try to get a hold on the subject:

how about the propeller adds two numbers together and then sends the results to the serial terminal or something very simple like that, so the use of the full duplex program doesn't get lost in pages of programming ?

If I can just see how a simple task would be accomplished, I think I could expand upon it, but I never am able to find anything that is on a level this simple.

I have the fullduplexSerial driver installed... could someone show me an extremely simple program that uses it to send and/or receive between the Serial terminal and the propeller, using nothing but the serial cable and possibly some resistors and jumpers .... maybe the propeller could send which input is high or low.... that'd be great
thank you

and it would appear that I probably put this in the wrong forum category ... sorry

Comments

  • Moved to Prop1
  • Duane DegnDuane Degn Posts: 10,588
    edited 2016-12-02 16:23
    Parallax Serial Terminal.spin has a "DecIn" method which makes this sort of program easier.

    Here's a program which requests two numbers and provides a total.

    You'll want to make sure to familiarize yourself with ASCII encoding of characters.
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      BAUD = 115200
      QUOTE = 34
      
    VAR
    
      long sumOfTwoNumbers
    
    OBJ
    
      Pst : "Parallax Serial Terminal"
        
    PUB Main | firstNumber, secondNumber
    
      Pst.Start(115200)
    
      ' Wait for key press so program knows terminal is ready.
      repeat
        result := Pst.RxCount
        Pst.Str(string(11, 13, "Press any key to start."))
        waitcnt(clkfreq / 2 + cnt)
      until result ' stop loop when result is non-zero
    
      repeat
        Pst.Str(string(11, 13, "Enter first of two numbers to add:"))
        firstNumber := Pst.DecIn
        Pst.Str(string(11, 13, "You entered ", QUOTE))
        Pst.Dec(firstNumber)
        Pst.Char(QUOTE)
        Pst.Str(string(11, 13, "Enter second number:"))
        secondNumber := Pst.DecIn
        Pst.Str(string(11, 13, "You entered ", QUOTE))
        Pst.Dec(secondNumber)
        Pst.Char(QUOTE)
        Pst.ClearEnd
        Pst.NewLine
        Pst.Dec(firstNumber)
        Pst.Str(string(" + "))
        Pst.Dec(secondNumber)
        Pst.Str(string(" = "))
        sumOfTwoNumbers := firstNumber + secondNumber
        Pst.Dec(sumOfTwoNumbers)
        
    

    I mixed local and global variables for the heck of it.

    Here's the output:
    Press any key to start.
    Press any key to start.
    Press any key to start.
    Enter first of two numbers to add:
    You entered "5"
    Enter second number:
    You entered "8"
    5 + 8 = 13
    Enter first of two numbers to add:
    

    There are many different ways this sort of program could be written.
  • Hey Mr. Duane Degn,

    Your program works like a charm.... now I'll have to study it and see if I can understand how it works.

    Thank you very much
  • Here are a few hints.

    I don't know if you're familiar with the carriage return character but this character has the numeric value 13. The value 11 is used by the Parallax Serial Terminal.exe program to clear the end of a line. I the combination of 11 and 13 to clear the end of a line and then move to the next line down.

    Clearing the end of the line becomes a lot more important when you have text which stays in one location on the screen.

    I used the constant "QUOTE" in place of the double quote character. You can see this character has the numeric value 34. You can see the numeric value of many characters by selecting "Help"\"View Character Chart".

    Wikipedia has a good article on ASCII characters. If you're not familiar with ASCII characters, I suggest you look at the Wikipedia article.
  • realolman1realolman1 Posts: 55
    edited 2016-12-04 12:36
    I am, as my username states, pretty old... I am very familiar with ASCII characters.

    What I would like to eventually do is communicate between the propeller and a BASIC program ... whatever is the current free version...if the current version will do serial comms

    I have tried that in the past with very little success.

    The best success I ever had was using a LAB JACK, but I would like to try some things that don't require the computer to be involved continuously.

    I always was hooked on this kind of thing but never had the time. I retired a little over a year ago and now I have more time.

    Thank you for your help, and please don't hesitate to provide more
  • Thanks to your program, I am now able to turn LED's on and off from a small program I wrote in Visual basic.

    I know that is small potatoes for many of you, but it's a giant leap from where I was this morning.
    thank you
  • how about the propeller adds two numbers together and then sends the results to the serial terminal or something very simple like that, so the use of the full duplex program doesn't get lost in pages of programming ?

    Believe it or not, that's a fairly sophisticated task. I do this kind of thing a lot (well, not adding numbers, but processing commands). I created a parser object that gets used in a lot of personal and professional projects. It allows me to accept commands from a serial stream, or -- as in a few designs -- I can read a string from a file and send it to the parser for processing. This allows my projects to have command files that are simple text.

    I've attached a demo in case you want to give it a try.
  • I appreciate your input, but you are pretty much what I was talking about in the OP... way over my head right off the bat.

    Maybe eventually I will get to where you are with "parsers" and "serial streams", but now I am clueless about a parser. I looked it up and became even more clueless.

    I modified some of what Duane Degn posted to end up with this:
    repeat while CharRec<>"x"    'x will stop the loop
    
        Pst.Str(string(11, 13, "Press any key to start."))  
     
        result := Pst.RxCount
    
          Pst.Char(16)
    
         result := Pst.RxCount  
    
       CharRec:= Pst.CharIn
       
         
        case CharRec  
         
         "s": Pst.Str(string(11, 13, "found s."))
              !outa[16] 'toggle 16 if s        
            
         "q": 
            Pst.Str(string(11, 13, "found q."))
             !outa[17] 'toggle 17 if q
    
    In a Visual basic program I put a few buttons that "Write" either an "s", "q", or an "x"

    the propeller toggles LEDs according to the character received.
    It seems to me that something like this could be modified and expanded to be much more useful

    I get lost pretty much immediately in many of the programs posted by people who know a lot more that I do

    I don't want to be an ingrate... I just don't know what to do with the files you posted... I looked at them and they are way over my head.

    thank you
  • It's great you were able to control a couple LEDs with from the computer.

    I have a list of tutorials in my "index" (it's not alphabetized so I'm not sure why I call is an index). The third post in the thread has the tutorial links.

    I personally learned Spin from the original Propeller Manual (v1.0).

    If I were starting again, I'd probably use Parallax's Learn site and the Propeller Education Kit (PEK) materials to learn to program the Propeller.

    JonnyMac publishes articles titled "Spin Zone" in Nuts and Volts. I've learned a lot from these articles. Jon's articles particular helped me understand programming using assembly (PASM). (There's a link to Jon's articles in my index.)

    I also learned a lot from reading these forums. I think you'll be hard pressed to find a friendlier electronic forum than this one here at Parallax.

    I started learning about microcontrollers about eight years ago. I had always thought I'd like to be able to program microcontrollers but I had severely underestimated how fun this stuff can be. Here's a playlist I put together showing some of the fun I've had with the Propeller.
  • JonnyMacJonnyMac Posts: 9,104
    edited 2016-12-05 15:03
    Keep in mind, that every skill is learned -- nobody expects you or any other new person to understand the code right away. There are many roads that lead to Rome, it's finding a solution that is applicable across a broad range of applications that drove me to create my parser object. It now gets used in a lot of my personal projects, and even some commercial devices (like the Parallax hackable badge, and products from EFX-TEK).

    Keep experimenting, keep learning Spin, and keep looking at programs written by others. As your skills improve things will begin to make sense. It works that way for all of us.
    I just don't know what to do with the files you posted
    Run the program (jm_parser_demo) and open a terminal (I use PST, but any serial connection will work). The syntax for the included commands are detailed in the code. The easy ones that you can try with an LED are HIGH, LOW, and TOGGLE.
    I am clueless about a parser
    A parser breaks apart some form of string input so that the constituent parts can be dealt with. For example, if you run my program on the PAB, open a terminal, and the entering HIGH 26 followed by [Enter], the LED will light. The parser code takes all the characters until you press Enter, and then breaks them up (using spaces or other non-characters as separators). It then looks into its known list of commands. LOW is in that list. In the code that handles LOW, the second parameter needs to be a number between 0 and 27 (I protect the I2C and serial pins with my commands).

    Again, I didn't knock out that code overnight, you won't learn it overnight, either (especially being new).

    I don't consider you ungrateful. That said, neither will I pat you on the head and tell you it's going to be alright with no effort on your part -- that wouldn't be fair to you. There are a lot of great contributors here (like Duane); look at everything they post and it will ultimately make sense. Any person that you are learning from has gone through what you are now.

    Since you're playing with PST (not my usual choice), let me show you how you can extend the control you want with features that are built into that object. This bit of code uses single letter commands (as you did), and allows you to enter a specific pin #.
    pub main | cmd, pin                                                        
                                                                     
      pst.start(115_200)  
    
      repeat
        cmd := pst.charin
        pin := pst.decin
    
        case cmd
          "h", "H" :
            pst.str(string("HIGH "))
            pst.dec(pin)
            pst.newline
            if ((pin => 0) and (pin =< 27))
              outa[pin] := 1
              dira[pin] := 1
    
          "l", "L" :
            pst.str(string("LOW "))
            pst.dec(pin)
            pst.newline      
            if ((pin => 0) and (pin =< 27))  
              outa[pin] := 0
              dira[pin] := 1
    
          "t", "T" :
            pst.str(string("TOGGLE "))
            pst.dec(pin)
            pst.newline
            if ((pin => 0) and (pin =< 27))  
              !outa[pin] 
              dira[pin] := 1
    
          other:
            pst.str(string("Bad command")) 
            pst.newline
    

    Note that by using the decin() method, you can specify any pin -- no need to have a letter per pin. This structure always wants a command and a pin.

    To turn on the P26 LED on a PAB you would enter (without the quotes) "h 26" and then press [Enter].

    The next step is to modify this program so that the letter will call a method that will accept the number of parameters required for it (0 to n...) -- this is when it starts to get fun.
  • realolman1realolman1 Posts: 55
    edited 2016-12-05 15:23
    How friendly and helpful you guys are... thank you

    I will try the things you posted.


  • realolman1 wrote: »
    I am, as my username states, pretty old... I am very familiar with ASCII characters.

    What I would like to eventually do is communicate between the propeller and a BASIC program ... whatever is the current free version...if the current version will do serial comms

    I have tried that in the past with very little success.

    The best success I ever had was using a LAB JACK, but I would like to try some things that don't require the computer to be involved continuously.

    I always was hooked on this kind of thing but never had the time. I retired a little over a year ago and now I have more time.

    Thank you for your help, and please don't hesitate to provide more

    There is a free "Basic" called RobotBasic that has serial methods built in for communicating with microcontrollers. It is located at robotbasic.org/

    There is a free tutorial and a number of not-free books, including one that is targeted at the propeller (A Hardware Interfacing and Control Protocol using RobotBasic and the Propeller Chip).

    Serial connections can be made between the computer with RobotBasic and the Propeller using wired or wireless methods.

    One use is to collect information and save it with the propeller, then send it to RobotBasic where it is processed and displayed or saved for use in other PC programs.

    tom
  • Thank you I will look into it
    One use is to collect information and save it with the propeller, then send it to RobotBasic where it is processed and displayed or saved for use in other PC programs.

    That sounds like the thing
Sign In or Register to comment.