Via SMS commando's aan uw Arduino geven.

Toon hier Uw afgeronde projecten aan anderen.
Berichten: 2
Geregistreerd: 06 Mei 2015, 15:47

Via SMS commando's aan uw Arduino geven.

Berichtdoor Jay Brad » 09 Feb 2016, 16:44

[code][/code]Dit is mijn eerste projectje dat ik aan dit forum wil toevertrouwen in de hoop dat iemand er wat aan heeft.
Het project bestaat uit een Arduino-2560, een NEOWAY M590 module, een 4 kanalen level up-down converter en een Step down converter om 4,2 volt voor de module te maken.
Met deze sketch kun een commando wat je met je GSM naar de module gestuurd hebt omzetten in een actie van de Arduino, als voorbeeld in de sketch schakelen we de interne led aan en uit,
Wanneer je twee van deze modules hebt kun je dus ook zonder GSM een commando sturen.
Ik heb de sketch in het Engels gedocumenteerd, maar dat zal wel geen probleem zijn.

cpp code
/*NEOWAY M590 GPRS Module demo.
This is a example sketch to explain the receiving of a SMS text to switch on and off the internal LED.
Remember that every time the module is is powered up, it loses the 1st message send to it for some reason,
in stead of the message it sends the date and time like this, "16/02/09,13:32:44+04"
I bought several modules, and gues what, all had differend baudrates.
So if there is no response from the module, first try another baudrate before something else.
You can easely set the baudrate to your needs trough an AT command and then save the configuration.

Be aware of the VCC of the module, the datasheet says max 4,2 volt, i dont know if you damage the module
by connecting it to 5 volt. I use a cheap step down converter with display from AliExpress
Futhermore, the input level on the RX/TX datalines is 3,3 volt, you have to use a levelconverter.
Also make sure that the data connections between Arduino and M590 are crosswired, so connect
RX Arduino to TX Module and TX Arduino to RX Module.

This sketch is totaly without any copyright use it as you like.
I used a Mega2560 TX2 / RX2 but u can use any other arduino with only one serial port
if you dont use the serial monitor, or use softserial on a low baudrate.

Jay Brad, The Netherlands 10-02-2016 For comment mail to jaysketch2016@gmail.com

*/






int inByte = 0; // Incoming byte from the M590 module
String Message = ""; // String to hold and build the incoming characters.
int ledPin = 13; // Internal LED is connected to pin 13




void setup()

{
Serial2.begin(19200); // Set the baudrate of the GSM/GPRS Module.
Serial.begin(9600); // Set the baudrate of the serial monitor, start serial port at 9600 bps

pinMode(ledPin, OUTPUT); // Set pin 13 as output, so we can switch on and off the internal led.

delay(1000);

Serial.println("Example of receiving a SMS txt on a M590 Neoway GSM Module. ");
Serial.println("By Jay Brad !! 02-02-2016");
delay(1000);

Serial2.print("AT+CMGF=1\n\r"); // Set the module message mode, set either at 0 or 1 : 0 = PDU / 1 = Text mode.
delay(1000);
Serial2.print("AT+CSCS=\"GSM\"\r"); // Set the character sets : “GSM” = default alphabet (GSM03.38.6.2.1)
delay(1000);

Serial2.print("AT+CNMI=2,2,0,0,0\n\r"); // Set message indication Format, AT+CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,<bfr>]]]]]
// Where <mode> = 2: under On-line State, message indication code is cashed in module. When
// processing released, output indication code through serial port. Under its state,
// display indication code on terminal equipment directly.
// Where <mt> = 1: the message content is not displayed directly but storaged.
// Where <mt> = 2: the message content is displayed directly but not storaged.

delay(2000);
}



void loop()

{
Message = "";

for (int l=0; l<4; l++) // Receive 4 times a '"' character before we can go on.
{
do
{
while ( !Serial2.available() ); // Wait till we receive a character.
}
while (Serial2.read() != '"' ); // As long as it is not a '"' we go fetch the next character.
}

for (int l=0; l<2; l++) // Receive another two characters before we can read the actual message.
{
while ( !Serial2.available() ); // Wait till we receive a character.
inByte = Serial2.read(); // Read the character, but do nothing with it.
}



while(1) // Now we are going to read the message.
{
while ( !Serial2.available() ); // Wait till we receive a character.
inByte = Serial2.read(); // Store the character in inByte;

if ( inByte == '\r' ) // If we read an end of text marker we stop.
break;

else; Message += char(inByte); // Else we add the character to the Message String.
}

Check_Message(Message); // What can we do with the received message ??
Message = ""; // Clear the Message afterwards.

}

