Hello I have a Neoway M590 wired and running through a logic level converter wired to my nano but it is still giving me rubbish. On occasion the occasional line will be legible and so is the occasional letter. Please can you guys help
(deleted)
Hi,
Welcome to the forum.
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Thanks... Tom...
Thanks for responding I have fixed my initial problem it was my logic converter and i have switched to a voltage divide working ok. Now all I want is for me to text the number and a servo to move depending on the input. I found the code and have altered slightly but it doesn't engage the servo. I think the code is trying to ready the sms messages from storage but the sms is displayed in the serial monitor. Ideally I need it to just go he that says open move servo. I will appreciate any help.
#include <SoftwareSerial.h>
#include <Servo.h>
//Create software serial object to communicate with M590
SoftwareSerial M590(2,3);
Servo myservo;
// EN: String buffer for the GPRS shield message
String msg = String("");
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
int SmsContentFlag = 0;
void setup() {
//Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
while(!Serial);
myservo.attach(9);
// Initialize PINs
pinMode( 6, OUTPUT);
digitalWrite( 6, LOW);
//Being serial communication with Arduino and M590
M590.begin(9600);
delay(15000);
M590.println("AT");
delay(300);
M590.println("ATE0");
delay(300);
M590.println("AT+CMGF=1");
delay(300);
M590.println("AT+CNMI=2,2,0,0,0"); // set module to send SMS data to serial out upon receipt
delay(300);
M590.println("AT+CMGD=0,4");
delay(300);
M590.println("AT+CSCS=\"GSM\"\r");
delay(300);
M590.println("AT+CREG?");
Serial.println("Setup Complete!");}
void loop(){
//Read M590 output (if available) and print it in Arduino IDE Serial Monitor
if(M590.available()){
Serial.write(M590.read());
}
//Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
if(Serial.available()){
M590.write(Serial.read());
}
char SerialInByte;
if(M590.available())
{
SerialInByte = (unsigned char)M590.read();
Serial.print(SerialInByte);
delay(5);
// -------------------------------------------------------------------
// EN: Program also listen to the GPRS shield message.
// -------------------------------------------------------------------
// EN: If the message ends with <CR> then process the message
if( SerialInByte == 13 ){
// EN: Store the char into the message buffer
ProcessGprsMsg();
}
if( SerialInByte == 10 ){
// EN: Skip Line feed
}
else {
// EN: store the current character in the message string buffer
msg += String(SerialInByte);
}
}
}
// EN: Make action based on the content of the SMS.
// Notice than SMS content is the result of the processing of several GPRS shield messages.
void ProcessSms( String sms ){
if( sms.indexOf("on") >= 0 ){
Serial.println("On");
digitalWrite( 6, HIGH );
}
if( sms.indexOf("off") >= 0 ){
Serial.println("Off");
digitalWrite( 6, LOW );
}
if( sms.indexOf("open") >= 0 ){
Serial.println("Opening");
myservo.write(180);
}
if( sms.indexOf("close") >= 0 ){
Serial.println("Closing");
myservo.write(0);
}
}
// EN: Request Text Mode for SMS messaging
void GprsTextModeSMS(){
M590.println( "AT+CMGF=1" );
}
void GprsReadSmsStore( String SmsStorePos ){
M590.print( "AT+CMGR=" );
M590.println( SmsStorePos );
delay(200);
//Deletes SMS from sim once read
M590.print( "AT+CMGD=" );
M590.println( SmsStorePos );
}
// EN: Clear the GPRS shield message buffer
void ClearGprsMsg(){
msg = "";
}
// EN: interpret the GPRS shield message and act appropiately
void ProcessGprsMsg() {
if( msg.indexOf("Call Ready") >= 0 ){
Serial.println("*** GPRS Shield registered on Mobile Network ***");
GprsTextModeSMS();
}
// EN: unsolicited message received when getting a SMS message
if(msg.indexOf("+CMTI") >= 0 ){
Serial.println("*** SMS Received ***");
// EN: Look for the coma in the full message (+CMTI: "SM",6)
// In the sample, the SMS is stored at position 6
int iPos = msg.lastIndexOf(",");
String SmsStorePos = msg.substring( iPos+1 );
Serial.print( "SMS stored at " );
Serial.println( SmsStorePos );
// EN: Ask to read the SMS store
GprsReadSmsStore( SmsStorePos );
}
// EN: SMS store readed through UART (result of GprsReadSmsStore request)
if( msg.indexOf( "+CMGR:" ) >= 0 ){
// EN: Next message will contains the BODY of SMS
SmsContentFlag = 1;
// EN: Following lines are essentiel to not clear the flag!
ClearGprsMsg();
return;
}
// EN: +CMGR message just before indicate that the following GRPS Shield message
// (this message) will contains the SMS body
if( SmsContentFlag == 1 ){
Serial.println( "*** SMS MESSAGE CONTENT ***" );
Serial.println( msg );
Serial.println( "*** END OF SMS MESSAGE ***" );
ProcessSms( msg );
}
ClearGprsMsg();
// EN: Always clear the flag
SmsContentFlag = 0;
}