Go Down

Topic: "cellphone" shield? (Read 4 times) previous topic - next topic

Malcolm H

OK, but remember that the GSM module will draw more power than the USB port can supply.

Yes,  thanks.
The set up is running from a 12v 2.5a Supply, into Vin.

The Unit will always send the first SMS without a problem.
The second and subsequent  SMS's fail with a error message from the SM5100.

The error is as listed before CME Error 4 (an unknown command error).
I can still query the unit, and get an answer, using other queries, like AT  and I get OK.

There is something I cant find getting in the way of the next message.
Like an unfinished command getting fed into the sm5100 before I start the SMS sending loop.

Does any one have a working code example?
IE push a button and send an SMS.
I would love to see one, and test with my hardware.

MH


PaulS

Quote
There is something I cant find getting in the way of the next message.
Like an unfinished command getting fed into the sm5100 before I start the SMS sending loop.

Maybe some other eyes looking at the code would help. Post your code.

Anachrocomputer

Quote
The set up is running from a 12v 2.5a Supply, into Vin.


OK, so how much current can the on-board regulator supply?  I'm not sure myself, so it's worth looking up. Remember that the regulator will be dropping 7V, so it'll be dissipating quite a bit of heat.

In my experience, bizarre hardware behaviour can be caused by marginal power supplies. I certainly had the GSM Playground crash unexpectedly when I didn't have it connected to a LiPo battery.

wayneft

How long are you waiting before sending the next SMS?  I didn't see it documented in the datasheet but in the Telit datasheet (I use the GE865) they warn you that it could take up to 60 seconds before the message goes through.  If you're trying to send the next message during this timeout period then you will probably get an error.  Try issuing just a "AT" command prior to sending each SMS and see if that helps.  If it does it's probably a timeout issue.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Malcolm H

I would have thought that Sparkfun designed the board with its high current regulator to be able to drive the GSM unit from the 5v supply.

Regardless running from a 12v 2.5A psu there is No voltage drop or fluctuation from the 3.3v, 5v, or Vin +12v lines when sending a SMS.

And Like I said, it ALWAYS sends one SMS and it is DELIVERED to my phone.

Code dont fit in one post
M

Malcolm H

Here is the code.
Code: [Select]
#include <Messenger.h>
//#include <Time.h>         // Clock Function
#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h>         //Used for string manipulations
#include <Bounce.h>         //Used to de-bounce the door switches
#include <Metro.h>          //Timing function

// Instantiate Messenger object with the default separator (the space character)
Messenger message = Messenger(44);

char incoming_char=0;      //Will hold the incoming character from the Serial Port.
NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

//Door Inputs from 4 thru 12 (10 in total)
#define DoorInput1  4  // Door read switch connected to digital pin
#define BusyLed  12    // Red LED connected to digial pin 12
#define ReadyLed 13    // Green LED connected to digital pin 13
#define TestSMS 14     // Test button - Red Button on Analouge 0 (digital14)

//TIming of door hold and SMS sending
#define timing 5000         // Set the doorHoldOpen timing
#define timingRepeat 20000  // Set the time to reset a message.
#define TestTiming 5000     // Set the SMS Test time lockout.

// DEFINE SMS AND GSM SETTINGS
#define maxLength 200
char PHONE[ ] = "1234567890";  // Mobile number to send to
#define SMSTime 10        // How many minutes before sending the first SMS
#define SMSRepeat 15     // How many minuted before sending additional SMS messages.
//String inString = String(maxLength);
#define MAXSIZE 30
char string[MAXSIZE];

int SMS1 = 0;
int SMS0 = 0;
int SIND = 0;

int isActive1 = 0;
int isActive0 = 0;

int state1 = 0; // Open or Closed State of a Door
int state0 = 0; // Open or Closed state of the test button

// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce door1 = Bounce( DoorInput1,5 );
Bounce test  = Bounce( TestSMS, 5 );

Metro Door1Metro = Metro(timing, 1);
Metro TestSMSMetro = Metro(100, 1);


// Define messenger function
void messageCompleted() {
 // This loop will echo each element of the message separately
 while ( message.available() ) {
   if ( message.checkString("OK") )
            {
            digitalWrite (ReadyLed, HIGH);
            digitalWrite (BusyLed, LOW);
            Serial.println("GSM Ready - OK");
            }
   if ( message.checkString("+CME ERROR: 4") )
            {
            Serial.println(string); // Echo the string
            Serial.println("+CME ERROR:4 -operation not supported. This thing Sux");
            digitalWrite (ReadyLed, HIGH);
            digitalWrite (BusyLed, HIGH);
            cell.println("AT+COPS?");
            }      
   if ( message.checkString("+SIND: 4") )
           {  
           Serial.println("SIM Ready");
           bootOneTime();
           }
   
   message.copyString(string,MAXSIZE);
   Serial.print(string); // Echo the string
   Serial.println(); // Terminate the message with a carriage return  
 }
 
 
}

void sendSMSpreamble() {
   //StatCheckGSM();
   delay(1500);
   cell.print("at+cmgs=");  // comand message
   cell.print(34,BYTE);     // "
   cell.print(PHONE);       // Insert phone number
   cell.println(34,BYTE);   // "
   Serial.println("preamble");
   delay(1500);
}

void sendSMSappend() {
   delay(500);
   cell.println(26,BYTE);                // end of message command Ctrl-z
   Serial.println("append");
   delay(5000);
   isActive0 = 0;    //Finished Sending
}

void sendErrorSMS() {
   sendSMSpreamble();
   cell.print("Error: ");
  // cell.print(errorMsg[error]);
  // writeStatus();
   sendSMSappend();
}  

void StatCheckGSM() {
 cell.println("atz");
 delay(1000);
}

void sendTestSMS() {
 SetMode();
 sendSMSpreamble();
 sendStatus();
 sendSMSappend();
}

void sendStatus() {
 cell.print("Test SMS: ");
 cell.println(SMS0);
 Serial.println("message");
}

void sendStatusSMS() {
 sendSMSpreamble();
 //writeStatus();
 sendSMSappend();
}

void SetMode() {
 cell.println("at+cmgf=1");  //Set message mode to Text (1)
 Serial.println("setmode");
}

void bootOneTime() {
   digitalWrite (ReadyLed, LOW);
   digitalWrite (BusyLed, HIGH);
   cell.println("at+cmgf=1");  //Set message mode to Text (1)
   delay(1000);
   cell.println("AT+CSQ");  // Check signal strength
   Serial.println("System Ready....");
   digitalWrite (ReadyLed, HIGH);
   cell.println("AT+COPS?");
 }




void setup()
{
 //Initialize serial ports for communication.
 Serial.begin(9600);
 cell.begin(9600);

 // Attach the callback function to the Messenger
// message.attach(messageReady);
 message.attach(messageCompleted);
 pinMode(ReadyLed, OUTPUT);   // sets the digital pin 13 as output GREEN
 pinMode(BusyLed, OUTPUT);    // sets the digital pin 12 as output RED
 pinMode(DoorInput1, INPUT);  // sets the pin as input
 pinMode(TestSMS, INPUT);     // sets the digital pin 14 as input
 
 digitalWrite(DoorInput1, HIGH); // Activate Pull UP     Inputs wire to GND
 digitalWrite(TestSMS, HIGH);    // Activate Pull UP     Inputs wire to GND
 
 Serial.println("System Start....");
 int boot = 1;
 delay(1000);
 cell.println("AT+SBAND=4");  //Set the GSM to AU band 4
 delay(1000);


}

