Three serial data channels displayed on LabVIEW plots, LabVIEW charts, serial sensor data, three-channel plotting

Display Serial Data on Real Time Graph in Labview

2.5K Views
40
700
60
25
60
PCBWay

Hello friends! In this tutorial, we will display serial data on live plots in LabVIEW. In the previous lesson, we received comma-separated records from a COM port and converted them into a numeric array. We will now take the three values in that array and display each channel as a changing trace.

If you have not built the serial reader yet, start with getting continuous data from a COM port in LabVIEW. The plotting stage assumes that a complete record has been received and validated. A graph cannot correct an incomplete message or determine which sensor a badly parsed number belongs to.

We will preserve the original three-channel example and screenshots, then explain the differences between charts and graphs, how to label the time axis honestly, and how to keep the display responsive. Here, real-time means a display that updates as measurements arrive; a desktop serial VI does not provide a deterministic real-time execution guarantee.

Three serial data channels displayed on LabVIEW plots, LabVIEW charts, serial sensor data, three-channel plotting
Figure: Three serial data channels displayed on LabVIEW plots.

Start with a Valid Three-Value Record

The original reader displays the incoming text in Response and its separated numeric values in Data 1D. For example, the complete line 120,221,312 produces a numeric array containing three elements. Array index 0 is 120, index 1 is 221 and index 2 is 312.

Serial reader supplying a numeric array for plotting, LabVIEW charts, serial sensor data, three-channel plotting
Figure: Serial reader supplying a numeric array for plotting.

Keep that raw-text display while adding the plots. It is a useful debugging reference: you can compare what arrived with what was parsed and finally with what was plotted. Hiding the raw input too early makes a graphing problem and a communication problem look unnecessarily similar.

Require exactly three valid fields before updating any of the three traces. If a line contains only two values, do not update the first two charts while leaving the third with an old measurement. Treat the channels as one record so that their displayed samples remain aligned.

Choose a Chart or Graph Deliberately

LabVIEW has several plotting indicators with different input and history behavior. The important distinction for this tutorial is whether the indicator accumulates new samples or displays a data set supplied by your program. NI describes these controls in its graph and chart reference.

IndicatorSuitable useWhat the program supplies
Waveform ChartIncremental updates with retained historyNew sample values or supported blocks of samples
Waveform GraphA complete uniformly spaced data setAn array or waveform containing the desired trace
XY GraphValues with explicit or irregular x coordinatesMatching x and y data

For a first implementation receiving one record at a time, three separate Waveform Charts are straightforward. Each accepted record contributes one scalar to each chart. A Waveform Graph also works, but you must retain the history yourself and supply the array you want it to show.

Do not assume that every object informally called a graph in a screenshot is configured identically. Inspect the actual indicator type and its terminal. A wire that works with a chart may have a different meaning or be invalid when connected to a graph.

Extract the Three Channels on the Block Diagram

Place an Index Array function after the validated numeric array. Expand it or use explicit index inputs to obtain elements 0, 1 and 2. Connect each scalar output to its corresponding chart. Keep all three updates inside the same valid-record case so that a rejected line adds no measurement points.

Separating three array values for LabVIEW plots, LabVIEW charts, serial sensor data, three-channel plotting
Figure: Separating three array values for LabVIEW plots.

The original diagram illustrates the central idea: separate the array elements and send them to individual plots. The refreshed design adds validation before that split. NI's arrays and clusters guide is useful if you are unfamiliar with array indexing or the difference between an array and a cluster.

  1. Receive a complete serial record.
  2. Validate the expected field count and numeric syntax.
  3. Convert the accepted fields to a consistent numeric type.
  4. Extract the three channel values by their documented indices.
  5. Update Response, Data 1D and the plots from that same record.
  6. Record the sample sequence or timestamp if the protocol provides one.

Give the wires or nearby labels meaningful channel names. A raw array index is easy to confuse when the sender's format changes. For example, document whether index 0 means X acceleration, temperature or another quantity rather than leaving the meaning implicit.

