Shop OBEX P1 Docs P2 Docs Learn Events
Problems in programming the EB-500! — Parallax Forums

Problems in programming the EB-500!

Future_EngineerFuture_Engineer Posts: 25
edited 2008-03-01 15:51 in BASIC Stamp
Hi there,
I need some help here..

I am working with the EB-500 controlled by the BS2 for a project, I wrote a program to turn ON the LED using the HyperTerminal by typing the letter "a", actually it worked, but I found out that the LED turn ON when I type any letter, also I've tried to turn OFF the LED by typing another letter but it didn't work since when I type anything it just turn it ON..

what should I do? anyone can help me or correct my mistakes?
if needed, I'll write down the program that I've wrote!

thank you very much in advanced!

PS: I've attached the program, its just to turn ON the LED, because the other program is in the school's PC.

Post Edited (Engineer_4ever) : 2/26/2008 5:45:32 PM GMT

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2008-02-26 17:32
    Yes, please "attach" your program as an "attachment" to a posting -- it's much easier to work with that way.

    You can do that with the "edit reply" button (the little pencil).
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-26 17:44
    Thank you!
    I did what you told me to do!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-02-26 18:25
    Hello,

    Your program does exactly what it is programmed to do. You’re main routine is falling into the LED routine and turning it on before it ever checks the condition to see what character was received. You will need to reorganize the code such that the HIGH 9 occurs inside the conditional block.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-26 20:29
    Hi,

    Thank you..
    I'm sorry for asking for more, but its my first time to use and write a program in BS, and I need to know this thing "for testing only" to write another program for another project am doing..
    I don't know all the commands but I'm trying my best to learn them ASAP!
    so, my question now is, how should I reorganize the code?

    Thanks again!
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-02-26 22:56
    I would recommend flow-charting the way you want the program to run. It will make it easier to write the actual code. Remember, your code drops right into the second routine and the first thing you are doing is turning on the LED. Given this that means the LED will come on when any data is received, because you’re turning it on before you test for which character was received. At minimum you will need to swap those routines, but then your program flow really should be revisited. Plan out the order of events and see what you can come up with. If it doesn’t work, post the code and we’ll identify why. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-27 13:43
    Thanks Mr. Chris, I'll try, and if I face any problem I'll drop here!
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-27 16:45
    a question, what is "ACK", and what it's used for? and what other than "szData" I can use?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-02-27 16:58
    ACK is an ASCII character used by serial devices to “ACKnowledge” receipt of data or a packet of data. NAK is its counterpart (NotAcKnowledge). These are used in most of my RF systems to let the sender know the remote has received its packet. If the sender receives a NAK or worse, nothing within a specified time it will re-transmit the packet up to a certain number of times before giving up and assuming the remote device is no longer responding.

    As to your other question, I don’t know what you are asking…szData is just a variable you’re using to get a byte from the sender. You could call it anything you want. You could even set it to an ACK or NAK value and send it back to the sender to acknowledge the transmission. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-02-27 17:18
    "szData" is Hungarian Notation for a variable named "Data", which holds a zero-terminated(z) string(s).

    Which you originally HAD specified 'szData' as an Array of Byte, but then changed it to a Word variable.

    · Here's a fix for you:

    '{$STAMP BS2}
    ' {$PBASIC 2.5}
    'szData VAR Byte(20)
    · szData VAR Byte
    · LEDPin CON 9
    · 'Wait for the eb500 radio to be ready
    · PAUSE 1000
    Main:
    · SERIN 16,84,[noparse][[/noparse]szData]····· ' MOD -- Wait here for a character to be recieved.
    · SEROUT 16,84,[noparse][[/noparse]szData]
    · GOSUB LED··················· ' MOD
    GOTO MAIN·····················' MOD

    LED:
    · IF szData = "a" THEN
    ··· HIGH LEDPin
    · ELSE
    ··· LOW LEDPin
    · ENDIF
    RETURN
    Note "SERIN 16..." uses the DB-9 programming connection to your PC.
    Note "LED:" is now a subroutine, which turns ON the LEDPin if an 'a' is recieved, or
    turns OFF the LEDPin if any other character is recieved.
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-27 17:44
    Mr. Chris, thanks, it did help me! so, I can use the ACK and NAK for the EB-500, right?

    allanlane5, thank you so much for correcting my program, I've tried it and it worked!

    another question, "sorry am asking so much" after I tested the program I thought about using more than one letter to HIGH the LED, so, I have to change "szData VAR Byte" to "szData VAR Word", right? and what about connecting the EB-500 to a smart phone?

    "I hope I can finished the project soon to share it in the Completed Project section"
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-02-27 17:48
    Well, PBasic doesn't let you compare "strings" like that. You COULD send a string like "10", CR -- and then use the 'DEC' modifier to covert the three recieved bytes (a "1", a "0", and a CHR(10) byte) into the value 10.

    or:
    MyVal VAR WORD
    ...

    SERIN 16, 84, [noparse][[/noparse]DEC MyVal]
    SEROUT 16, 84, [noparse][[/noparse]DEC MyVal, CR]
    ...

    LED:
    IF MyVal = 10 THEN
    HIGH LEDPin
    ELSE
    LOW LEDPin
    ENDIF
    RETURN
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-27 18:30
    oh, I see! I will try it!

    thanks again!

    edit:
    I've tried it, but it didnt work! smhair.gif

    what is DEC?

    also, when I tried to run the program it says "No BASIC Stamp found", why? everything is connected!
    and when I ran the previous program, it didn't work when I type anything!shocked.gif

    Post Edited (Engineer_4ever) : 2/27/2008 6:52:06 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-02-27 19:48
    1. "No basic stamp found" can happen for multiple reasons. Low power being one, having Hyperterm 'owning' the port can be another.

    2. The "DEC" is a "Modifier" for SERIN/SEROUT that says "Don't send (or recieve) the literal value, instead send (or recieve) an ASCII translated version of the value". You can read about it in the help file under SEROUT.

    So, what's an "Ascii translated version"? Say you have a number, like 10. Now, that number can be a VALUE stored in a memory location or register, the VALUE 10. That number can be converted into an ASCII string, which consists of 2 bytes, the byte "1" (CHR(49)) followed by the byte "0" (CHR(48)).

    You COULD send the VALUE 10, and to VB it would look like CHR(10) (which is a newline in ASCII). It's easier to send "1" "0" <CR> using Hyperterm, so that's why I suggested the DEC modifier, which does all this "ascii translation" for you.
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-28 20:47
    Thank you allanlane5 for what you provided for me!

    I found out that the reason why I kept having a "no basic stamp found" is the low power, and I've fixed it!

    Well, right I didn't understad everything, but there is a program in my mind I want to try it first, if it didn't work, i'll write down the program here for checking "if no one mind", and if it is not good, I'll get back on that and work on it!
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-29 16:58
    Hi again!

    I've got a question.
    I want to do increment using IF...THEN command, how to do it?
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-02-29 17:15
    Engineer -

    The simple answer is you don't. You increment a counter (X = X + 1) outside of the IF...THEN statement. Here is an example:

    ··· IF variable = value THEN Bypass

    ··· X·= X + 1

    Bypass:

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison

    Post Edited (Bruce Bates) : 2/29/2008 5:31:41 PM GMT
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-02-29 18:29
    oh, so it is outside the IF...THEN...

    so, can I do:

    IF variable1 = value1 THEN
    x = x + 1
    ENDIF

    IF variable2 = value2 THEN
    x = x + 1
    ENDIF

    IF x = 2 THEN
    HIGH .......
    ?

    anyway, thanks Bruce Bates..
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-03-01 11:05
    Hi again!

    can someone please tell me what's wrong in this program? It's not working!

    I wrote this program to be like checking·a password, but somehow it's not working!

    Thank you!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ~Swimming in·the oacen of Electronic Engineering~
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-01 13:57
    Future_Engineer -

    In what way is the program not working? You'll have to provide a better description of what's wrong, if you'd like help in troubleshooting the problem.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-03-01 14:29
    Hi..

    The error message I got is telling me this:
    "Lable is missing ':' "
    and the "Y" in the program is shaded. I don't know why!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ~Swimming in·the oacen of Electronic Engineering~
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-01 14:35
    · IF szData1 = "h" THEN
    ··· Y = Y + 1

    It's because you haven't declared Y as a variable.
  • Future_EngineerFuture_Engineer Posts: 25
    edited 2008-03-01 15:04
    Oh, thank you Mr. PJ Allen. I've correct my mistake!

    But, when I run it, and tried to test it in HyperTerminal, it didn't work!
    I wanted to turn ON the LED after I type the word "hello" and if I made any mistake in typing the word, it should give me a chance for 3 times only to re-enter the word!

    Anyone can help?

    Here is the corrected·program!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ~Swimming in·the oacen of Electronic Engineering~
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-03-01 15:41
    Future Engineer?

    The most obvious problem I saw was that you have:

    GOSUB repeat

    in your program, and the is no RETURN command anywhere in the program. If you use GOSUB, there MUST be a RETURN statement. They are always used in pairs.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Genius is one percent inspiration and ninety-nine percent perspiration."

    Thomas Alva Edison
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-03-01 15:51
    Give this program a shot.· It's not everything, but it should help you to manage.

    [noparse][[/noparse] That should be ocean, not "oacen" ]
Sign In or Register to comment.