I've been trying to write a small simple sketch, mainly using the SoftwareSerial library,
to see the response of the AT commands, to ensure I'm actually inputting them correctly
and of course to see what they respond with.
I used a couple of examples from previous projects, and some stuff I found online, and I got to this:
#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
boolean started=false;
void setup()
{
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
if (gsm.begin(2400))
{
Serial.println("\nstatus=READY");
started=true;
}
else
Serial.println("\nstatus=IDLE");
}
void loop()
{
//Enter AT command.
Serial.println("Enter AT command:\n");
char atCmd[200];
readSerial(atCmd);
mySerial.write(atCmd);
delay(100);
mySerial.println();
//Response from AT command.
Serial.println("Response:\n");
if(mySerial.available())
{
mySerial.write(Serial.read());
}
}
//Read serial input.
int readSerial(char result[])
{
int i = 0;
while(1)
{
while (Serial.available() > 0)
{
char inChar = Serial.read();
if (inChar == '\n')
{
result[i] = '\0';
Serial.flush();
return 0;
}
if(inChar!='\r')
{
result[i] = inChar;
i++;
}
}
}
}
And ofcourse, this doesn't work. I get an error when I try to compile, which is:
readwriteat.ino: In function 'void.loop()':
readwriteat:31: error: 'mySerial' was not declared in this scope.
I had a go changing it to Serial instead of mySerial, as I found suggested on
another forum, but this didn't change anything. My knowledge when it comes
to this is a bit limited, so I'm not entirely sure on which tips and instructions to follow.
If anybody can provide me some feedback on this, it would be greatly appreciated!
You might have already found this sketch, but I've been using the Arduino as just a serial patch. This lets me send AT commands and see their response from Terminal or the Arduino serial monitor. This short sketch does the trick:
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
void setup()
{
mySerial.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the GPRS baud rate
mySerial.println("AT+IPR=19200"); // Tell the SIM900 not to autobaud
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
The only trouble I ran into is that the serial buffer being 64 bytes means things like SMS messages which are larger than this don't print all their content. To resolve this, I modified the SoftwareSerial.h file in the SoftwareSerial library by editing this line:
#define _SS_MAX_RX_BUFF 256 // RX buffer size was 64
Sorry for the very late reply, had a lot of revising to do during the holidays.
I came across this piece of code before in another post I believe, and I get the problem that
I receive no responses. I don't know if that is due to me not inputting anything correct, or
I'm doing something else wrong. I tweaked it a little bit just to get the baud rate on a lower
setting, so I'm not entirely sure what is going wrong.
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART
#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 8);
void setup()
{
mySerial.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate
mySerial.println("AT+IPR=9600"); // Tell the SIM900 not to autobaud
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}