title: Saving Arduino sensor data to text file
body: <p>I've been working to save data from an accelerometer sensor to a text file. But after searching the web for several hours, the methods I've found haven't worked. Here is the program I have now.</p>
  
  <pre><code>// Accelerometer sensor program
  
  const int ar1 = A5; 
  const int ar2 = A4;
  const int ar3 = A3;
  
  int x = 0;        
  int ov1 = 0;    
  int y = 0;      
  int ov2= 0;      
  int z = 0;       
  int ov3= 0;      
  
  void setup() {
    // initialize the communications
    Serial.begin(9600);
  
  }
  
  void loop() {
    analogReference(EXTERNAL);    //connect 3.3v to AREF
  
    // X axis
    // Read the analog
    x = analogRead(ar1);            
    // Range of analog out
    ov1 = map(x, 0, 1023, 0, 255);  
    delay(2);                     
  
    // Y axis
    y = analogRead(ar2);            
    ov2 = map(y, 0, 1023, 0, 255); 
  
   // Z axis 
    delay(2);                 
    z = analogRead(ar3);            
    ov3 = map(z, 0, 1023, 0, 255);  
  
  // Should print to the monitor
  // Output for X axis
    Serial.print("Xsensor1 = " );                       
    Serial.print(x);      
    Serial.print("\t output1 = ");      
    Serial.println(ov1);   
  
  // Output for Y axis
    Serial.print("Ysensor2 = " );                       
    Serial.print(y);      
    Serial.print("\t output2 = ");      
    Serial.println(ov2);   
  
  // Output for Z axis
    Serial.print("Zsensor3 = " );                       
    Serial.print(z);      
    Serial.print("\t output3 = ");      
    Serial.println(ov3);   
  
  // Should repeat every second
    delay(1000); 
  </code></pre>
  
  <p>What I've found does seem to do what I want, the issue is that Arduino doesn't want to run it, saying that 'import' was not declared in the scope. I've tried installing some libraries, but I couldn't find the exact library that import is part of, or PrintWriter for that matter. Here is the code causing issues:</p>
  
  <pre><code>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() &gt; 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
  }
  </code></pre>
  
  <p>Thanks in advance.</p>