Offline
Newbie
Karma: 0
Posts: 10
|
 |
« on: June 29, 2012, 07:29:40 am » |
I'm with a problem reading the Micro Sd through the Ethernet Shield, the first time it reads the file, but the second time he already failed, perhaps I'm using the keypad? or by using the library display 128x64 GLCD? #include <glcd.h> #include <fonts/allFonts.h> #include <Keypad.h> #include <SD.h>
//DECLARAÇÃO DO TECLADO unsigned long startMillis; unsigned int iter = 0; unsigned int iterStart = 0;
const byte ROWS = 4; //four rows const byte COLS = 4; //three columns
char keys[ROWS][COLS] = { { '1','2','3','A' } , { '4','5','6','B' } , { '7','8','9','C' } , { '*','0','#','D' } };
byte rowPins[ROWS] = { A12, A13, A14, A15}; //connect to the row pinouts of the keypad byte colPins[COLS] = { A8, A9, A10,A11}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); char key = keypad.getKey();
char id[5]; int a=0;
const int chipSelect =4;
void setup() { Serial.begin(9600); pinMode(10, OUTPUT);
//INICIALIZAÇÃO DO DISPLAY GLCD.Init(NON_INVERTED); // initialise the library GLCD.ClearScreen(); //limpa lcd GLCD.SelectFont(System5x7); // select fixed width system font GLCD.SetTextMode(SCROLL_UP);
}
void loop(){ int i=0; delay(150); GLCD.ClearScreen();
GLCD.CursorTo(0,0); GLCD.print("ID=");
//SE NÃO FOI DIGITADO NENHUM ID AINDA ID=0000 if (a == 0){ //A VARIAVEL FOR FALSA ELE JOGA O ID = 0000 for(i=0;i<5;i++){ id[i]=0; } }
while (i < 5 ){ //MOSTRA O ID GLCD.CursorTo(i+4,0); GLCD.print(id[i]); i++; } GLCD.CursorTo(0,1); GLCD.println("PRECIONE A FUNCAO DESEJADA"); GLCD.println("A=Identificação"); GLCD.println("B=Mensagens Diversas");
//MENU DE ESCOLHA switch (key = keypad.getKey()){
case 'B': Sd(); break; }}
} }
//**************--------------****************************************---------------------------------------**********
void Sd(){ File myFile; delay(110); myFile = SD.open("test.txt", FILE_WRITE); if (!SD.begin(4)) { 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("done."); } else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } delay(110); // 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()); } myFile.close();
} else { // if the file didn't open, print an error: Serial.println("error opening test.txt"); } }
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #1 on: June 29, 2012, 07:33:31 am » |
Try disabling the w5100 SPI. That caused the same problem with my SD card. void setup() { Serial.begin(9600); pinMode(10, OUTPUT); // add this digitalWrite(10,HIGH);
// rest of your setup }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #2 on: June 29, 2012, 07:46:06 am » |
Continue message initialization failed! 
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #3 on: June 29, 2012, 07:52:50 am » |
void Sd(){ File myFile; delay(110); // you are opening this before the SD is initialized myFile = SD.open("test.txt", FILE_WRITE); // this should be in setup() if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // rest of code
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #4 on: June 29, 2012, 08:53:24 am » |
I still have problems, will be a problem of the Ethernet Shield? Sdfat16 tried to use the library but could not.
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #5 on: June 29, 2012, 09:08:15 am » |
Try this sketch. Does the SD still fail? #include <SD.h>
void setup() { Serial.begin(9600); pinMode(10,OUTPUT); digitalWrite(10,HIGH);
Serial.print("Starting SD..."); if(!SD.begin(4)) Serial.println("failed"); else Serial.println("ok"); }
void loop() { }
edit: My bad on the serial command. If it fails, explain what keypad and GLCD you are using, and how they are connected.
|
|
|
|
« Last Edit: June 29, 2012, 09:50:21 am by SurferTim »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #6 on: June 29, 2012, 09:55:49 am » |
I managed to make it work with the library fat16, someone has some examples explaining the commands?
The 4x4 keypad is connected to pins A10 ... A15 The display is connected to pins traditional, is the type B.
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #7 on: June 29, 2012, 11:11:21 am » |
The display is connected to pins traditional, is the type B. Can you be more specific? The lcd stuff in the examples has pin assignments that will conflict with the SD. You can't use digital pins 4 or 10. Those are used by the SD and w5100.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #8 on: June 29, 2012, 11:20:29 am » |
Pino do Display LCD 128×64 Pin Arduino Mega 1 GND 2 5V 3 - 4 36 5 35 6 37 7 22 8 23 9 24 10 25 11 26 12 27 13 28 14 29 15 33 16 34 17 Reset 18 - 19 5V 20 GND
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #9 on: June 29, 2012, 11:41:34 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #10 on: June 29, 2012, 11:47:07 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Miramar Beach, Florida
Offline
Faraday Member
Karma: 60
Posts: 3547
|
 |
« Reply #11 on: June 29, 2012, 11:52:56 am » |
That looks ok. I see no conflict. You said above "I managed to make it work", so it is working now?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #12 on: June 29, 2012, 11:59:17 am » |
Yes,using SdFat16 worked, but it is much more complicated, I am having difficulty sending the data file for the serial. Sorry for my english beginner. 
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #13 on: June 29, 2012, 12:36:41 pm » |
It worked, thanks for the support. 
|
|
|
|
|
Logged
|
|
|
|
|
|