Librairie SD Arduino ne marche pas avec Proteus - carte SD ne s'initialise pas

Fermé
TheSiffer910 Messages postés 99 Date d'inscription lundi 21 décembre 2015 Statut Membre Dernière intervention 6 février 2019 - Modifié le 6 févr. 2019 à 18:09
 Darkairy - 18 mars 2019 à 15:04
Salut,

Je veux simuler un lecteur de carte SD sur Proteus. J'ai fait le programme mais qua,d je lance la simulation, le Virtual Terminal (Port Série) me donne un message d'erreur codé afin de savoir si la carte SD est accessible.
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}

J'ai écrit ça dans le void setup, j'ai déjà déclaré chipSelect en tant qu'OUTPUT et inclus la librairie SD d'Arduino (voir le code en entier plus tard). Pourtant, le Virtual Terminal affiche "Card failed, or not present", alors qu'elle est bien présente.
J'ai joint quelques screens de Proteus.
De plus, quand je code ceci:
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.");
}

cette phase se déroule bien et ça affiche bien "card initialised" mais plus tard "error opening datalog.txt" s'affiche (de nouveau, voir plus bas dans le code entier).
J'en ai déduit que Proteus ne comprenait pas lelibrairie SD Arduino et donc ne comprenait pas "SD.begin()" and SD.open()".
Si quelqu'un pouvait m'aider ça serait bienvenu parce que là je sèche.

Voici le code en entier (pas final, mais tout est là pour la carte SD):
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");
}
}


Merci de prendre le temps de lire ça. Je tiens aussi à rajouter que j'ai la dernière version de a librairie SD. Les screens sont en commentaire, je les avais oubliés.
A voir également:

2 réponses

TheSiffer910 Messages postés 99 Date d'inscription lundi 21 décembre 2015 Statut Membre Dernière intervention 6 février 2019 8
6 févr. 2019 à 18:10
Les screens Proteus



0
Hey ! Tu as trouvé la solution depuis ? J'ai exactement le même problème x)
0