[Arduino] how to save serial monitor in the text file?

In summary, Nate is trying to save the serial monitor data into a text file, but he doesn't know how. Jedishrfu has provided him with code tags that will help make his post more readable.
  • #1
Nate Duong
126
3
Dear everyone,

I trying to save serial monitor in the text file, but I still do not know how, could you please help on this problem?

Here is the codes with random numbers are set up, and I would like you save all data into the text file,

Thank you very much,
Nate Duong,

C:
long Channel1a;long Channel1b;
long Channel2a;long Channel2b;
long Channel3a;long Channel3b;

long Channel4a;long Channel4b;

int count1 = 0;
int count2 = 0;
int n1 = 1000        +1;  //  +1 is missing count
int n2 = 2         +1;

void setup(){
  Serial.begin(9600);
  randomSeed(analogRead(0));
}

void loop(){while(count2<=n2){
  //Serial.print("nate1\n");
   while(count1<=n1){
     if ((count1==2)|(count1==1)){
               Serial.print("     Q1     I1     Q2     I2     Q3     I3     Q4     I4 \n");  // print out the channels
                   }
     Channel1a = random(300); Channel1b = random(300);
     Channel2a = random(300); Channel2b = random(300);
     Channel3a = random(300); Channel3b = random(300);
     Channel4a = random(300); Channel4b = random(300);

     Serial.print("    "); Serial.print(Channel1a); Serial.print("    ");
     Serial.print(Channel1b); Serial.print("    ");
     Serial.print(Channel2a); Serial.print("    ");
     Serial.print(Channel2b); Serial.print("    ");
     Serial.print(Channel3a); Serial.print("    ");
     Serial.print(Channel3b); Serial.print("    ");
     Serial.print(Channel4a); Serial.print("    ");
     Serial.print(Channel4b); Serial.print("    \n");
     count1 = count1 +1;
     delay(500);
                      }
                 }
     count2 = count2  +1;
     Serial.print(" \n");}
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Hi Nate, I added code tags to your post to make it more readable. Click Reply on your post to see what the code tags look like.

On your question, are you familiar with how to write to files in C? It's in chapter 7 of the Kernighan & Ritche book on C (2nd Edition). :smile:
 
  • #3
Thread moved to the Programming forum for more views... :smile:
 
Last edited by a moderator:
  • #5
how did you know it was an Arduino?
 
  • #6
By the sketch model of setup() and loop() which is similar to Processing sketches which uses setup() and draw() loop methods.
 
  • #7
Hi Nate, I added code tags to your post to make it more readable. Click Reply on your post to see what the code tags look like.

On your question, are you familiar with how to write to files in C? It's in chapter 7 of the Kernighan & Ritche book on C (2nd Edition). :smile:
thank you very much, berkeman.
 
  • #8
post: 5219108 said:
By the sketch model of setup() and loop() which is similar to Processing sketches which uses setup() and draw() loop methods.
thank you very much, jedishrfu.
 

What is the purpose of saving serial monitor data in a text file?

The purpose of saving serial monitor data in a text file is to store and analyze the data over time. This can be useful for troubleshooting, data analysis, and creating visualizations.

How can I save serial monitor data in a text file using Arduino?

To save serial monitor data in a text file using Arduino, you can use the Serial.println() function to print the data to the serial monitor, and then use a File object to create, open, and write the data to a text file on an SD card or computer.

What format is the data saved in when using Arduino to save serial monitor data in a text file?

The data is typically saved as plain text in a comma-separated values (CSV) format, with each line representing a new set of data.

Can I save serial monitor data in a text file while the Arduino is still running?

Yes, you can save serial monitor data in a text file while the Arduino is still running. However, it is important to properly close the file after writing to it to avoid corruption or loss of data.

What are the potential drawbacks of saving serial monitor data in a text file?

One potential drawback is the limited storage capacity of an SD card or computer, which may limit the amount of data you can save. Additionally, if the code or hardware is not properly configured, the data may not be saved accurately or may be lost altogether.

Similar threads

  • Programming and Computer Science
Replies
9
Views
662
  • Programming and Computer Science
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
1K
Replies
1
Views
3K
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top