Fairly new to Arduino. I am trying to send commands to the Grove Air530 GPS module to either adjust the baud rate of it or to disable unnecessary output variables. I am unable to do either.
I am able to read GPS data from it via Serial correctly, however I am trying to send the same data over Bluetooth using the HC-06 module. The data being sent over is gibberish so I was suspecting it to be a baud rate issue. I am able to adjust the baud rate of the HC-06 but not for the Air530.
I have attached some code that I have tried based on an earlier discussion on the Arduino threads but it has made absolutely no difference. Please advise where I could have gone wrong or if I need a completely different approach.
Thank you
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(4, 5);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count=0; // counter for buffer array
void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}
void setsatellites(){
String cmd = "$PGKC242,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
cmd = calchecksum(cmd);
sendcmd(cmd);
}
String calchecksum(String cmd)
{
uint8_t checksum=cmd[1];
char temp[5];
for(int i=2;i<cmd.length();i++)
{
checksum^=cmd[i];
}
memset(temp,0,5);
sprintf(temp, "*%02X\r\n", checksum);
cmd += temp;
return cmd;
}
void sendcmd(String cmd){
while(SoftSerial.available())
{
SoftSerial.readStringUntil('\n');
}
SoftSerial.print(cmd);
}
//The loop below is for reading the GPS data and it functions correctly
void loop()
{
if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++]=SoftSerial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
}
void clearBufferArray() // function to clear buffer array
{
for (int j=0; j<count;j++)
{
buffer[j]=NULL;
} // clear all index of array with command NULL
Which Arduino are You using?
What does the datasheet and/or application notes say for the GPS and commanding it?
Please post a link to the GPS datasheet..
Schematics might be valuable.
The Grove Air 530 only has a datasheet in Chinese although one person was kind enough to translate it into English. The datasheet/manual only contains the commands that can be used to send and other useful information on how to interpret the data received by the GPS module but no instruction on how to send it. The same person had also posted some code on how he managed to send instructions to the GPS module. Following his steps is what I used to produce the code I attached below.
Here is a link for the translated version of the GPS module. It also contains the schematics.
I was under the impression that the void sendcmd is used to write the command to the module. How would you go about sending the string to the module? I have also attempted to send the command directly via serial but to no avail. Please advise on the best approach for this.
This was the only GPS chip that my university had provided me with for my project so I figured it was the quickest way to get started with my project. Before deciding to purchase another GPS module I wanted to tinker with the Air530 first.
I have called sendcmd under setsatellites. Shouldn't this send the command after the checksum string has completed and returned the cmd? How would you approach this? Please let me know if I need to call the sendcmd elsewhere to accomplish this.
I have gone by a translated manual for the module and formatted the command that way. I have also tried some other variations that I noticed in another thread discussing this module but none of them have worked.
A primer for Arduino code: setup() is called once at the start of the sketch. loop() is called repeatedly infinitely. All code not called from one of these two routines won't be executed (generally speaking).
Thank you for highlighting this to me. I see your point, I should have called in setsatellites within either the setup or loop.
I have called setsatellites in both the setup and loop separately. When called in setup nothing happens again and when called within the loop the data I receive from the GPS gets corrupted into random characters.
Despite now running the command lines I am unable to change the parameters of the module. Have you got any more suggestions?
void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
setsatellites();
}
Without the Arduino mediator passing the command how would directly connecting it serially to my PC show that the command has passed? I do use Tera Term to observe the output of the GPS module, but this is via the Arduino COM port. In some occasions when I call in the command line in the loop it causes the data to get corrupted.
You connect the TX pin from the Arduino to the RX pin on a USB-Serial adapter. This tap arrangement will allow you to see the actual command being sent to the GPS.
Ah, I see what you mean. Connect the GPS module via both the Arduino and USB-Serial adapter to observe the command being sent. I could definitely try that out but will need to look into obtaining the serial adapter. If I manage to find one, I shall try this and get back to you.