I am using the hardware serial ports of Atmega 328 to connect to a GPS module . A GSM SIM900 module is connected via Software serial . Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports? Both my module and the Serial window is set to 9600 bps baud rate . Also I want to read the GSM responses from the Software serial and print the same in the Serial window for debugging. Is this possible?
-
I am using the following statements for the latter function:Vj1989– Vj19892017年06月02日 17:25:22 +00:00Commented Jun 2, 2017 at 17:25
-
I am using the following statements for printing the GSM responses : Serial.print (softserial.read()) . Is this possible while I am connecting GPS module to the hardware serial ports?Vj1989– Vj19892017年06月02日 17:31:24 +00:00Commented Jun 2, 2017 at 17:31
-
You can edit your question. No need to add additional info into the comments.gre_gor– gre_gor2017年06月02日 17:40:52 +00:00Commented Jun 2, 2017 at 17:40
2 Answers 2
Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports?
Yes, that works. If you connect the Arduino TX pin 1 to the GPS RX, then everything you print to Serial goes to both the Serial Monitor window and the GPS device.
This works, because:
- It's ok if you see the GPS configuration commands (if any) on the Serial Monitor window. Your debug prints will appear after them.
- The GPS device ignores anything that doesn't start with a '$' character; it ignores all your debug prints.
-
Just make sure the debug information never includes a
$
at the start!Gerben– Gerben2017年06月02日 18:54:00 +00:00Commented Jun 2, 2017 at 18:54 -
1If you don't ever need to send anything to the GPS module then you don't need to connect the Arduino's TX pin to it.Majenko– Majenko2017年06月02日 19:52:04 +00:00Commented Jun 2, 2017 at 19:52
-
@ Gerben .. Thanks.. @ Majenko .. will it do any harm if the pins are connected? My code is using only the commands to read from the gps. What are the possible data / commands that can be sent to the gps other than these?Vj1989– Vj19892017年06月03日 04:39:23 +00:00Commented Jun 3, 2017 at 4:39
-
@Vj1989, no harm to the pins (there are resistors on board to allow this). As for other data and messages from the GPS, my NeoGPS library has a nice table here. It's the smallest, fastest, most reliable and most accurate GPS library out there. Commands that you can send to the GPS would be documented in the spec for your device.slash-dev– slash-dev2017年06月03日 15:01:26 +00:00Commented Jun 3, 2017 at 15:01
While I agree with slash-dev, I feel unless you're really struggling with pin real state, you don't really need to have both the GPS serial and UART on the same pins (unless I'm missing some point or convention, in which case please do correct me).
When I was using a GPS module (GTOP013) with an Atmega328p, I just used the SoftwareSerial library to configure some unused pins (12 and 13 I think? it's been a while) as a dedicated RX/TX lines to the GPS, whilst the atmega's RX/TX remained reserved for a USB connection. Any time I needed anything sent to or from the GPS, I had a function to handle that. Also allowed me to keep polling the lines for data from the GPS to be printed onto the Serial.Console as desired for debugging.
-
@ Zaeche .. I'm using software serial pins for a GSM device and the program is not working when GPS is also connected to another set of Software serial pins. That's the reason why I'm using hardware serial ports for GPS.Vj1989– Vj19892017年06月03日 04:32:48 +00:00Commented Jun 3, 2017 at 4:32
-
Ah, I understand--thanks for clearing that up. I assume you'd prefer to Rx/Tx from the GSM and GPS simultaneously, as well as being able to debug using the hardware serial (thus, 1 hardware serial port + 2 software serial port). As per this, serial ports can't be heard in tandem so I see why you had to reuse the hardware port for the GPS as well (the Mega has two hardware ports but honestly isn't as portable as the 328p).Zaeche– Zaeche2017年06月03日 04:45:21 +00:00Commented Jun 3, 2017 at 4:45