void loop() {
 
 // Test SMS button.
 // Update the debouncers
 test.update ( );   // Get the update value
 if ( test.read() != state0 && test.duration() > 100 ) {  // has our orientation changed for more the 100th a second?
   state0 = test.read();
   if ( state0 ) {
     Serial.println( "SMS Test OFF" );
   }
   else {
     Serial.println( "SMS Test ON" ); // Start the door timer to trigger an SMS
     isActive0 = 1; //
     digitalWrite (ReadyLed, LOW);
     digitalWrite (BusyLed, HIGH);
   }
 }
 
 
 int value0 = test.read();
 if ( value0 == HIGH) // Push button are N/O :: High is a UN-pushed Button
   {  
   TestSMSMetro.reset();
   }
 
 
 if ( isActive0 ) {      // Send Test SMS
     ++SMS0;
     Serial.print("Test SMS Trigger ");
     Serial.println(SMS0);
     sendTestSMS();  // Send Test SMS
     TestSMSMetro.interval(TestTiming);
 }

 
   
 // Update the debouncers
 door1.update ( );   // Get the update value
 if ( door1.read() != state1 && door1.duration() > 500 ) {  // has our orientation changed for more the 1/2 a second?
   state1 = door1.read();
   if ( state1 ) {
     Serial.println( "Door 1 Closed!" );
     isActive1 = 0;
     Door1Metro.reset(); // Door 1 timer
   }
   else {
     Serial.println( "Door 1 Open!" ); // Start the door timer to trigger an SMS
     isActive1 = 1; //
     Door1Metro.interval(timing);
   }
 }
 
 int value1 = door1.read();
 if ( value1 == HIGH) // Read switches are N/O :: High is a Closed Switch
   {  
   Door1Metro.reset(); // Door 1 timer
   }
 
 if ( isActive1 && Door1Metro.check() ) {
     ++SMS1;
     Serial.print("Door-1 Timing Trigger ");
     Serial.println(SMS1);
     Door1Metro.interval(timingRepeat);
 }

// Send the restore SMS
 if ( SMS1 >= 1  && isActive1 == 0 ) {
     Serial.print("Door-1 Restore. Now Closed after "); // Do something only if interval has elapsed and the metro is "active"
     Serial.print(SMS1);
     Serial.println(" times.");
     Door1Metro.interval(timing);
     cell.println("at+cmgf=1");
     Serial.println("at+cmgf=1");
     delay (100);
     cell.print("at+cmgs=");
     Serial.println("at+cmgs=");
     cell.print(34,BYTE);
     cell.print(PHONE);
     Serial.println(PHONE);
     cell.println(34,BYTE);
     //cell.print(13,BYTE);
     cell.print("Door 1 Restore. Door 1 Now secure. Door trigger was looped ");
     cell.print(SMS1);
     cell.print(" times.");
     cell.println(26,BYTE);
     cell.print("ok");
     SMS1 = 0;
   }
//cell.println("at+cmgf=1");
//cell.print("at+cmgs=");
//cell.print(34,BYTE);
//cell.print(PHONE);
//cell.println(34,BYTE);
//cell.print("Your Message Here");
//cell.print(SMS1); //insert counter
//cell.print(26,BYTE);  
   


  // The following line is the most effective way of using Serial and Messenger's callback
 while ( cell.available() )  message.process(cell.read () );

}


M

Malcolm H

Quote
How long are you waiting before sending the next SMS?


Anytime from after the message was received on my phone.
The sending process in the code takes about 8 seconds, delivery of the message to the phone normally takes about 3 seconds from the end of the loop.

It makes no difference if it is left sit for 1 min, 10 min or 10 hours, before the next 'Push'.

miloSA
Quote
I cannot tell you why, just yet, but I found that if I use a 32K sim card instead of a 64K sim card, all works properly.


No idea about this one.
The only SIM's I have here in OZ are the Telstra Next G 128k USIMs.

miloSA, what do you mean by "all works properly", what behaviour did you experience?

If you have it working can you post a work code example please.

MH




wayneft

Quote

     cell.print(SMS1);
     cell.print(" times.");
     cell.println(26,BYTE);
     [glow]cell.print("ok");[/glow]
     SMS1 = 0;



try deleting this line or changing "ok" to "AT" .
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

Malcolm H

Quote
try deleting this line or changing "ok" to "AT".


Did both, still fails on the second SMS.  
M

Malcolm H

#24
Aug 18, 2010, 08:30 am Last Edit: Aug 18, 2010, 09:38 am by malcolmatecs Reason: 1
Funny how things work out.
I now have it working fine.
Quote
cell.print(" times.");
     cell.println(26,BYTE);  // THIS IS THE PROBLEM...
     SMS1 = 0;


Taking out the println and it all works.
Quote
cell.print(" times.");
     cell.print(26,BYTE);
     SMS1 = 0;


Edit-
I can report it works fine on USB power for sending SMS, not a problem at all.

Next thing is to drop out the timing delays and see how fast I can bung out messages.
I will report back once its done.


M

wayneft

Glad to hear you got it working. I'm also working on a GSM project and would like to pass on a few things I've learned.

DON'T power it from USB.  Use an external supply or battery capable of supplying the necessary current.  The module will draw large amounts of current regularly (216Hz) up to 2 amps.  It will cause intermittent network registration problems and could potentially damage your USB controller because the USB port simply can't provide the necessary current.  

DON'T rely on delays between SMS sending to increase throughput.  It can take anywhere up to 60 seconds for the module to acknowledge successful completion of an SMS. The most reliable approach is to wait for the acknowledge message before transmitting the next SMS.  

Just a couple of things I've learned along the way.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

PaulS

The cell.println() is adding extra characters (carriage return and line feed) that, apparently, need to be processed before another message can be sent. Since nothing is expecting them to be there, nothing processes them, and they screw up additional commands.

Great that you found the problem.

tronixstuff

Hello
If anyone is interested, I have written the first of a trilogy of articles about the SM5100B GSM module shield and how to use it with our Arduino boards. There are examples you can use and so on. Please have a look at http://wp.me/pQmjR-1bM.
Check out my Arduino tutorials at http://tronixstuff.com/tutorials - Order my  Arduino book from http://nostarch.com/arduino

Go Up