void Check_Message(String M) // Here we can control things depending on the message M.
{
if (M == "L1 on") // The Message M is a command to switch the light on.
{
Serial.println ("Internal LED is turned on."); // Do something.
digitalWrite(ledPin, HIGH);
M = ""; // Clear the Command M.
}

if (M == "L1 of") // The Message M is a command to switch the light off.
{
Serial.println ("Internal LED is turned off."); // Do something.
digitalWrite(ledPin, LOW);
M = ""; // Clear the Command M.
}


if (M != "") // If the Message M is not a command but a Message or a unknown command.
{
Serial.println (M); // Then print the Message or the unknown command.
M = ""; // Clear the Message.
}
}

Advertisement

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor nicoverduin » 09 Feb 2016, 16:54

Mooi!!
TIP: Wees voorzichtig met String. String is een memory killer. In die zin dat elke keer als je een byte toevoegt, er nieuw geheugen wordt gealloceerd. char is veiliger en beter beheersbaar op dit soort controllers. Er zit namelijk geen "garbage collection" op waardoor het geheugen dat vrijkomt ook daadwerkelijk weer op de zgn. Heap terecht komt.
Dit zijn kleine berichten en stack wise lijkt het goed te gaan omdat de berichten kort zijn. Worden het langere berichten zou je bij grote programma's wel eens in de problemen kunnen komen door een "freeze" van je programma omdat geheugen overschreven wordt.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 2
Geregistreerd: 06 Mei 2015, 15:47

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor Jay Brad » 15 Feb 2016, 10:44

Hoi Nico,
Heb de sketch een beetje aangepast.

cpp code
/*
NEOWAY M590 GPRS Module demo.
This is a example sketch to explain the receiving of a SMS text to switch on and off the internal LED.
Remember that every time the module is is powered up, it loses the 1st message send to it for some reason,
in stead of the message it sends the date and time like this, "16/02/09,13:32:44+04"
I bought several modules, and gues what, all had differend baudrates.
So if there is no response from the module, first try another baudrate before something else.
You can easely set the baudrate to your needs trough an AT command and then save the configuration.

Be aware of the VCC of the module, the datasheet says max 4,2 volt, i dont know if you damage the module
by connecting it to 5 volt. I use a cheap step down converter with display from AliExpress
Futhermore, the input level on the RX/TX datalines is 3,3 volt, you have to use a levelconverter.
Also make sure that the data connections between Arduino and M590 are crosswired, so connect
RX Arduino to TX Module and TX Arduino to RX Module.

This sketch is totaly without any copyright use it as you like.
I used a Mega2560 TX2 / RX2 but u can use any other arduino with only one serial port
if you dont use the serial monitor, or use softserial on a low baudrate.

Jay Brad, The Netherlands 10-02-2016

*/





int inByte = 0; // Incoming byte from the M590 module
String Message = ""; // String to hold and build the incoming characters.
int ledPin = 13; // Internal LED is connected to pin 13

