How to write data to a text file on Arduino

前端 未结 2 417
别那么骄傲
别那么骄傲 2021-01-13 02:15

I have some position data continually coming in and I am currently printing it to the serial.

Say I have the string \"5\" and want to print that to a text file, \"my

2条回答
  •  别那么骄傲
    2021-01-13 02:44

    U have to Use serial-lib for this

    Serial.begin(9600);
    

    Write your sensor values to the serial interface using

    Serial.println(value);
    

    in your loop method

    on the processing side use a PrintWriter to write the data read from the serial port to a file

    import processing.serial.*;
    Serial mySerial;
    PrintWriter output;
    void setup() {
       mySerial = new Serial( this, Serial.list()[0], 9600 );
       output = createWriter( "data.txt" );
    }
    void draw() {
        if (mySerial.available() > 0 ) {
             String value = mySerial.readString();
             if ( value != null ) {
                  output.println( value );
             }
        }
    }
    
    void keyPressed() {
        output.flush();  // Writes the remaining data to the file
        output.close();  // Finishes the file
        exit();  // Stops the program
    }
    

提交回复
热议问题