Pages: [1]   Go Down
Author Topic: Arduino Mega + Ethernet Shield  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Quote
Code:
#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
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try disabling the w5100 SPI. That caused the same problem with my SD card.
Code:
void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT);
  // add this
  digitalWrite(10,HIGH);

  // rest of your setup
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Continue message initialization failed!   smiley-cry
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try this sketch. Does the SD still fail?
Code:
#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 Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this the GLCD you are using?
http://www.sparkfun.com/products/710
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is the display http://www.datasheetcatalog.org/datasheet/vishay/128g064e.pdf
Logged

Miramar Beach, Florida
Online Online
Faraday Member
**
Karma: 147
Posts: 6040
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That looks ok. I see no conflict. You said above "I managed to make it work", so it is working now?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. smiley-cry
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It worked, thanks for the support.  smiley
Logged

Pages: [1]   Go Up
Jump to: