LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from Serial port and save them in txt file

Solved!
Go to solution

Hello,

 

i want to read the data from Arduino serial port and save them in an Excel file. The Arduino is combined with a temperature sensor and sends data to the serial port. I followed the tutorial of link: Read Arduino Card Serial Port Data Using LabVIEW (youtube.com)

 

However when i check the txt file, i'm getting these weird data. It repeats the count from 0 on to actualize the new data. I just need sheet from 0 to the new data point directly.

luckyliu_1-1715700144919.png

 

I've tried with the suggestion to put the Write To Measurement function outside of loop. But by doing so, even no files can be generated.

 

Could anyone help me to solve the problem?

 

 

My vi can be found in attachment. 

0 Kudos
Message 1 of 5
(23,126 Views)

Could you share your Arduino code as well?  I just want to make sure what your messaging protocol actually is before giving any real advice, which would currently be based on a wild guess.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 5
(23,089 Views)

Hello,

 

thanks for your reply. Below is my Arduino sketch.

 

#include "max6675.h"

// Define the Arduino pins, the MAX6675 module is connected to
int SO_PIN = 4;  // Serail Out (SO) pin
int CS_PIN = 5;  // Chip Select (CS) pin
int SCK_PIN = 6; // Clock (SCK) pin

// Create an instance of the MAX6675 class with the specified pins
MAX6675 thermocouple(SCK_PIN, CS_PIN, SO_PIN);

void setup() {
  Serial.begin(115200);

  Serial.println("MAX6675 test");
  // wait for MAX chip to stabilize
  delay(500);
}

void loop() {

  // Read the temperature in Celsius
  Serial.print(thermocouple.readCelsius());
  Serial.println();
 
  delay(180);
}
0 Kudos
Message 3 of 5
(23,078 Views)

With the feedback node, you are appending one element and then write that array to the file. You actually wanted to do this:

cordm_0-1715716517311.png

It should have worked when you put write to measurement file after the loop, but only after stopping the loop.

 

 

Write to measurement file is really slow. You could also write to a comma-separated text file. You can open it with excel:

cordm_1-1715717493072.png

 

 

Message 4 of 5
(23,065 Views)
Solution
Accepted by luckyliu

Here's what I would do.

 

First, get away from the Write Measurement File function.  Instead, create/replace a file before the loop, close it after the loop, and you can write whatever you want inside of the loop.  In this case, you can just take the string that was just read from the Arduino straight into the Write Text File.

 

Secondly, get rid of the array and instead use a Chart.  The chart has a built-in history, so you don't even need the Feedback Node anymore.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 5 of 5
(23,009 Views)