Shop OBEX P1 Docs P2 Docs Learn Events
SIN pin 16 — Parallax Forums

SIN pin 16

willthiswork89willthiswork89 Posts: 359
edited 2006-08-12 01:04 in BASIC Stamp
ive been reading the syntax help guide and the code

sData·· VAR···· Byte

Main:
· SERIN 16, 16780, [noparse][[/noparse]WAIT("XYZ"), DEC sData]
· END

doesnt work, actually none of it works when i use the DEC modifier the only time ive gotten it to continue what when i did

sData VAR Byte
Main:
SERIN 16,16780,[noparse][[/noparse]sData]
END

why doesnt it work when i use the dec formatter? im using a homework board for tests because it doesnt matter if i ruin it.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-10 08:48
    Kevin -

    I doubt the DEC formatter has anything to do with it. As I remember, SIN (pin port 16) uses a fixed baud rate of 9600.

    Thus, if you are actually sending at 2400 baud, the Stamp will essentially be receiving garbage, and the WAIT("XYZ") will NEVER make a match. Therefore, your example one will NOT work, and example two WILL work, but it will be receiving garbage. The proof of what I suspect is to add the following line to the second example program:

    DEBUG sData

    Was garbage printed?

    The solution is to transmit and receive at 9600 baud, if you are going to use the SIN pin (pin port 16).

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-10 09:26
    ahh yes thanks Bruce! now im got two connected and its working wonderfully but when i try to add a delay into the mix it says garbage

    SEROUT 1\0, 24660, 1000, 2000, No_Permission, [noparse][[/noparse]"SLOWLY!"]

    Editor error is "Expected a label?"

    the thing for serout says

    SEROUT TPIN{\FPIN},Baud Mode,{Pace,}{Timeout, TLabel,}[noparse][[/noparse]Output Data]

    SEROUT 1\0, 24660, 1000, 2000,No_Permission,[noparse][[/noparse]"SLOWLY"]

    its highlighting the 2000 for some reason....
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-10 13:14
    Kevin -

    I guess you skimmed over this caveat in the PBASIC Help File when you were reading it:

    "Pace is an optional variable/constant/expression (0 - 65535) that determines the length of the pause between transmitted bytes. NOTE: Pace cannot be used simultaneously with Timeout."

    Pacing makes no sense when flow control is being used. One or the other, but not both.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-10 13:55
    oh okay yes i must have missed that part! thank you bruce
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-10 14:08
    The baud rate at the Programming Port can be other supported baud rates besides 9600 bps, however timing may have been an issue here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-10 14:56
    Hey guys is there a way to check is a cirtain string arrives, basically im waiting for multiple commands but i have one serin sending data to a STR array and i dunno how to check that string for cirtain commands, i looked up IF in the pbasic but it doesnt say anything about string comparison?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-10 15:39
    Kevin -

    PBASIC has no string comparison facility, thus you must check it one character at a time. If this is a "system" of your own design, limit the "commands" to a single character, and you'll have no problems.

    OTOH. if you are only seeking certain POSITIONAL parameters within a fixed character string, check out the SKIP formatter. If this is the case and you need an example, just ask.

    Your technical service support bill is really mounting up this month smile.gif

    Regards,

    Bruce Bates
    just kidding

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-10 16:09
    Check_Packet:
    IF(serStr(0) = "L" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    DEBUG CR,"GREEN or RED: "
    SERIN 16,16468,Bad_Data, [noparse][[/noparse]WAIT("!"),STR serStr\9\"!"]
    IF(serStr(0) = "R" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    LEDm = 1
    LEDp = 0
    ELSEIF(serStr(0) = "G" AND serStr(1) = "R" AND serStr(2) = "E")THEN
    LEDm = 0
    LEDp = 1
    ENDIF
    ENDIF

    IF(serStr(0) = "P" AND serStr(1) = "I" AND serStr(2) = "E") THEN
    FREQOUT Piezo,2000,3000
    ENDIF
    RETURN


    thats what i came up with, any revisions you guys can think of would be appreciated, its not for any project thats big im just trying to understand whats going on here.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-08-10 16:18
    Does it work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-10 16:31
    Kevin -

    You may need to have your glasses prescription checked, as you're OBVIOUSLY NOT READING THE REPLIES WE ARE LEAVING FOR YOU! This is CERTAINLY a "system of your own design" so I leave you with this, which I already said:

    "If this is a "system" of your own design, limit the "commands" to a single character, and you'll have no problems."

    Sorry, Kevin, but I've run out of patience. I'm sure others will be happy to help you. In the nearly 10 years I've helped folks on this Stamp List, this is the FIRST TIME I've thrown in the towel. Perhaps that will give you something to think about.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 8/10/2006 4:46:20 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2006-08-10 16:53
    You're trying to do relatively complicated things with a fairly simple and limited system (PBasic and the Stamp) when you are just learning. This is a recipe for problems (which you seem to be having). You have to back off, stick to simpler examples, and get them to work AND UNDERSTAND THEM!. Then you can take the working examples and begin, a step at a time, to make them more complicated and sophisticated. It's not as interesting or exciting, but you'll learn more and better. All of us have gone through this at some time or another. I'm trying to get something working on the Propeller and I'm having problems with it. I'm going to have to drop the fancy interface for now and pull out the heart of my program and work on that until it works reliably, then add back the fancy trappings a bit at a time. I think I understand the Propeller really well and I'm an experienced programmer and I'm stuck for the moment, so you go back to the basics, get a little routine to work, then add a little more, each time including some debugging statement that displays something that tells you if it's working the way you expect it. This can be something as simple as hooking an LED to an unused pin and turning it on and off at certain points, maybe adding a PAUSE so you don't miss the flash.
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-10 17:06
    bruce, i dont understand the frustration, it works perfectly just as i wanted it to, i know i could have used single commands but what fun is in that? IM NOT SHOWING MY CODE BECAUSE IT DOESNT WORK IM SHOWING IT BECAUSE IT DOES WORK. I just wanted to see what others may have to say about the system. I did the single letter and attempted the array just for fun.
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-11 19:31
    i want thinking about maybe iterating through the array but i dont know it seems like its a easier system possibly have it iterate through each variable in my array and check for a circtain letter or number, that would be easier for a single character but i dont know if anyone else has a system please share!
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-08-11 19:43
    will -

    Take a look at the SELECT ... CASE instruction.

    SELECT Operator

    CASE "F" ' Check for forward
    GOTO FWD_Rtn

    CASE "R" ' Check for reverse
    GOTO REV_Rtn

    etc

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-11 20:27
    ahh good good thanks bruce, i think it works pretty decent so ill leave it alone right now thats perfect for single letter ill keep that in my log until that comes in handy!
  • T ChapT Chap Posts: 4,223
    edited 2006-08-11 22:53
    What exactly does this code below do? I know it makes a decision and turns on an led in response, but where is it checking to read the serSTR? Is serStr a variable array that got stored previously and is in a temp RAM( a variable ?), was it obtained by a serial transfer of multiples strings? I am new to serial and trying to get an undrstanding of what takes place when a bytre/string is received. I want to apply this knowledge to the Propeller ultimately.

    Please correct this thinking if wrong:

    1. an Rx pin is always in a mode to receive, or it can be instructed to go into a mode to receive
    2. the Rx pin must be programmed to receive either 1 byte or a fixed number of bytes at a time, or any number of bytes that may include some method to terminate the process.
    3. if a string is to be received, it has to have an array specified as in VAR serSTR[noparse][[/noparse]20] BYTE , which allocates 20 bytes to the temp storage of the string, how it is stored I don't know, top to bot, bottom to top? If you receive a string, but ONLY want to look at one particular byte, you say serStr(0) if you want to deal with the first byte received in the string? serSTR(1) for the second byte stored in the array?
    4. if a string is rec'd again, it replaces the previous string, your older data is gone forever, unless you write it to a new location in ram, or eeprom for future?
    5. a byte can be represented either as a letter or number as below, or as binary $0000011? or hex $0F etc
    6. the method to receive the byte is a high>low transistion follwing some space of time called a start bit?
    7. what if a string is not the full arrays size then what? it just stored in the first X slots?


    Check_Packet:
    IF(serStr(0) = "L" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    DEBUG CR,"GREEN or RED: "
    SERIN 16,16468,Bad_Data, [noparse][[/noparse]WAIT("!"),STR serStr\9\"!"]
    IF(serStr(0) = "R" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    LEDm = 1
    LEDp = 0
    ELSEIF(serStr(0) = "G" AND serStr(1) = "R" AND serStr(2) = "E")THEN
    LEDm = 0
    LEDp = 1
    ENDIF
    ENDIF

    IF(serStr(0) = "P" AND serStr(1) = "I" AND serStr(2) = "E") THEN
    FREQOUT Piezo,2000,3000
    ENDIF
    RETURN
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-08-12 01:04
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    serStr VAR Byte(10) ' Make a 10-byte array
    LEDm PIN 15
    LEDp PIN 14
    Piezo PIN 0
    OUTPUT LEDm
    OUTPUT LEDp
    DO
    DEBUG CLS
    serStr(9) = 0 ' Put 0 in last byte
    SERIN 16, 16468,Bad_Data, [noparse][[/noparse]WAIT("!"),STR serStr\9\"!"]
    GOSUB Check_Packet
    LOOP

    Bad_Data:
    DEBUG CR, "Bad data Received! Timing out!"
    STOP

    Check_Packet:
    IF(serStr(0) = "L" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    DEBUG CR,"GREEN or RED: "
    SERIN 16,16468,Bad_Data, [noparse][[/noparse]WAIT("!"),STR serStr\9\"!"]
    IF(serStr(0) = "R" AND serStr(1) = "E" AND serStr(2) = "D") THEN
    LEDm = 1
    LEDp = 0
    ELSEIF(serStr(0) = "G" AND serStr(1) = "R" AND serStr(2) = "E")THEN
    LEDm = 0
    LEDp = 1
    ENDIF
    ENDIF

    IF(serStr(0) = "P" AND serStr(1) = "I" AND serStr(2) = "E") THEN
    FREQOUT Piezo,2000,3000
    ENDIF
    RETURN

    basically my SERIN wait for a ! then it listens for what ever up to 9 letters each one is stored in the array, either it comes to nine or another ! and it will stop so

    !LED!

    will make it continue on with the program storing LED in the array serStr

    then it goes and checks the data in the packet sent and decides what its telling the stamp to do.
Sign In or Register to comment.