Ai-thinker A7, combining GPS and SMS code so it only require 1 TX & 1 RX pin.

Hi!

So i'm using Ai-Thinker A7 and Arduino UNO for my project to get GPS coordinates and then send it via SMS. I tested both of the codes separately, they worked fine, the coordinates appear on the serial monitor and i got the SMS.

connection for GPS:
UNO -> A7 (external power)
D11(RX) -> TX
D10(TX) -> RX
GND -> GND

connection for SMS:
UNO -> A7 (external power)
RX -> TX
TX -> RX
GND -> GND

here is the GPS code

#include <SoftwareSerial.h>

byte RX = 10;
byte TX = 11; 
SoftwareSerial *A7board = new SoftwareSerial(RX, TX); 

void print_result()
{
  Serial.print("A7 board info: ");
  while( A7board->available() != 0)
    Serial.write( A7board->read());
  Serial.println();  
}

void setup() {
  Serial.begin(115200);
  A7board->begin(115200);
  delay(200); 

  Serial.println("Send AT command");  
  A7board->println("AT");
  delay(25000);
  print_result();
  
  Serial.println("AT+GPS turn on");  
  A7board->println("AT+GPS=1");  
  delay(10000);
  print_result();
  
  Serial.println("AT+GPSRD turn on");  
  A7board->println("AT+GPSRD=1");  
  delay(10000);
  print_result();
  
}

void loop() {
  print_result();
  delay(2000);
}

here is the SMS code:

char phone_no[]="08xxxxxxxxx";

