Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Sep 4, 2015 #1
    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,

    Code (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: Sep 4, 2015
  2. jcsd
  3. Sep 4, 2015 #2

    berkeman

    User Avatar

    Staff: Mentor

    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:
     
  4. Sep 4, 2015 #3

    berkeman

    User Avatar

    Staff: Mentor

    Thread moved to the Programming forum for more views... :smile:
     
    Last edited by a moderator: Sep 4, 2015
  5. Sep 4, 2015 #4

    jedishrfu

    Staff: Mentor

  6. Sep 4, 2015 #5
    how did you know it was an Arduino?
     
  7. Sep 4, 2015 #6

    jedishrfu

    Staff: Mentor

    By the sketch model of setup() and loop() which is similar to Processing sketches which uses setup() and draw() loop methods.
     
  8. Sep 5, 2015 #7
    thank you very much, berkeman.
     
  9. Sep 5, 2015 #8

    thank you very much, jedishrfu.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: [Arduino] how to save serial monitor in the text file?
Loading...