Arrange the Front Panel

Place the three charts near the numeric values and retain the port selector and acquisition controls. Use descriptive plot titles and units. The original front-panel arrangement is shown below.

LabVIEW front panel with three serial data plots, LabVIEW charts, serial sensor data, three-channel plotting
Figure: LabVIEW front panel with three serial data plots.

If all channels represent the same physical quantity and comparable ranges, matching their vertical scales makes comparison easier. If they represent different quantities, separate axes or separate charts usually communicate the values more clearly than forcing everything onto a shared scale.

The original experiment used an accelerometer board described as IMUv2. That name alone does not establish the exact sensing chip, selected range or conversion factor. Unless you have those details, label the plotted output as raw counts rather than claiming that it represents acceleration in g or metres per second squared.

Display itemRecommended information
Chart titleChannel name, such as X acceleration
Y axisRaw counts or the correctly calculated unit
X axisSample index or a justified time coordinate
StatusRunning, paused, stale or disconnected
Quality countersAccepted, rejected and missing records where detectable
Last updateTime of the most recent valid measurement

Run the Three-Channel Display

  1. Select the actual COM port and matching serial parameters.
  2. Run the VI and start acquisition.
  3. Send a known record and compare its text, numeric array and plotted values.
  4. Change one input channel at a time and confirm that only the intended trace changes.
  5. Observe the status and rejected-record counter during operation.
  6. Stop through the VI's normal control so its VISA cleanup runs.

Running LabVIEW serial acquisition with numeric values and live plots, LabVIEW charts, serial sensor data, three-channel plotting
Figure: Running LabVIEW serial acquisition with numeric values and live plots.

The original result image shows the three output forms together: raw Response text, separated Data 1D values and live plots. That arrangement remains useful because each stage answers a different question. The text shows the communication payload; the array shows its interpretation; the plots show how the interpreted values change.

What Does the Horizontal Axis Actually Mean?

A chart receiving one scalar per accepted record naturally advances by one sample at each update. Labelling that axis “seconds” does not establish a sampling interval. First decide whether the source produces regularly spaced samples, whether any samples can be lost, and whether the record contains a timestamp.

If a device samples at exactly 20 Hz and delivers every sample in order, the nominal interval is dt = 1 / 20 = 0.05 seconds. Sample n can then be assigned the nominal time t(n) = t0 + n × 0.05. Configure the chart scale or waveform timing consistently with that assumption.

Do not derive that interval solely from a Wait function in the receiving loop. Serial reads, operating-system scheduling and display work also take time. More importantly, the device may already have sampled the signal before the bytes reached the computer.

Acquisition Time and Arrival Time Are Different

A device timestamp describes when the measurement was taken, subject to that device's clock definition. A computer timestamp taken after VISA Read describes when your program received or processed the record. USB buffering can make several evenly spaced measurements arrive close together.

If the source sends irregularly timed measurements, retain explicit timestamps and use an XY Graph with matching time and value arrays. NI discusses irregular timestamps in its guidance on nonuniform graph data. Keep the timing source in the project documentation so another reader can interpret the trace correctly.

If no trustworthy time information exists, use sample index and say so. That is more informative than displaying a time scale that silently compresses missing records or ignores communication delays.

Set a Useful History Length

A chart's history is a display buffer, not an unlimited data archive. Choose a length from the time span you need to observe. For a 60-second window at 20 samples per second, approximately 60 × 20 = 1200 scalar points per channel are required. The interval from the first retained point to the last is one sample period shorter than the corresponding count divided by the rate.

NI's chart history guidance explains how retained history depends on the input representation. For this tutorial's scalar updates, think in points per channel. If you later send waveforms or blocks, inspect the history behavior again rather than reusing an assumption from the scalar case.

Reset history deliberately when beginning a new experiment if old and new runs should not appear connected. A visible line joining the last sample of yesterday's run to the first sample of today's run has no physical meaning. Alternatively, preserve runs separately with their own timestamps and labels.

Put Several Channels on One Chart