void setup() {
Serial.begin(9600);
delay(300); 

Serial.println("AT+CMGF=1");    
delay(2000);
Serial.print("AT+CMGS=\"");
Serial.print(phone_no); 
Serial.write(0x22);
Serial.write(0x0D);  
Serial.write(0x0A);  
delay(2000);
Serial.print("A7 sent message yo");
delay(500);

i noticed that these codes using a different RX & TX pins but the A7 has only 1 pin for each TX and RX, so I'm confused, how am i going to combine these codes.
I'm hoping it could either using pin 10,11 or the RX TX on the Arduino.
if it can't, please provide me with solutions.

Any kind of help would be appreciated

Which AI-thinker A7 breakout are you using or are you using the raw module ?
115200 looks rather fast for software serial.

I use an no-name A7 break out together with an STM32F103C8F (Blue Pill) which has up to 4 serial ports. Actually, I built a GPS clock. I've used a lot of ideas from the Elecrow breakout documentation which uses a Atmega32u4 (2 serial ports).

Maybe you find something here: 32u4 with A7 GPRS/GSM - Elecrow

if you are ONLY receiving from GPS AND transmitting to SMS then you could do connect it this was PROVIDED they both operate at the same baud rate:

UNO -> A7 (external power)
D11(RX) -> TX (GPS)
D10(TX) -> RX (SMS)
GND -> GND

sherzaad:
if you are ONLY receiving from GPS AND transmitting to SMS then you could do connect it this was PROVIDED they both operate at the same baud rate:

UNO -> A7 (external power)
D11(RX) -> TX (GPS)
D10(TX) -> RX (SMS)
GND -> GND

What is RX (SMS) ie which pin on the raw module ?

Anyway, the GPS-TXD pin (9600 Baud) is not required if you use the "AT+GPSRD=1" command as you have done.
Then you simply use these pins for all functions:
UART_TXD (Pin 30 on the raw module) 115200 Baud
UART_RXD (Pin 31 on the raw module) 115200 Baud

I've included the Elecrow schematic (spread over 4 pages) ant the previous link has the matching code.
The matching code is linked in the previous post

You can't have more than one instance of software serial.

If you still have a problem, maybe start by providing a link to the break out you are using.

a7-schematic.pdf (190 KB)

6v6gt:
Which AI-thinker A7 breakout are you using or are you using the raw module ?
115200 looks rather fast for software serial.

I use an no-name A7 break out together with an STM32F103C8F (Blue Pill) which has up to 4 serial ports. Actually, I built a GPS clock. I've used a lot of ideas from the Elecrow breakout documentation which uses a Atmega32u4 (2 serial ports).

Maybe you find something here: 32u4 with A7 GPRS/GSM - Elecrow

i am using A7 like this Makerfabs,Turnkey PCB Assembly Solution Provider (i didn't buy it there, just for reference), and just directly connect it to the arduino

thanks, i'll check the link

OK. That is exactly the same as I am using.
The short antenna is for GSM. The longer antenna is a WLAN antenna and is useless for GPS reception. I bought an active GPS antenna and made a hack to the board to put a 100pf capacitor in the antenna path and jumper between the 5volt pin and the capacitor/antenna connection to drive the active antenna.

6v6gt:
OK. That is exactly the same as I am using.
The short antenna is for GSM. The longer antenna is a WLAN antenna and is useless for GPS reception. I bought an active GPS antenna and made a hack to the board to put a 100pf capacitor in the antenna path and jumper between the 5volt pin and the capacitor/antenna connection to drive the active antenna.

regarding the GPS antenna, i am using the same antenna as yours(i think), as i told you it is worked, if i'm using the codes separately

will you kind enough to show me the connection between the A7 and the arduino? because from the link you've just shared it used pin 4,5,8 that i assume to turn off and on the A7 but i have no idea where to connect those pin. and to be honest it is kinda too complicated, i'm looking for something more simple.

so in conclusion so far, yes i could use, lets say pin 11 as RX and 10 as TX and connect them to UART_TXD and UART_RXD to do both GPS and SMS, yes?

The Arduino to A7 connections following the Elecrow model are:

(1) Arduino D5 -> A7 GPIO1 via 330 Ohm ( LOW POWER FUNCTION )
HIGH = Wakeup , LOW = Sleep so hold this high during normal operation

(2) Arduino D4 -> A7 RST via Logic level N channel Mosfet. (RESET FUNCTION if required)
This is optional and you can leave it disconnected. I use a IRLML0030 mosfet with a 39K pullup on the drain which is also connected to the A7 RST pin.

(3) Arduino D8 -> A7 PWR KEY via 330 Ohm (POWER UP )
Hold HIGH for about 3 seconds and then force LOW to put the module in the ON state.

Since I am using a 3 volt Arduino, I do not use the 330 Ohm resistors. At 5 volt you may not need the 39K pull up on the A7 RST pin.

so in conclusion so far, yes i could use, lets say pin 11 as RX and 10 as TX and connect them to UART_TXD and UART_RXD to do both GPS and SMS, yes?

That is how I see it. You'll need 115200 which stretches software serial. Maybe AltSoftSerial is a better choice but uses fixed pins. Ideal would be an Arduino Micro or Leonardo for ease of use with 2 hardware serial ports. If you haven't already used the Blue Pill STM32... it is good and cheap but there is a lot of fiddling around to get it first set up.

//monitor both tx and rx (2 instances of putty) on the tx and rx pins ARDUINO ONO or NANO

//working example --- iTS NOT ELEGANT BUT IT WORKS

// QUICK AND DIRTY LINEAR TEST PROGRAMME
// Sets up a single hardware UART to 9600 board for both A7 and GPS control
// setup A7 to send GPS data on Arduino hardware uart. No second software uart required
// This sends an sms to a test phone and spews out 10 seconds of
// GPS NEMA sentances back to the Arduino

void setup() {
// put your setup code here, to run once:

// initialize the serial communications:
Serial.begin(115200);
delay(10000); // wait 10 seconds to power up and wait for initial A7 115200baud stuff to subside
//
Serial.print("AT+IPR=9600"); // Sends RESET BAUDRATE to 9600 to A7 module
Serial.println(); //9600 is a nice reliable baudrate for the A7

Serial.begin(9600); // Resets arduino baud rate to 9600 Reliable Baud Rate
delay(1000);
//
Serial.print("AT"); // prints OK (gives error if reset produces garbage)
Serial.println(); // send cr/lf
delay(1000);
// IT WORKS!

//SET UP A TEST SMS

Serial.print("AT+CMGF=1"); // sets up SMS string mode
Serial.println();
delay(1000);

Serial.print("AT+CMGS="); // Sets up destination mobile (Angies)
delay(100);
// send --> AT+CMGS="0770000000" // THE DOUBLE QUOTES ARE NESECEARY HENCE A Serial.write(34) ASCII for "
Serial.write(34); // double quotation mark "
delay(100);
Serial.print("07700000000"); //Phone number (your phone number that you want to send text to!?)
delay(100);
Serial.write(34); // double quotation mark "
delay(100);

Serial.println(); //responds with a > for message entry
delay(1000);
Serial.println("This is a message from the A7 module"); // message text
Serial.write(26); //SEND A CONTROL Z!!!! NO cr/lf <---- important
delay(10000); // long wait to send SMS

}

void loop() {
// put your main code here, to run repeatedly:

Serial.print("ATI"); // replies AI THINKER
Serial.println();
delay(1000);

Serial.print("AT+GPS=1"); // Turns on GPS
Serial.println();
delay(5000);
Serial.print("AT+GPSRD=1"); // Sends NEMA to console NO NEED FOR SECOND SERIAL PORT

Serial.println();
delay(10000);
// A whole load of NEMA data is printed for 10 seconds on the test equipent /putty terminal.

Serial.print("AT+GPSRD=0"); // Turns off NEMA strings
Serial.println();
delay(2000);

Serial.print("AT"); // prints OK
Serial.println();
delay(1000);

Serial.print("AT+GSN"); // prints IMEI NUMBER
Serial.println();
delay(1000);

do other stuff, loop or stop!

Don't you think it would be reasonable to read the response of the device you are talking to?

That code is fine for talking to two devices, but it is useless for listening to two devices, and knowing which one sent data.

Serial.begin(115200);
delay(10000); // wait 10 seconds to power up and wait for initial A7 115200baud stuff to subside
//
Serial.print("AT+IPR=9600"); // Sends RESET BAUDRATE to 9600 to A7 module
Serial.println(); //9600 is a nice reliable baudrate for the A7

Serial.begin(9600); // Resets arduino baud rate to 9600 Reliable Baud Rate