I am trying to hook up to an A9G Pudding GSM board via an Arduino. I intend to use the onboard UART chip to facilitate TTL-UART conversion between PC and A9G.
I have initiated a software serial instance and using this to pass communication to/from the A9G and the Arduino.
Here's my code. However, all I'm getting is gibberish stuff. I've checked my connections, the link seems to exist but the encoding is mismatched. I'm communicating with the A9G at 115200 and my emulated serial is at 9600.
Could this be an issue?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600); // Monitor baud rate
mySerial.begin(57600); // Set to detected baud rate
Serial.println("A9G Module Communication Test");
// Send AT command with carriage return and line feed
mySerial.print("AT\r\n");
delay(1000); // Wait for response
}
void loop() {
// Check if data is available from the A9G module
if (mySerial.available()) {
// Read the data from the A9G module
while (mySerial.available()) {
char c = mySerial.read();
Serial.write(c); // Send it to the Serial Monitor
}
}
// Check if data is available from the Serial Monitor
if (Serial.available()) {
// Read the data from the Serial Monitor
while (Serial.available()) {
char c = Serial.read();
mySerial.write(c); // Send it to the A9G module
}
}
}
Here's the output on the serial monitor.
-
Type "AT" and press "Send" from your Serial Monitor, what do you get?hcheung– hcheung05/28/2024 13:32:51Commented May 28, 2024 at 13:32
-
Try it with mySerial.begin(115200); since that is the default baud rtate of the A9G.Lee-xp– Lee-xp05/28/2024 15:07:48Commented May 28, 2024 at 15:07
-
please do not write in all capitals ... it indicates SHOUTING which is considered impolite ... use the edit button to correct the titlejsotola– jsotola05/28/2024 16:56:13Commented May 28, 2024 at 16:56
-
1please do not post pictures of text ... post the text instead... format as code for readabilityjsotola– jsotola05/28/2024 16:58:10Commented May 28, 2024 at 16:58
1 Answer 1
You can edit your code like this.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600); // Monitor baud rate to match A9G
mySerial.begin(115200); // Set to A9G baud rate
Serial.println("A9G Module Communication Test");
// Send AT command with carriage return and line feed
mySerial.print("AT\r\n");
delay(1000); // Wait for response
}
void loop() {
// Check if data is available from the A9G module
if (mySerial.available()) {
// Read the data from the A9G module
while (mySerial.available()) {
char c = mySerial.read();
Serial.write(c); // Send it to the Serial Monitor
}
}
// Check if data is available from the Serial Monitor
if (Serial.available()) {
// Read the data from the Serial Monitor
while (Serial.available()) {
char c = Serial.read();
mySerial.write(c); // Send it to the A9G module
}
}
}
-
-
My serial baud rate has been changed from 57600 to 115200.tepalia– tepalia06/07/2024 14:21:05Commented Jun 7, 2024 at 14:21
-
and why is that the right value. please write an answer without the sketch if only the baud rate is changed.06/07/2024 16:31:04Commented Jun 7, 2024 at 16:31
-
The serial monitor is showing garbage value. That's why I thought, the defined baud rate for A9G might not be correct.tepalia– tepalia06/08/2024 15:55:24Commented Jun 8, 2024 at 15:55
-
but that should be in your answer. not a copy of the sketch. arduino.stackexchange.com/help/how-to-answer06/08/2024 17:06:57Commented Jun 8, 2024 at 17:06
Explore related questions
See similar questions with these tags.