Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Serial (ASCII) in, to variable voltage (0-5v) out — Parallax Forums

BS2 Serial (ASCII) in, to variable voltage (0-5v) out

TimDTimD Posts: 2
edited 2005-05-01 01:43 in BASIC Stamp
Hello. First post!
After a bit of searching, I am still wondering if I can perform this exact scenario:

I have a device which emits a constant ASCII serial (rs-232) stream. It is an evironmental sampling unit (measuring total volatile organic compounds).

I have a Basic Stamp 2 microcontroller.

I need a 0-5volt output to interface with a separate datalogger.

From what I read, I believe it is possible to read the input stream, parse out the value I want, and scale an output on the BS2 to give me a range for my external logger to read.

I am not seeing any example code to evaluate a serial stream and was wondering if someone has already done something similar, and could help me 'jumpstart' this little project.

I only need to read 1 serial device, and only need to control 1 output. This program must run 24x7.

I heard that the BS2 may not be able to read serial data, and output at the same time, this is OK, I just need to 'sample' and output once each minute.

Any help would be appreciated greatly. Thank you for reading this!

Tim D'Apice

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-30 14:12
    What does the serial stream from your other device look like? Does it have any kind of marker that you can look for? If yes, you can use the WAIT parameter of SERIN to simplify things.

    If the BS2 doesn't work for you, the SX with our SX/B compiler is an option. In the projects section you'll see a MIDI project I designed that receives, buffers, and analyzes a MIDI stream on the fly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • TimDTimD Posts: 2
    edited 2005-04-30 17:15
    So far, I know that it is 9600 baud, 8-bits no parity
    I am asking the vendor for bit-specifics. Hopefully, there is some type of sentinel for me to 'grab' what I need out of each packet.
    Does it matter that the unit is sending continuously? Does the BS2 just wait for a full packet on SERIN command?

    I'm still new to the stamp, I'm spending the better part of today studying more. I have the What's a microcontroller kit and have done several projects in the book. I would like a serial project that I can try. I'll look on the website for your MIDI example.

    Thank you for your prompt response.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-04-30 17:35
    The BS2 cannot listen 'continuously' to an RS-232 signal. It is a single-tasking module, which means when it is changing the output voltage (using a D to A converter, I assume) it cannot be reading the RS232 signal.

    This may not be a problem -- you probably could 'miss' a few data packets and still get updates sufficiently often.

    Now, the SX28 can recieve RS232 data 'in the background' using a "virtual-peripheral" -- basically an interrupt driven RS232 sampling piece of code.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-04-30 20:55
    If there is a distinct marker in the stream, you can use it to grab a bit of data from the incoming stream.· If, for example, your data looked like this:

    · X=0023, Y=0100, ALT=00000

    and you wanted to capture the·X value, you could use a statement like this:

    · SERIN SPin, Baud, [noparse][[/noparse]WAIT("X="), DEC xVal]

    The WAIT modifier would monitor the stream until it saw "X="·then it would use the DEC modifier to convert decimal characters to the value.· In the example above, the X value input would be terminated by the trailing comma.· See SERIN in the help file for details on WAIT and using modifiers like DEC, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-04-30 21:57
    Thanks, Jon, that's very true. However, if the 'sender' immediately sent another packet while the BS2 was dealing with the 'xVal' value, the BS2 would miss that packet.

    Again, this may not be a problem, but the OP should be aware it exists.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-05-01 01:43
    We recently attached a Stamp data logger to an IMR flue/exhaust gas analyzer www.imrusa.com/english/2800-auto.htm, and that may be similar to what you are trying to do. The analyzer kicks out a set of readings at 2400 baud on several different gases at a programmable interval, like once every five seconds or once every 15 seconds. There is a preamble and each component gas is tagged with a label like,
    **********
    CO 121.3 ppm
    O2 .....
    and so on.
    The Stamp serin command has a "WAIT" modifier that allows it to key in and capture each value to its own variable, as others have pointed out.

    In our system, those values are logged into a file with a time stamp.

    If you want to convert readings to analog values in order to transmit them to another data logger (huh?!), then one option is the Stamp PWM command, in conjuntion with an RC filter to hold the value while the Stamp is busy getting the serial readings. A better option for the analog output would be a DAC (digital to analog coverter chip).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.