Arduino SD library not working in Proteus? SD card not initialising

Hi,

I want to simulate a SD card reader and Writer on Proteus. I made a code but when I launch the simulation, the Virtual Terminal (Serial port) gives me a coded troubleshooting error message.

if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}

This is written in the void setup, I already declared CS pin as OUTPUT and included the SD library (see full code later). However, the Virtual Terminal shows “Card failed, or not present”, even tho it is.
I joined some Proteus screenshots.
Moreover, when I code this:

Sd2Card card;
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
    
  pinMode(chipSelect, OUTPUT);
  }
  Serial.print("Initializing SD card...");

  // see if the card is present and can be initialized:
  if (!card.init()) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
Serial.println("card initialized.");
}

this phase goes on and displays “card initialised” but later the “error opening datalog.txt” shows up (again, see full code).
I came to the conclusion that Proteus just didn’t understand the Arduino SD library for some reason so that it doesn’t understand “SD.begin()” and SD.open()".
If someone could help me solve this problem I would be thankful.

Here is the full code (so far):

int VSIG_num = A0; /* The numerical converted value of the received voltage is an integer
and will be read on the analogical pin 0 (later defined as an analogical input) */
int VSIG_read = 0; // VSIG_read is the numerical value Arduino gives to VSIG, between 0 and 1023
int VSIG = 0; // The actual value of the output voltage of the sensor, later calculated
int intensity = 0; // The value we seek to find, luminous intensity

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

const int chipSelect = 10;

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
    
  pinMode(chipSelect, OUTPUT);
  }


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

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");
}

void loop() {

    long sum = 0;
    for(int i=0;i<1024;i++) // Used here to make an average of the value
    {    
      VSIG_read = analogRead(VSIG_num); // Obtains the numerical value of VSIG given by Arduino
      sum = VSIG_read+sum;
      delay(2);
    }
    sum = sum >> 10; // Divides the total by 1024 to make the average (10 bits shift = /1024)
    VSIG = sum*5/1024; // Calculates the actual value of the output voltage of the sensor
    intensity = 307*VSIG; // Calculates the luminous intensity according to the given calculation


  String dataString = "";
  dataString += String(intensity);
  dataString += ",";

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    Serial.println(dataString);
  }
  else  {
    Serial.println("error opening datalog.txt");
  }
}

Thank you for taking time reading this. Btw, I have the latest version of the Arduino SD library.

You do NOT have a problem with the Arduino.

Take your proteus problem to the proteus forum.

Shoot... Then how do I archive this post?

NRShrimp: Shoot... Then how do I archive this post?

You don't. You have to leave it for everyone to see, forever.