Parse Serial Stream into 20 Byte segments

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
combib
 
Posts: 5
Joined: Tue Dec 17, 2013 9:56 am

Parse Serial Stream into 20 Byte segments

Post by combib »

I have a project where I need to display a serial stream on an LCD. I am using a 4x20 LCD, but only want to display on the first two lines. I am hoping to convert the stream into 20 byte segments. I am new to programming and need a suggestion to start the program. I am using a Mega, as eventually, I will be selecting from three data streams. Thank you :?:

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Parse Serial Stream into 20 Byte segments

Post by adafruit_support_mike »

Technically that isn't 'parsing'. Parsing involves looking at the content of the text and deciding what it means. What you're looking for is closer to 'buffering'.

The general process for moving a certain amount of text into a buffer looks like this:

Code: Select all

char *buffer[21];

for (int i=0 ; i < 20 ; i++) {
	buffer[i] = [next character from the input stream]
}
buffer[21] = 0;
What are the streams you're using as sources?

combib
 
Posts: 5
Joined: Tue Dec 17, 2013 9:56 am

Re: Parse Serial Stream into 20 Byte segments

Post by combib »

The source is the serial ports. Thanks for the buffering info, but how do I get that from a serial stream to buffer array

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Parse Serial Stream into 20 Byte segments

Post by adafruit_support_mike »

"Serial ports" doesn't tell me enough to give a specific answer.

If you're using the Arduino Serial library, you'd just use:

Code: Select all

char buffer[21];
Serial.readBytes(buffer, 20);

combib
 
Posts: 5
Joined: Tue Dec 17, 2013 9:56 am

Re: Parse Serial Stream into 20 Byte segments

Post by combib »

The complete project is monitoring three serial ports each having variable data. The data ranges from GPS data to command and control to sensor outputs. After being able to aquire the data and display it on a Lcd: the next step is to be able to automatically get the Baud rate ; then decifer the data to determine whether the data is hex; Ascii; or binary then translate it and display on the Lcd; while simultaneously sending it to a terminal. The three serial ports are monitor (RX) only.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Parse Serial Stream into 20 Byte segments

Post by adafruit_support_mike »

If you have an RX line, you're probably using the UART protocol. That's handled by the Serial library: http://arduino.cc/en/reference/serial

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”