Module SD et Mega 2560

bonjour
voila pour continuer sur mon projet testeur j'ai acheté un module sd LCstudio
je modifie mon fichier SdFatConfig pour avoir les bonnes connexion

/** Software SPI Master Out Slave In pin /
uint8_t const SOFT_SPI_MOSI_PIN = 51;
/
* Software SPI Master In Slave Out pin /
uint8_t const SOFT_SPI_MISO_PIN = 50;
/
* Software SPI Clock pin */
uint8_t const SOFT_SPI_SCK_PIN = 52;

le test sdinfo est bon
si je test en ecriture et lecture avec ReadWrite ou ReadWriteSdFat je me retrouve avec des dossier et caractere ilisible sur ma SD

une aide svp

ATTENTION, les librairies SD (il y en a plusieurs) n'acceptent généralement que les noms au format 8.3 (huit caractères pour le nom + 3 pour une extension). Des noms trop longs peuvent entraîner des plantages.

Il ne faut pas oublier de fermer les fichiers ouverts.

voici un des code uitilise

/*
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

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

This example code is in the public domain.

*/
#define SD_CS_PIN SS
#include <SPI.h>
//#include <SD.h>
#include <SdFat.h>
SdFat SD;

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 Leonardo only
}

Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
//pinMode(10, OUTPUT);

if (!SD.begin(SD_CS_PIN)) {
Serial.println("initialization failed!");
return;
}
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);

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

// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");

// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}

void loop()
{
// nothing happens after setup
}

carte sd formaté et je control avec Sdinfo
voir sdinfo.txt

il ecrit bien sur la SD (monitor serie ReadWrite.txt)mais je me retrouve avec des fichiers inexploitable voir jpg

sdinfo.txt (832 Bytes)

monitor serie ReadWrite.txt (129 Bytes)

Salut,

Ta carte SD est formaté en FAT32 ou NTFS ?, pourquoi ne pas utiliser la librairie SD qui existe déjà, elle apporte quoi SdFat ?.

@+

oui j'ai gardé la librairie SD et revue mes connections, mauvais contact
donc ça fonctionne je peu ecrire et lire

maintenant si je reprendmon post TESTEUR
j'ai deux varaible que je souhaite charger selon un choix dans la carte SD
je lit les fichier present sur la SD et je choisi

exemple
si choix 1selectionné
const char *nompoint[8] = {"J408","J407", "J406","J405", "J404","J403", "J402", "J401"};// nom des points inversés le N°0 ==N°9 de end
unsigned long motok[] = {0b110100000, 0b110100000, 0b001000000, 0b110100000, 0b000011000, 0b000011000, 0b000000110, 0b000000110}; // motif attendu
si choix 2 selectionné
const char *nompoint[8] = {"A","B", "C","D", "E","F", "G", "H"};// nom des points inversés le N°0 ==N°9 de end
unsigned long motok[] = {0b010100000, 0b010100000, 0b101000000, 0b010100000, 0b000011000, 0b000011000, 0b000001110, 0b000001110}; // motif attendu

etc......
je sais ecrire et charger du texte mais des variable comment faire

petit up
pour comment ecrire

const char *nompoint[8] = {"J408","J407", "J406","J405", "J404","J403", "J402", "J401"};// nom des points inversés le N°0 ==N°9 de end
unsigned long motok[] = {0b110100000, 0b110100000, 0b001000000, 0b110100000, 0b000011000, 0b000011000, 0b000000110, 0b000000110}; // motif attendu

sur carte sd et transert vers arduino

merci

Et plus particulièrement:

Bonjour,

je cherche aussi à écrire dans un fichier sur carte SD. Je n'arrive pas à y écrire une structure de ma composition, il me bloque sur la fonction :

Fichier.write( Buffer, TailleBuffer) ;

Buffer est un uint8_t qui doit correspondre à une adresse si j'ai bien compris (celle du démarrage de la lecture des données à copier) et il me refuse le moyenne de passer l'adresse de ma structure. Qui connaît le truc ? Je pense que tu devrais soit avoir rapidement le même problème, soit avoir la solution !

#include <SD.h>

#define BrocheSD 10

#define MAX_C 3

struct Entete{
char Version[5] ;
unsigned long Score ;
word Coups ;
} ;

struct Plateau {
word Tableau [MAX_C+1][MAX_C+1] ;
} ;

struct TOUR{
unsigned long Score ;
word Coups ;
Plateau Tour ;
} ;

Entete MonEntete ;
TOUR MonTour ;

String MonF = "Toto.2K8" ;
File Fichier ;
uint8_t AdresseBuffer ;

void setup()
{
MonEntete.Version ={'L','A','T','I','N'} ;
MonEntete.Score = 25 ;
MonEntete.Coups = 100 ;
Serial.begin(9600);
pinMode(BrocheSD, OUTPUT);
AdresseBuffer =&MonEntete ;
Fichier =SD.open(&MonF[0],FILE_READ) ;
Fichier.write((uint8_t)&MonF[0], 8) ; <----------------- Ca coince
}

String n'est pas un tableau. C'est un objet.
Donc soit tu travailles avec une variable de type string
soit tu utilises la méthode toCharArray() sur l'objet MonF. Voir là: toCharArray() - Arduino Reference

Si tu n'as pas impérativement besoin d'utiliser un objet String la première solution est plus simple et moins gourmande en mémoire.