Go Down

Topic: A6 GPRS and sim lock (Read 516 times) previous topic - next topic

Diedhert

Hi all

I just received my A6 GPRS module. I inserted a sim code and tried to send an SMS.

I found some scripts on the internet. They ran okay.

When I tried to send an sms, I got CME 58 error. I found out that this was due to a pin lock on the sim card.
Using AT+CPIN=XXXX (where XXXX was the sim code) in the serial monitor, it gave some output I didn't understand, but however, thereafter I could send an sms-message.

Is it possible to 'run' that code without typing it in the serial monitor ? If yes, how should I enter this as a command (as AT+CPIN=xxxx is not recognized as an Arduino commando).

The code I am using is written below.

Thanks for any help.


Quote
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);  // TX-Pin11, RX-Pin10
void updateSerial()
{
  delay(2000);
  while (Serial.available()) {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }

}

void setup()
{
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop()
{
  mySerial.println("AT");          // Once the handshake test is successful, it will back to OK

  updateSerial();
  mySerial.println("AT+CMGF=1");   // Configuring mode is TEST, only English texts are available
  updateSerial();
  mySerial.println("AT+CMGS=\"0497249119\"");//xxxxxxxxxxx is the phone number
  updateSerial();
  mySerial.print("Dit is een test"); //text content
  updateSerial();
  mySerial.write(26);
  while(1)
  {
    if(mySerial.available())
    {
      Serial.write(mySerial.read());}//Data received by mySerial will be outputted by Serial }
    if(Serial.available())
    {
      mySerial.write(Serial.read());//Data received by Serial will be outputted by mySerial }
    }
    }
    }

pert

Is it possible to 'run' that code without typing it in the serial monitor ? If yes, how should I enter this as a command (as AT+CPIN=xxxx is not recognized as an Arduino commando).
You can print whatever you want to the A6. You are already doing that in the code you posted:
Code: [Select]
  mySerial.println("AT");          // Once the handshake test is successful, it will back to OK

  updateSerial();
  mySerial.println("AT+CMGF=1");   // Configuring mode is TEST, only English texts are available
  updateSerial();
  mySerial.println("AT+CMGS=\"0497249119\"");//xxxxxxxxxxx is the phone number

These are all AT commands you are sending from the program running on your Arduino board to the A6.

Diedhert

Hi

(I have little programming skills, so I am looking for codes, try to understand it and then to adjust it).

If I understand well, if I add a line

Quote
mySerial.println("AT+CPIN=1234") //where 1234 is the pin code
updateSerial();
the pincode should be send to the A6.


But - apologies if this is a dumb question - will this work on the "arduino+A6" solely, not connected to a computer & serial monitor ?
If I understand well ... the instruction is written to the serial monitor, and read (=send to A6) as well. So what if there is no serial monitor ?

But what command should I use to send an sms if something happens (for instance if a laser beam is interrupted, if a counter counts 100, ...) ?

If the Arduino+A6 is not connected to a computer, there is no serial monitor, so I suppose the MySerial command will not work ?
(I am just trying to understand how it is working).

Regards
Diederik

pert

if I add a line
Code: [Select]
mySerial.println("AT+CPIN=1234") //where 1234 is the pin code
You forgot the semicolon.

the pincode should be send to the A6.
Correct.

will this work on the "arduino+A6" solely, not connected to a computer & serial monitor ?
Yes.

If I understand well ... the instruction is written to the serial monitor, and read (=send to A6) as well
You don't understand well. This line:
Code: [Select]
mySerial.println("AT+CPIN=1234") //where 1234 is the pin code
writes "AT+CPIN=1234" to the software serial interface on pins 2 and 3, which your A6 is connected to. It does not write it to Serial Monitor. If the A6 returns data in response to that command, that data will be written to Serial Monitor.

If you wanted to write something to Serial Monitor, you would do it like this:
Code: [Select]
Serial.println("This is printed to Serial Monitor");



But what command should I use to send an sms if something happens (for instance if a laser beam is interrupted, if a counter counts 100, ...) ?
https://lastminuteengineers.com/a6-gsm-gprs-module-arduino-tutorial/#arduino-code-sending-sms

If the Arduino+A6 is not connected to a computer, there is no serial monitor, so I suppose the MySerial command will not work ?
It will work just fine! Why don't you give it a try? The great thing about Arduino is it's so easy to run experiments and learn from them.

Diedhert

#4
Feb 12, 2020, 04:54 pm Last Edit: Feb 12, 2020, 04:56 pm by Diedhert
Thanks for your answer. Really (truly really).

I am experimenting further.

I have still another issue.

Actually, I found two codes, from a different site.


The code below is working fine, giving nothing peculiar in the serial monitor view.


Quote
#include <SoftwareSerial.h>

//Create software serial object to communicate with A6
SoftwareSerial mySerial(3, 2); //A6 Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and A6
  mySerial.begin(9600);

  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();

  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CMGS=\"0497249119\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
  updateSerial();
  mySerial.print("Last Minute Engineers | lastminuteengineers.com"); //text content
  updateSerial();
  mySerial.write(26);
}

void loop()
{
}

void updateSerial()
{
  delay(500);
  while (Serial.available())
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available())
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}
However, this very similar code

Quote
"#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);  // TX-Pin11, RX-Pin10
void updateSerial()
{
 delay(2000);
 while (Serial.available()) {
   mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
 }
 while(mySerial.available()) {
   Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
 }

}

void setup()
{
 Serial.begin(9600);
 mySerial.begin(9600);
}

void loop()
{
 mySerial.println("AT");          // Once the handshake test is successful, it will back to OK
 updateSerial();
//  mySerial.println("AT+CPIN=1111");
//  updateSerial();
 mySerial.println("AT+CMGF=1");   // Configuring mode is TEST, only English texts are available
 updateSerial();
 mySerial.println("AT+CMGS=\"0497249119\"");//xxxxxxxxxxx is the phone number
 updateSerial();
 mySerial.print("SIM5 test"); //text content
 updateSerial();
 mySerial.write(26);
 while(1)
 {
   if(mySerial.available())
   {
     Serial.write(mySerial.read());}//Data received by mySerial will be outputted by Serial }
   if(Serial.available())
   {
     mySerial.write(Serial.read());//Data received by Serial will be outputted by mySerial }
   }
   }
   }"
Returns in the serial monitor

Quote
AT

OK
AT+CMGF=1

OK
AT+CMGS="0497249119"

> SIM5 test⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
+CMGS: 15

OK
⸮⸮
I do receive the sms (so far so good), but I am quite confused with the inverted question marks.


When I do compare the two codes, they are very similar. Only some parts are in different order.

The procedure void updateSerial() is exactly the same, only once in the beginning and once in the end.

Main difference is in the one code the void loop is empty, and the void setup consists of the code that is in the void loop of the other one. It is followed by a while-function as well.

Is it the while-loop that generates an error ?

Regards (and once again thanks for clearing out things step by step)




Go Up