[size=150]Code for leonardo[/size]
Serial 1 hardware~
[code]
#include <SoftwareSerial.h>
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count = 0; // counter for buffer array
void setup()
{
Serial1.begin(19200); // the GPRS baud rate
Serial.begin(19200); // the Serial port of Arduino baud rate.
}
void loop()
{
if (Serial1.available()) // if date is comming from softwareserial port ==> data is comming from gprs shield
{
while (Serial1.available()) // reading data into char array
{
buffer[count++] = Serial1.read(); // writing data into array
if (count == 64)
break;
}
for ( int j=0;j<count;j++)
{
Serial.write(buffer[j]);
}
clearBufferArray(); // call clearBufferArray function to clear the storaged data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardwareserial port ==> data is comming from PC or notebook
Serial1.write(Serial.read()); // write it to the GPRS shield
}
void clearBufferArray() // function to clear buffer array
{
for (int i=0; i < count; i++)
{
buffer[i] = NULL;
} // clear all index of array with command NULL
}[/code]