Help with a compiling error

My latest version of code will not compile for an UNO.

When I comment out the line below it works, but that’s so weird since that part of the code is exactly the same as the code I had in my previous version.

myFile.println(dataString);

What was added:

  • Output LED on pin 13
  • Input Switch (recordDATA) on pin 12 (which hopefully only lets the arduino save the string to the SD card if the switch is on

Newest code:

#include <SPI.h>
#include <SD.h>

File myFile;

int ledPin = 13;
int recordDATA = 12;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  Serial.println("A0, A1, A2, A3, A4, A5, ms time");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.


  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);


  pinMode(recordDATA, INPUT);
}

void loop() {



  // make a string for assembling the data to log:
  String dataString = "";


  // read 6 sensors and append to the string:
  for (int analogPin = 0; analogPin < 6; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);

    dataString += ",";

  }

  // append time stamp
  dataString += String(millis());
  Serial.println(dataString);

  myFile = SD.open("test.csv", FILE_WRITE);


  if (digitalRead(recordDATA) == HIGH) {
    digitalWrite(ledPin, HIGH);

    // if the file opened okay, write to it:
    if (myFile) {
      myFile.println(dataString);
      myFile.close();
    } 
    else {
      // if the file didn't open, print an error:
      Serial.println("error opening test.txt");
    }

  }

  else {
    digitalWrite(ledPin, LOW);
  }

  Serial.println(dataString);

  delay(3000);
}

Error message:

Arduino: 1.8.8 (Windows Store 1.8.19.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In member function 'availableForWrite':

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:203:1: internal compiler error: Segmentation fault

 }

 ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.19.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.19.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

previous code version that worked perfectly:

/*
  SD card read/write

 This example shows how to read and write data to and from an SD card file
 The circuit:
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

 created   Nov 2010
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>

File myFile;



void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  Serial.println("A0, A1, A2, A3, A4, A5, ms time");
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  



 
}

void loop() {



// make a string for assembling the data to log:
  String dataString = "";


  // read 6 sensors and append to the string:
  for (int analogPin = 0; analogPin < 6; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
   
    dataString += ",";
    
  }
  
// append time stamp
  dataString += String(millis());
  Serial.println(dataString);

  myFile = SD.open("test.csv", FILE_WRITE);
  


  // if the file opened okay, write to it:
  if (myFile) {
    myFile.println(dataString);
    myFile.close();
   } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

Serial.println(dataString);

  delay(3000);
}

Do a search of this site for "arduino ide segmentation fault" for information.

Which version of IDE? it compiles ok in 1.8.5

Sketch uses 12650 bytes (39%) of program storage space. Maximum is 32256 bytes.
Global variables use 1020 bytes (49%) of dynamic memory, leaving 1028 bytes for local variables. Maximum is 2048 bytes.

I am using IDE 1.8.8

Turns out I had to follow Pert's response here to roll back to an older version of the AVR Boards: https://forum.arduino.cc/index.php?topic=572746.0

It's compiling properly.

Thank you both for taking your time to help!