int vrijRam () { // For testing only Remove if you like.
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

int ReadChar()
{
while (!Serial2.available()) ;
return Serial2.read();
}


void setup()

{
Serial2.begin(19200); // Set the baudrate of the GSM/GPRS Module.
Serial.begin(9600); // Set the baudrate of the serial monitor, start serial port at 9600 bps


pinMode(ledPin, OUTPUT); // Set pin 13 as output, so we can switch on and off the internal led.

delay(1000);

Serial.println("Example of receiving a SMS txt on a M590 Neoway GSM Module. ");
Serial.println("By Jay Brad !! 02-02-2016");
Serial.println("");
Serial.println("Wacht 10 seconden zodat de module de tijd heeft om zich aan te melden bij het netwerk.");
delay(10000);

Serial2.print("AT+CMGF=1\n\r"); // Set the module message mode, set either at 0 or 1 : 0 = PDU / 1 = Text mode.
delay(1000);
Serial2.print("AT+CSCS=\"GSM\"\r"); // Set the character sets : “GSM” = default alphabet (GSM03.38.6.2.1)
delay(1000);

Serial2.print("AT+CNMI=2,2,0,0,0\n\r"); // Set message indication Format, AT+CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,<bfr>]]]]]
// Where <mode> = 2: under On-line State, message indication code is cashed in module. When
// processing released, output indication code through serial port. Under its state,
// display indication code on terminal equipment directly.
// Where <mt> = 1: the message content is not displayed directly but storaged.
// Where <mt> = 2: the message content is displayed directly but not storaged.

delay(1000);
Serial2.print("AT+CMGD=1,4\n\r"); // Delete all messages from the current storage.
delay(1000);
}



void loop()

{

Message = "";

int count = 0; // Receive 4 times a '"' character before we can go on.
do
{
if (ReadChar() == '"')
count++;
}
while (count < 4);



inByte = ReadChar(); // Receive another two characters before we can read the actual message.
inByte = ReadChar(); // Read the character, but do nothing with it.




while(1) { // The actual message, read and append to message until a \r
inByte = ReadChar();

if (inByte == '\r')
break;
else
Message += char(inByte);

}

Check_Message(Message); // What can we do with the received message ??
}





void Check_Message(String M) // Here we can control things depending on the message M.
{
if (M == "L1 on") // The Message M is a command to switch the light on.
{
Serial.println ("Internal LED is turned on."); // Do something.
digitalWrite(ledPin, HIGH);
}

if (M == "L1 of") // The Message M is a command to switch the light off.
{
Serial.println ("Internal LED is turned off."); // Do something.
digitalWrite(ledPin, LOW);
}


if (M != "") // If the Message M is not a command but a Message or a unknown command.
{
Serial.println (M); // Then print the Message or the unknown command.
}

M = ""; // Clear the Command M.

Serial.print("Vrij geheugen is : " + String(maxCount) + " : "); // For testing only Remove if you like.
Serial.println(vrijRam()); // For testing only Remove if you like.

}

Berichten: 2
Geregistreerd: 04 Apr 2016, 12:44

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor henk2 » 04 Apr 2016, 13:00

Hallo,
ik ben hier nieuw en ondeskundig, doch heb belangstelling voor deze Neoway M590 software en had graag wat hulp indien mogelijk.
ik heb een controller arduino uno r3 en de unit neoway m590. ik wil dus op afstand een led aan en uit kunnen schakelen.
bij het gebruiken van dit programma gaat er wat fout "SERIAL2"
mvg henk arends

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor nicoverduin » 04 Apr 2016, 13:51

Dat klopt. Jij gebruikt een UNO en die heeft geen 2e Serial. De TS gebruikt een Mega2560. Die heeft meerder hardware serials.
Maar niet getreurd mogelijk is er een oplossing in SoftwareSerial.
Ik heb bovenstaande sketch ff aangepast. voor de UNO.
cpp code
/*
NEOWAY M590 GPRS Module demo.
This is a example sketch to explain the receiving of a SMS text to switch on and off the internal LED.
Remember that every time the module is is powered up, it loses the 1st message send to it for some reason,
in stead of the message it sends the date and time like this, "16/02/09,13:32:44+04"
I bought several modules, and gues what, all had differend baudrates.
So if there is no response from the module, first try another baudrate before something else.
You can easely set the baudrate to your needs trough an AT command and then save the configuration.

Be aware of the VCC of the module, the datasheet says max 4,2 volt, i dont know if you damage the module
by connecting it to 5 volt. I use a cheap step down converter with display from AliExpress
Futhermore, the input level on the RX/TX datalines is 3,3 volt, you have to use a levelconverter.
Also make sure that the data connections between Arduino and M590 are crosswired, so connect
RX Arduino to TX Module and TX Arduino to RX Module.

This sketch is totaly without any copyright use it as you like.
I used a Mega2560 TX2 / RX2 but u can use any other arduino with only one serial port
if you dont use the serial monitor, or use softserial on a low baudrate.

Jay Brad, The Netherlands 10-02-2016

*/

#include <Arduino.h>
#include <SoftwareSerial.h>

SoftwareSerial Serial2(9,10); // ontvangst op pin 9 en zenden op pin 10


int inByte = 0; // Incoming byte from the M590 module
String Message = ""; // String to hold and build the incoming characters.
int ledPin = 13; // Internal LED is connected to pin 13

int vrijRam () { // For testing only Remove if you like.
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

int ReadChar()
{
while (!Serial2.available()) ;
return Serial2.read();
}


void setup()

{
Serial2.begin(19200); // Set the baudrate of the GSM/GPRS Module.
Serial.begin(9600); // Set the baudrate of the serial monitor, start serial port at 9600 bps


pinMode(ledPin, OUTPUT); // Set pin 13 as output, so we can switch on and off the internal led.

delay(1000);

Serial.println("Example of receiving a SMS txt on a M590 Neoway GSM Module. ");
Serial.println("By Jay Brad !! 02-02-2016");
Serial.println("");
Serial.println("Wacht 10 seconden zodat de module de tijd heeft om zich aan te melden bij het netwerk.");
delay(10000);

Serial2.print("AT+CMGF=1\n\r"); // Set the module message mode, set either at 0 or 1 : 0 = PDU / 1 = Text mode.
delay(1000);
Serial2.print("AT+CSCS=\"GSM\"\r"); // Set the character sets : “GSM” = default alphabet (GSM03.38.6.2.1)
delay(1000);

Serial2.print("AT+CNMI=2,2,0,0,0\n\r"); // Set message indication Format, AT+CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,<bfr>]]]]]
// Where <mode> = 2: under On-line State, message indication code is cashed in module. When
// processing released, output indication code through serial port. Under its state,
// display indication code on terminal equipment directly.
// Where <mt> = 1: the message content is not displayed directly but storaged.
// Where <mt> = 2: the message content is displayed directly but not storaged.

delay(1000);
Serial2.print("AT+CMGD=1,4\n\r"); // Delete all messages from the current storage.
delay(1000);
}



void loop()

{

Message = "";

int count = 0; // Receive 4 times a '"' character before we can go on.
do
{
if (ReadChar() == '"')
count++;
}
while (count < 4);



inByte = ReadChar(); // Receive another two characters before we can read the actual message.
inByte = ReadChar(); // Read the character, but do nothing with it.




while(1) { // The actual message, read and append to message until a \r
inByte = ReadChar();

if (inByte == '\r')
break;
else
Message += char(inByte);

}

Check_Message(Message); // What can we do with the received message ??
}





void Check_Message(String M) // Here we can control things depending on the message M.
{
if (M == "L1 on") // The Message M is a command to switch the light on.
{
Serial.println ("Internal LED is turned on."); // Do something.
digitalWrite(ledPin, HIGH);
}

if (M == "L1 of") // The Message M is a command to switch the light off.
{
Serial.println ("Internal LED is turned off."); // Do something.
digitalWrite(ledPin, LOW);
}


if (M != "") // If the Message M is not a command but a Message or a unknown command.
{
Serial.println (M); // Then print the Message or the unknown command.
}

M = ""; // Clear the Command M.

Serial.print("Vrij geheugen is : " + String(vrijRam()) + " : "); // For testing only Remove if you like.
Serial.println(vrijRam()); // For testing only Remove if you like.

}


Hij compileert goed. Ik heb geen module hier dus kan niet voor je testen.

m590 aansluiten op pinnen 9 (=RX) en 10 (=TX). GNDs doorverbinden van de module en de arduino. Verder geen idee over die module. Die ken ik niet.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 2
Geregistreerd: 04 Apr 2016, 12:44

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor henk2 » 04 Apr 2016, 15:01

eerst maar vriendelijk bedankt voor de snelle service.
het is bij mij nu zo, compueleren en uploaden gaat goed.
ik krijg nu op de monitor volgende
Example of receiving a SMS a M590 Neoway GSM Module.
By Jay Brad !! 02-02-2016

wacht 10 seconden zodat de module de tijd heeft om zich aan te melden bij het netwerk.

Hoe kan ik nu de led aan en uit schakelen, moeten door speciale codes worden ingetoest.
Verder heb ik met een telefoon naar de module Neoway gebeld en hoor dan dit nummer is niet bereikbaar!
als ik de sim kaart in mijn handy doe is deze wel bereikbaar ??
wat doe ik nog verkeerd?
mvg henk arends

Gebruikers-avatar
Berichten: 5043
Geregistreerd: 13 Mei 2013, 20:57
Woonplaats: Heemskerk

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor nicoverduin » 04 Apr 2016, 18:10

Zoals ik al eerder zei. Geen idee. Ik ken dat ding verder niet. Daar zul je iets van een handleiding eerst voor moeten lezen. FF zoeken, downloaden en lezen. Mogelijk moet je een juiste baudrate instellen voor dat ding. HEt moet 19200 worden. Mogelijk de RX/TX draden naar de GSM omdraaien.
Samenvattend.... lees de handleiding of google ervoor op het web.
Handleidingen zat. Daarnaast zou ik ff lezen over de level compatibiliteit. Kennelijk werkt het op 3.3V en moet je level conversie doen. Ik zou zeker ff googelen op "Arduino neoway m590" en eens goed doornemen voordat de module evt. uitfikt.
Docent HBO Technische Informatica, Embedded ontwikkelaar & elektronicus
http://www.verelec.nl

Berichten: 12
Geregistreerd: 08 Mei 2017, 20:38

Re: Via SMS commando's aan uw Arduino geven.

Berichtdoor JDD » 09 Mei 2017, 21:46

Misschien even voor de duidelijkheid.

In de NEOWAY M590 module moet een SIM kaart geplaatst worden om aan het GSM netwerk verbonden te worden.

Terug naar Afgeronde projecten

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 8 gasten