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

Click For Summary
The discussion revolves around a user's request for assistance in saving data from a serial monitor to a text file using Arduino code. The user, Nate Duong, shares a code snippet that generates random numbers and prints them to the serial monitor. Participants clarify that Arduino does not support file systems for direct file writing, suggesting that data can only be sent via serial communication. They reference C programming resources for file writing concepts and highlight the similarities between Arduino and Processing sketches. The conversation emphasizes the limitations of Arduino in terms of file handling while providing guidance on potential workarounds.
Nate Duong
Messages
125
Reaction score
4
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
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:
 
Thread moved to the Programming forum for more views... :smile:
 
Last edited by a moderator:
how did you know it was an Arduino?
 
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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K