Three separate charts are easy to learn, but a shared chart can make timing relationships more visible. For one new scalar value per channel, bundle the three scalars into a cluster and connect that supported representation to a multi-plot Waveform Chart. Give each plot a distinct name and expand the legend so the names are visible.

Do not simply replace the cluster with a one-dimensional numeric array and assume its elements still mean separate channels. Depending on the indicator and input type, an array can represent multiple samples of one channel. Check the chart's expected input representation in LabVIEW Context Help. The LabVIEW user manual's graph and chart chapter provides the underlying multi-plot conventions.

Test the mapping with deliberately different constants, such as 10, 100 and 1000. If three separate traces do not appear as expected, resolve the data structure before reconnecting the real sensor. A simple artificial input is easier to interpret than three noisy measurements.

Convert Raw Counts into Engineering Units

Apply a conversion only when you know the sensor's output format, zero offset and scale. A common linear form is physical value = (raw count − zero offset) / sensitivity. The units of sensitivity determine the resulting unit.

For an illustrative sensor whose documented sensitivity is 16384 counts per g, an offset-corrected value of 8192 counts represents 0.5 g. Multiplying by the standard gravitational acceleration 9.80665 m/s² gives approximately 4.90 m/s². These numbers demonstrate the calculation; they are not a specification for the unidentified IMUv2 board in the original screenshots.

Keep calibration constants together and record their origin. Changing the sensor's measurement range may change its sensitivity. A plot that remains visually smooth after a range change can still be numerically wrong if the old conversion factor is retained.

Handle Missing Data Without Inventing Measurements

If a record fails validation, increment a rejected-record counter and preserve the reason. Do not replace that record with three zeros. A zero can be a valid measurement, and inserting one creates an artificial event in the trace.

Also avoid repeatedly plotting the last valid value on every receiver-loop iteration. That creates extra apparent samples even though the sensor produced no new information. Update the measurement history only when a new record is accepted.

For a plot with an explicit time coordinate, decide whether to show a visible gap, a separately marked invalid point or another clearly documented missing-data representation. Connecting a line across a long outage can imply a measured transition that never occurred. Keep validity information in the saved data even if the display uses a simplified visual treatment.

Keep Acquisition Responsive

At modest data rates, one loop may be sufficient. At higher rates, separate acquisition from display work. The acquisition loop can read, frame and validate records, while a second loop receives batches through a queue and updates the plots at a manageable rate.

For example, a device may generate 100 samples per second while the display refreshes ten times per second. Each display update can add the ten newly received samples rather than discarding nine of them. A lower screen refresh rate does not require a lower acquisition rate.

Bound the queue and monitor its occupancy. If display or file writing cannot keep up indefinitely, an unbounded queue merely delays the eventual memory problem. Choose an explicit policy: stop acquisition, reduce the source rate or drop data with a recorded loss indication. Do not silently discard old records while presenting the result as complete.

The serial bandwidth must also support the source rate. A 30-byte record using 8N1 requires about 300 transmitted bits. At 9600 baud, its ideal transmission time is 31.25 ms, giving only about 32 records per second before overhead. A 100-record-per-second source needs a different rate or record format.

Check the Plot Before Using It for Analysis

Test inputExpected observationWhat it checks
Three different constantsThree distinct steady levelsChannel mapping
A ramp on one channelOnly the corresponding trace risesArray indexing
A shorter numeric valueCorrect numeric position without text remnantsParsing and display conversion
A malformed recordRejected count increases without invented pointsValidation
A pause in transmissionStale status or visible time gapMissing-data behavior
A new acquisition runHistory follows the selected reset policyRun separation

Use auto-scaling while discovering an unfamiliar signal, but consider fixed limits when comparing runs. If the vertical scale changes automatically, a small disturbance may appear as large as a major event from a previous run. Keep the axis values visible and include units in saved screenshots.

Download the Original VI

Download the Labview vi

