Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hey guys,
I'm trying to parse some serial data coming from the arduino. The arduino is dumping a angle and a distance. An issue im facing is that the arduino is dumping the angle, then a new line, then the distance, then another new line. Its in such a way that the output from putty looks like this:

0 <--angle
12 <---distance
1
45
2
324
.
.
.
180
3
179
14
.
.
.
0
12 and continues until i shut off the arduino

I want to put these data into an an array where dimension 1 is the position and dimension 2 is the distance. Ive read that using a single dim array is much faster due to the poorly optimized multidim array but I'm not sure why. The angle can only go to 180 and back, the distance has a max value of 400cm. This is coming from a ping sensor that is on a 180 degree sweeping servo. I can make the arduino dump the data into one line and parse out the string into two values but I think this might be slower than making it store values in every other line coming from the serial port. From what I know, the serial data will be coming into a byte array as the buffer for the SerialPort.read(buffer,0,1) where buffer is the byte[]. So to sum things up:

1. data must be processed as fast as possible
2. end result is a multi dim or two single arrays or whatever where for each angel value there is a corresponding distance.
3. the angel data will oscillate from 0 to 180 degrees and back but the distance is variable.

After that I want to convert the vectors into x and y components and plot the points on a bitmap where each pixel represents one centimeter. much like radar-where the image gets updated with new visual points every pass.

All im asking for is a way to grab serial data so that every other line is placed into one variable and the rest in another.
Posted
Updated 3-Oct-10 13:39pm
v2

1 solution

What about this?
(this way you have an optimized single dimension array)

C#
public struct ArduinoData
{
    public int Angle;
    public int Distance;
}

public const Max = 1000;  // Whatever

public ArduinoData[] arduinoData = new ArduinoData[Max];
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900