Shop OBEX P1 Docs P2 Docs Learn Events
Need to read ASCII data, then throw relay - complete noobie! — Parallax Forums

Need to read ASCII data, then throw relay - complete noobie!

drew4justicedrew4justice Posts: 2
edited 2011-10-06 16:16 in General Discussion
Hello all!

I'm a complete noobie. I don't even own a board or programmer, yet. But, I thought I'd write this in hopes to get a feeler out there for hardware recommendation and a simple structure on how to perform a task.

I have a constant, repeating ASCII serial stream representing values that I need to parse. Based on one value, I'd like to trip a relay.

For example, the output would look like this: A=23 BX=19 GRT=20.

Can anyone recommend hardware I should acquire? I'd like to trip a relay, say if GRT=22.

I understand that I'd need to set a pin high and then sense that pin to trip the relay. That part isn't an issue, but I'm not sure how to parse the ASCII stream?

I have had a programming background, but it's been twenty-some years! (Assembly code on Commodore 64!!) :)

Any response is appreciated.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-06 07:39
    A lot depends on details you haven't mentioned. If the Baud of the serial stream is low (< 9600) then pretty much any of the Basic Stamps or the Propeller would work fine. The BS1 would only work if the Baud is really low (2400 or less). If the Baud is 9600, you'd probably need a BS2px or Propeller and, faster than 9600, you'd need a Propeller.

    The Stamp's SERIN statement has a feature where it will wait for a specific string (like "GRT=") before proceeding. This string can be followed by an ASCII decimal number which is converted to a numeric value which you can then test further using other statements. Download and look at the "BASIC Stamp Syntax and Reference Manual" and the "What's a Microcontroller?" tutorial for descriptions and examples.

    The Nuts and Volts Column #6 shows how to use a transistor with a Stamp to control a relay. The same general idea applies to a Propeller.

    If your Baud is much above 9600, you'll have to use a Propeller. This is normally programmed in Spin. There are library routines (called "objects") available in the Propeller Object Exchange and several of them will do buffered high speed serial I/O. One is a library of routines that provides Stamp-like functionality including a "wait for a string" routine and a "convert an ASCII number to a numeric value" routine.
  • drew4justicedrew4justice Posts: 2
    edited 2011-10-06 07:45
    Perfect! The rate is 2400 baud, so it shouldn't be a problem.

    I've been shoved in the right direction... Thanks!
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-06 07:53
    If you want ready-to-go hardware and your Baud is less than 9600, you might look at EFX-TEK's Prop-2. This is essentially a BS2 with a high current output driver suitable for driving a relay directly.

    Note: Even though the BS2 is supposed to work fine at 9600 Baud and will transmit as high as 19200 Baud, it's kind of marginal at 9600 Baud for complex functions like a SERIN WAIT("GRT=") followed by a DEC prefix (for converting from ASCII to numeric). It makes a big difference to have 1.5 or 2 stop bits on your serial data stream characters. That gives a little more time for the Stamp to do its processing. The BS2px is much faster and will work up to 19200 Baud.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-06 09:54
    Mike Green wrote: »
    The Stamp's SERIN statement has a feature where it will wait for a specific string (like "GRT=") before proceeding.

    Correct me if I'm mistaken, but I believe that feature is NOT available for the BS1, regardless of the baud rate used.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-10-06 16:16
    The syntax for the corresponding function on the BS1 is different, but it can indeed wait for a "qualifier" just like the BS2. Check the section of the BASIC Stamp Syntax and Reference Manual on the SERIN statement. Given the Baud involved, the EFX-TEK Prop-1 could also be used to directly drive a relay when a given value comes in.
Sign In or Register to comment.