The archive is the original demonstration VI, retained for comparison with the screenshots. This written update does not replace its internal block diagram with a newly built version. Review its parsing, indicator type and timing assumptions before adapting it to a new instrument, and check whether your LabVIEW installation can open the file.

Review of the Three-Channel Method

The basic transformation remains the same as in the original lesson: receive a record, turn it into a numeric array, extract its channels and plot their changing values. The additional discipline is to preserve the record boundaries and the meaning of the horizontal axis.

For a reusable project, keep acquisition, conversion and display behavior identifiable on the block diagram. That makes it possible to change the sensor conversion without rewriting the serial reader, or to replace three charts with an XY display without changing the protocol parser.

Frequently Asked Questions

Why does my graph show only the newest data?

A graph displays the data set supplied to it. If you want earlier values included, maintain and supply that history, or use a chart designed to accumulate incremental input. Check the indicator type before changing the serial loop.

Can I plot more than three channels?

Yes. Extend the protocol validation, channel mapping and plot structure together. Give each channel a name and unit, and check that the serial bandwidth supports the larger record.

Why are all the plots changing together?

Check that the three outputs use different array indices and that each chart is wired to the intended output. Test with different constants before investigating the sensor hardware.

Should I smooth the data before plotting?

Only when the application benefits from a defined filter. Keep the raw data available and document the filter's window and delay. Smoothing can hide short events and does not repair corrupted serial records.

Does a chart save the complete experiment?

No. Its retained history is limited and can be cleared. Use a separate logging path with timestamps, units and validity information when you need an experiment record that survives closing the VI.


Comments

17

Join the conversation

Reply1

Hi friend, excellent tutorial, my question is how do you send serial, for instance in Arduino is something like: " Serial.println(measure_value);" then if I have three sensors, the thing will be something like this: " Serial.println(measure_value); Serial.println(measure_value1); Serial.println(measure_value2);"

Regards. Thanks in advance.

1 reply
Reply3

Sir, can u please upload this VI file to be compatible with labview version 2013? I tried to build the VI file as shown in the image, however, I was unable to retrieve data.
The only difference is that the data I am receiving serially is from only 1 sensor. But that shouldn't disturb the output?
Please guide? And upload the .Vi file compatible with LabVIEW version 2013, so that i can rectify my mistake.

Reply4

Hi,

You close and open Serial communication in every iteration, no matter if you write or read. Each of these operations takes time.

Why don't you start the serial com. at the beginning and close it to the end. Only once.

In attachment I've prepared a draft of how it should be easier for you to do it.

Paul

1 reply
1 reply
Reply6

Hi,

Thank you for this vi. Its half way through to what I need to do. I also need to be able to write data to the serial port. can you help me incorporate that in this code for yours.

Thank You

1 reply
1 reply
1 reply
1 reply
Reply6.1.1.1.1
Replying to syedzainnasir

Hi,

I have project that I need to control my mini-spectrometer (c12880ma) with arduino and get data (in waveform) with Labview interface. However, up to now, I couldn`t achieve to get data in waveform. I tried to modified some examples in the Labview, but does not work. Can you help me on this ?

Reply7

Hello Syed. I have a similar teensy program that loops in every 1000micoroseconds to send data to the serial port and i have used your code and i am unable to get a smooth sinusoidal wave ,while my input to the analog pin is sine wave of 1Hz frequency.
Can you post the teensy code or tell me what is your sampling rate for ADC in teensy.
Thanks .

Reply8

Hello everyone I want to connect a temperature controller Delta series having RS 485 communication, I am also having RS485 to USB converter. I just want to monitor and record the process value temperature from the controller in PC through LabVIEW . As I am beginner I dnt know how can I do it..any kind of help will be deeply appreciated.

Reply9

Hi Mr Nasir,

I am using c12880ma mini-spectrometer to get data in graph form by using Labview. I tried some examples in the Labview but still couldn`t solve my problem. Can we discuss my case on skype when you are not busy ?

Reply10

Hi , I am a new guy for Labview. I think VISA is only for NI tool ? I try to run your vi with my custom mcu board but no any action .