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!
#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");
}
}