Serial monitor CR and NL

Hi I apologise in advance if this is a bit of a dummy question but I am learning from it. My GPS module requires CR and LF line feed (NL?) at the end of the PMTK command and it works great when I select both CR NL and send my commands from the serial monitor. However I wish to send this CR NL from my micro controller and so naturally tried \r\n at the end of the command. BUT this does not appear to work so obviously the serial monitor is inserting something different but I cant work out what or how i would see this as i suspect the seril monitor will remove these characters. I have also tried the HEX characters \x0a but no joy. Any ideas from someone smarter than me and TIA. Tim

What micro controller?

Post your code.

Sorry should have said its an ESP8266 D1 mini and the GPS module is a Quectel L96. Not sure posting the code is relevant as the GPS module just needs a command with (CR><LF) at the end. Thanks.

In short i just need to replicate what the serial monitor is adding at the end when i select both CR and NL from the little drop down menu box.

Please allow the helpers here to make that evaluation.

1 Like

How can we tell that you tried it correctly when we can't see what you tried? If you did it correctly it should have worked. If you show us the code that works (copying between Serial and whatever serial port the GPS is on) and the code that doesn't (sending to whatever serial port the GPS is on) we might be able to spot a difference you didn't account for.

are you sure characters are are being transmitted to the modem?
this is a simple program I use as an initial test to check modems respond to AT commands

// SIM900 GSM modem test - working 13 March 2022

// note problems with lost character if Serial run at 115200

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7, 8); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  while (!Serial) {  }
  Serial.println("SIM900 test!");
  // set the data rate for the SoftwareSerial port

void loop() { // run over and over
  if (mySerial.available()) {
  while (Serial.available()) {
    char ch;

ypu may need to modify the baudrate and the SoftwareSerial IO pins to suit your ESP8266
characters typed into serial monitor are sent to the modem and characters received from modem are displayed on the serial monitor
this is a run using a Quectel EC21 modem

+CSQ: 12,99

if you get no response check the voltage on the serial Tx and Rx lines - it should be 3.3V
if you have an oscilloscope check you can see signals on the Tx when you enter characters

HI John thanks - I send the command via the serial monitor with both CR and NL enabled and the module responds correctly. When I try from the MC with GPSserial.print("$PMTK161,0*28\r\n"); it does not seem to work. I wonder if its to do with using software serial hmmm.

Thanks horace i will try that and let you know.

We can't see your use of SoftwareSerial so it is hard to provide an informed opinion. If you want an uninformed opinion: there is probably a mistake in the wiring or the sketch.

1 Like

Hi Guys

Thanks for all the suggestions on here and the helpful comments it was in the end as john guessed a wiring fault. I apologise for any time wasted but did learn some stuff from the exercise.



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.