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

  • Thread starter Nate Duong
  • Start date
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,

Best regards,

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:

berkeman

Mentor
55,117
5,343
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:
 

berkeman

Mentor
55,117
5,343
Thread moved to the Programming forum for more views... :smile:
 
Last edited by a moderator:
260
40
how did you know it was an Arduino?
 
10,602
4,147
By the sketch model of setup() and loop() which is similar to Processing sketches which uses setup() and draw() loop methods.
 
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.
 
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.
 

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top