SD card problem with Wio-terminal

The SD card on Wio-terminal does not function properly when there are two Grove modules working and LCD also working, but it works as expected if only SD card-related functions are running.

For example the below code works well, but my custom code with i2c sensor, LCD library and UART Grove module does not work properly for SD card. Is there any compatibility issue?

#include"seeed_line_chart.h" //include the library

#include <SPI.h>
#include <Seeed_FS.h>
#include "SD/Seeed_SD.h"

File myFile;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial) {
  }
   Serial.print("Initializing SD card...");
   if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) {
    
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  //myFile = SD.open("test.txt", FILE_WRITE);

}

void loop() {
  // put your main code here, to run repeatedly:

   myFile = SD.open("test2.txt", FILE_WRITE);

   if(myFile)
   {    
    for (int i=0; i<256; i++)
    {
      Serial.println("Open");
      myFile.println("Write num");
      myFile.println(i);
      delay(10);
    }    
   }
   else{
    Serial.println("Could not open");
    }
}

Thank you in advance for your support.

After testing, wio terminal can realize I2C port, UART port, LCD screen, and SD card at the same time. This means that wio terminal is compatible with all four.
Perhaps you could double check to see if the code you wrote was wrong?

Okay. I have had tried sometimes to see what could be wrong with the code but could not find it.
So I am pasting the code. The code has i2c sensor MPU6050, GPS module, LCD and SD card related lines.

#include <MPU6050reg.h>
#include <Wire.h>
#include "MPU6050IMU.h"
#include <SPI.h>
#include <Seeed_FS.h>
#include "SD/Seeed_SD.h"
#include <TFT_eSPI.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <seeed_line_chart.h>
#include <seeed_graphics_base.h>
#include"TFT_eSPI.h"
#include <seeed_graphics_define.h>

#define LCD_BACKLIGHT (72ul)

#define MAX_SIZE 100

doubles accdatax, accdatay, accdataz;
int ax, ay, az;

TFT_eSPI tft;
TFT_eSprite spr = TFT_eSprite(&tft);

// Choose two Arduino pins to use for software serial
int RXPin = D1;
int TXPin = D0;

//Default baud of NEO-6M is 9600
int GPSBaud = 9600;

//create a TinyGPS++ object
TinyGPSPlus gps;

// Create a software serial port called "gpsSerial"
SoftwareSerial gpsSerial(RXPin, TXPin);

File accelLog;
File gpsInfo;

MPU6050IMU imu;
float temp[3];

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
  Serial.begin(9600);  
 // while (!Serial){}

  // Start the software serial port at the GPS's default baud
  gpsSerial.begin(GPSBaud);

  //begin the SD card to store the data.
  Serial.print("Initialize the SD card");
  
  if(!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)){
    Serial.println("initialization failed!");
    while(1);
    }
  Serial.println("Sd card initialization done..");

  //begin the sensor
  imu.begin();
  delay(1000);
  
  tft.begin();          /* TFT init */
  tft.setRotation(3); /* Landscape orientation, flipped */
  tft.fillScreen(TFT_WHITE);
  spr.createSprite(TFT_HEIGHT, TFT_WIDTH);
  
}

void loop() {
  
  spr.fillSprite(TFT_WHITE); 
  
  gpsInfo = SD.open("gps.txt", FILE_WRITE);
  gpsInfo.println("GPS-Lat\t GPS-Lon\t Ax\t Ay\t Az\n");

  if(accdatax.size() > MAX_SIZE)
  {
    
    accdatax.pop();
    accdatay.pop();
    accdataz.pop();      
  }
  
  int range = 8;
  imu.readaccelerometer(temp, 8);
  
  Serial.print((temp[0]));
  Serial.print(" ");
  
  Serial.print((temp[1]));
  Serial.print(" ");
    
  Serial.print(" ");
  Serial.println((temp[2]));

  ax = (int)(temp[0]);
  ay = (int)(temp[1]);
  az = (int)(temp[2]);

  accdatax.push(ax);
  accdatay.push(ay);
  accdataz.push(az);


  //settings for the line graph title
  auto header =  text(0, 0)
                .value("Accelerometer data")                  
                .align(center)
                .valign(vcenter)
                .width(tft.width())
                .thickness(2);
                
  header.height(header.font_height(&spr) * 2);
  header.draw(&spr);

  //settings for line graph
  auto contentx = line_chart(20, header.height());
       contentx
              .height(tft.height() - header.height())
              .width(tft.width() - contentx.x() * 2) //actual width of the line chart
              .based_on(-8.0) //Starting point of y-axis, must be a float
              .show_circle(false) //drawing a cirle at each point, default is on.
              .value(accdatax) //passing through the data to line graph
              .max_size(MAX_SIZE)
              .color(TFT_BLUE) //Setting the color for the line
              .backgroud(TFT_WHITE)
              .draw(&spr);

  auto contenty = line_chart(20, header.height());
       contenty
              .height(tft.height() - header.height())
              .width(tft.width() - contentx.x() * 2) //actual width of the line chart
              .based_on(-8.0) //Starting point of y-axis, must be a float
              .show_circle(false) //drawing a cirle at each point, default is on.
              .value(accdatay) //passing through the data to line graph
              .max_size(MAX_SIZE)
              .color(TFT_RED) //Setting the color for the line
              .backgroud(TFT_WHITE)  
              .draw(&spr);
              
  auto contentz = line_chart(20, header.height());
       contentz
              .height(tft.height() - header.height())
              .width(tft.width() - contentx.x() * 2) //actual width of the line chart
              .based_on(-8.0) //Starting point of y-axis, must be a float
              .show_circle(false) //drawing a cirle at each point, default is on.
              .value(accdataz) //passing through the data to line graph
              .max_size(MAX_SIZE)
              .color(TFT_GREEN) //Setting the color for the line
              .backgroud(TFT_WHITE)  
              .draw(&spr);
              
  spr.pushSprite(0, 0); 
  
  gpsInfo.print(gps.location.lat(), 6);
  gpsInfo.print("\t");
  gpsInfo.print(gps.location.lng(), 6);
  gpsInfo.print("\t");
  gpsInfo.print(temp[0]);
  gpsInfo.print("\t");
  gpsInfo.print(temp[1]);
  gpsInfo.print("\t");
  gpsInfo.println(temp[2]); 
  Serial.println("log info");    
  gpsInfo.close();
  delay(50);
  
}

If you find something wrong with the code please do let me know

Also please make sure that your power supply is adequate for your main board and all the modules together.

It looks like the I2C sensor you’re using isn’t Seeed Grove. If two Grove interfaces are used to connect two Grove sensors, the LCD screen and SD card can be used at the same time. Maybe you could switch to a Grove product