Pages: [1]   Go Down
Author Topic: GSM code and SD code not working together  (Read 793 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

The following code is not behaving like how I would expect. When I add in the readSD() method, the initializing of the setup() function does not finish. However, when I remove JUST the readSD() method, the program works like its supposed to. I do not understand why adding this code in would cause the setup() to hang. I don't even call readSD() anywhere in the program.

Additional information: I added in the readSD() method to read data from a jpg that is saved on the SD card and write it to the Serial comm lines when my SIM900 GSM/GPRS module is waiting for a picture to download.

Please help. Also, if you  have been able to send MMS using the SIM900 module, please contact me as I am having trouble getting this feature to work. ted_pham08@yahoo.com

Thank you!

Code:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include <SD.h>

//Simple sketch to communicate with SIM900 through AT commands.

int numdata;
char inSerial[50];
int i=0;


void setup()
{
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(9600))
    Serial.println("\nstatus=READY");
  else Serial.println("\nstatus=IDLE");
};

void loop()
{
  //Read for new byte on serial hardware,
  //and write them on NewSoftSerial.
  serialhwread();
  //Read for new byte on NewSoftSerial.
  serialswread();
  //delay(1000);
};

void serialhwread(){
  i=0;
  if (Serial.available() > 0){           
    while (Serial.available() > 0) {
      inSerial[i]=(Serial.read());
      delay(10);
      i++;     
    }
   
    inSerial[i]='\0';
    if(!strcmp(inSerial,"/END")){
      Serial.println("_");
      inSerial[0]=0x1a;
      inSerial[1]='\0';
      gsm.SimpleWriteln(inSerial);
    }
    //Send a saved AT command using serial port.
    if(!strcmp(inSerial,"TEST")){
      Serial.println("SIGNAL QUALITY");
      gsm.SimpleWriteln("AT+CSQ");
    }
    else{
      Serial.println(inSerial);
      gsm.SimpleWriteln(inSerial);
    }   
    inSerial[0]='\0';
  }
}

void serialswread(){
  gsm.SimpleRead();
}

void readSD() {
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(10)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("x.jpg");

  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
      //Serial.print(dataFile.read());
    }
    dataFile.close();
  } 
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The following code is not behaving like how I would expect.
On which Arduino?

Quote
When I add in the readSD() method, the initializing of the setup() function does not finish. However, when I remove JUST the readSD() method,
The readSD method is not a trivial method. It drags in the whole SD library, with it's (necessary) 512 character buffer.

You might be running out of memory.

Have you confirmed that the Arduino can read, in a different sketch, from the SD card?

Which GSM shield? Which SD shield? Have you checked for pin conflicts?
Logged

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

Hi. Thanks for responding.

I am using an Arduino Uno. When I compile the sketch, it says: Binary sketch size: 13,218 bytes (of a 32,256 byte maximum). Would this cause the microcontroller to run out of memory?

I am using an IComSat v1.1 Sim900 GSM GPRS module and a parallax microSD adapter. I have verified that the SD card is able to read and write.

When you say that the SD library has a 512 character buffer, is that something that is changeable in the library?
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Would this cause the microcontroller to run out of memory?

That is telling you how much flash program storage will be used. It doesn't tell you how much SRAM you will use. On an Arduino Uno, there is only 2KB of SRAM. See http://www.arduino.cc/playground/Code/AvailableMemory for a way to find out how much SRAM is being used.

Quote
When you say that the SD library has a 512 character buffer, is that something that is changeable in the library?

I don't think so, it is that size because SD cards are read from/written to in 512 byte segments.
Logged

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

Hello,

Can anybody tel my where to put the power supply for the icomsat module ?

Is that in the Arduino CPU connector ?

Is that on a connector in the Icomsat 1.1 module ?

Many thanks for your help.

Thierry
Logged

Pages: [1]   Go Up
Jump to: