Shop OBEX P1 Docs P2 Docs Learn Events
Very simple question: RS232 from a sensor and RS232 to a display unit? — Parallax Forums

Very simple question: RS232 from a sensor and RS232 to a display unit?

OrangeOrange Posts: 14
edited 2007-10-11 10:14 in BASIC Stamp
Hi guys

I want to connect a sensor to a microcontroller with RS232 serial I/O, input the data from the sensor into the microcontroller with RS232, parse the string with the microcontroller, and output the extracted value from the string to a LCD display.

ie:

The sensor has this ascii string sent with RS232 serial comm:
$HEHDT,311.6,24.3,T*24

The microcontroller get the string from a serial port, parse the string with a program, and extracted this value:
24.3

This value is sent to another serial port to a LCD·display unit,·and the LCD displays:
24.3

I notice that BASIC Stamp 2px module only has on dedicated serial I/O with one input and one output.·Can I use·the one serial port of the·Stamp 2px to·input the data from the sensor and output the·parsed data to a LCD display unit?

Or do I need two serial ports and Stamp 2px cannot perform this operation? If cannot, is there any other microcontroller I can use?

Thanks.



·

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-10-10 11:27
    Assuming both need Rx and Tx, you would have two ports. The good news is that other BasicStamp pins can be configured for additional Rs-232 ports. But you must consider voltages. Are these TTL voltages of +5 and 0 or real serial of +12/-12. The latter requires an RS-232 transciever or level shifter to protect the Stamp. Something like a MAX232 chip.

    At the begining, you would have to intialize each with their own respective code. Then, the BasicStamp would act as an intelligent intermediate buffer. The intelligence means that raw data from the sensor can be converted into meaningful text and decimal numbers rather than just looking at binary.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • OrangeOrange Posts: 14
    edited 2007-10-10 11:46
    Thanks for the reply.

    The sensor has a Tx only. The LDC unit has a Rx only. Both are +12/-12V. So I don't need to add a MAX232 chip into the Basic Stamp, right?
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-10-10 15:12
    No. It is just the opposite for +12/-12, you must have a Max232. It has 4 lines [noparse][[/noparse]2 RX and 2TX, so can be use for two separate RS-232 ports if you later need bi-directional.

    Also, it does standard inversion of the RS-232 signals [noparse][[/noparse]+12 is changed to 0 and -12 is changed to +5]. Read SERIN and SEROUT in the PBasic manual for details. I know it is a lot, but it really is helpful and necessary.

    If I were you, I would first get the LCD working ans displaying a test text, then after I understood it well, I would add the sensor. It is nearly impossible to do all this at once. Work in small steps. DEBUG will also help you to verify that you are getting good data from the sensor without having an LCD connected. When you get everything working independently, it should be quite logical on how to have it work together.

    So if you are going to use the MAX232, you might as well keep the DEBUG PORT available for programing, testing, and development. Use any pins 1 to 16 for the RS-232. I am guessing that this is serial without any additional control lines - just TX and RX.

    The SERIN and SEROUT commands set up your RS-232. But they also help you convert data from one format to another [noparse][[/noparse]like HEX to ASCII]. This can greatly simplify moving info to the LCD, which really prefers only ASCII.

    The first thing you do in software is to setup the BasicStamp for proper serial i/o; then you set up your LCD and Sensor. I don't see how the sensor can operate without a setup which woudl require RX as well as TX to receive the instruction - many are bidirectional. Many LcDs can be bidirectional and also store some data to later be downloaded.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • OrangeOrange Posts: 14
    edited 2007-10-11 10:14
    My many thanks Kramer!
Sign In or Register to comment.