Problem connecting a NMEA Sensor to an ESP32

Hi there,
For a school project I have to connect a receiver a CV7 sensor from LCJ Sensor to an ESP32, since the sensor uses the NMEA0183 protocol, I first tested on my computer with an RS232 to USB adapter using only the 0v and NMEA+ OUT of the sensor, and I receive without problem the data on PuTTY, adding a RS422 converter (NMEA +/-) to TTL, and when I test on the computer I find the same data, but when I use on the ESP I have random characters, I tested several assembly, but I did not succeed in displaying the data thanks to the ESP. I conclude that there's an extra component on my computer that needs to be able to get the data or that my code isn't good, but I've tested ten or so shared codes online and it's the same result every time.

Here is a code I tested:

#include <SoftwareSerial.h>

int incByte = 0;

#define MYPORT_TX 33
#define MYPORT_RX 34

EspSoftwareSerial::UART mySerial;

void setup() {
  Serial.begin(4800);
  Serial.println("Hello World !");

  mySerial.begin(4800, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
}

void loop() {
  while (mySerial.available() > 0) {
    incByte = mySerial.read();
    Serial.print((char) incByte);
    Serial.print(" ");
    Serial.print(incByte);

    Serial.print("\n");
  }
}

Equipment:
Sensor + Receiver: https://lcjcapteurs.com/wp-content/uploads/2021/03/LCJ-CAPTEURS-Manuel-d-utilisation-CV7-FR-18012021.pdf
ESP32: ESP32 board with 150Mbps 4G LTE modem also supports RS485, CAN Bus, and relay expansion - CNX Software
RS422 to TTL: https://amzn.eu/d/0HVv2dC
Voltage booster: https://amzn.eu/d/0PULb1u


I had to Google that because I was clueless what it meant. I understand it's an ultrasonic wind sensor: CV7 - Ultrasonic wind sensor - LCJ Capteurs

I admit to having Googled that, too. Looks pretty straightforward, though. NMEA 0183 - Wikipedia
The question still is what command set your particular sensor works with, since the protocol pretty much boils down to "ASCII over UART 96008N1" and a couple of reserved characters. I leafed through the 'datasheet' of the sensor briefly, but it doesn't seem to provide much clues. Anyway, I assume you know how to find your way through this part...

Have you tried 9600bps instead? See note above. It's pretty much the only thing we do know for sure!

Thanks for adding the schematic; I see you feed the sensor from the 3.3V of the ESP32 board. I wouldn't do that. Instead, connect the IN+ of the DC-DC step up converter to the 5V of your ESP32 board, which comes from USB. This has a bit more capacity and efficiency will be better overall.

Connect the Vcc of your RS422 converter to the 3.3V of your ESP board, assuming it's intended to survive +/-6V on the RS422 side while being powered with 3.3V. I assume it's OK with that (it still appears to work, after all), but the info on the Amazon ad doesn't seem to be conclusive.

Hi, thanks for your response, I'll try to use the 5v, and no it's not 9600bps, it's 4800 as specified in the documentation, and when I have tried with my PC it worked with 4800bps. And the RS422 output NMEA+ 0v/3v and NMEA- 3v/0v

My apologies, I missed that. If it worked with 4800bps on the computer, it should work at the same rate on the ESP32.

If you have a second Arduino board or perhaps an USB-UART bridge, can you test if you can receive data at 4800 8N1 through your SoftwareSerial? This removes the possibly complicating factor of the 422 interface.

If you have none of those devices, you could connect a wire from the regular UART RX to your SoftwareSerial RX and then send some text from the Arduino Serial Monitor to the ESP32 and see if it's picked up correctly by the SoftwareSerial.

Btw, concerning SoftwareSerial - why use it at all? The ESP32 has 3 hardware UARTs if memory serves. UART0 is used for the USB/computer communication and sketch programming. UART1 might be used for flash (not sure), but UART2 should be free to use. You can use it just like Serial, the only difference is that it's called Serial2. Give it a try; it's probably more robust and reliable than SoftwareSerial (although it may not necessarily fix this particular issue).

Power the sensor with a separate 12V power supply, and don't forget to connect all the grounds.

The boost converter is very likely overloading the 3.3V output of the ESP32, or at least introducing a lot of electrical noise into the 3.3V supply.

I thought about this, but the sensor's spec sheet says it consumes max 40mA. At 3.3V this would be 150mA. Give or take some overhead for the converter, max current draw would be 200mA and I don't expect this to be a problem - even if it's not optimal (see my suggestion to step up from 5VDC instead).

I do. It is not a good idea.

1 Like

Hi, I've already tried with a separate 12v power supply, but i get the same problem, the data I receive is like randomized, and with this setup, I can connect directly to my computer using a RS232 to USB and it works, I can see the right data on PuTTY

In that case, any ESP32 board would be inherently unstable. Current draw with WiFi easily exceeds 300mA and will be erratic.

Look, I agree that it's bad practice to step up 3.3V to 12V in this case (or pretty much any case), but fixing this is not likely to fix the actual problem.

Good test. Something else is wrong.

See if switching over to hardware UART with Serial2 makes a difference, and give the other tests I suggested a try. It'll help to know if this is something that somehow relates to the 422 interface or if it's happening on the UART side of your ESP32.

I'm gonna try with an Arduino, but I'm not sure it will work, I've already tried a while ago, and got the same problem (Yes I'm on this project for a year now :joy:), and I need to use a SoftwareSerial because the last Serial is used for the integrated SIM module.

Please explain exactly what you did to have "the computer" read the TTL level data, and get the expected result. Also, post a link to the RS422 converter module.


Serial2 is GPIO16 and GPIO17, but I dont have access to them

You can init Serial2 with whatever pins you choose, AFAIK.

I've connected a RS232 to USB adapter, with the RX of the adapter to the NMEA+ of the sensor (without the RS422 converter) and I done the same but the TXD of the RS422 to the RX of the adapter, and both works on my PC.

https://amzn.eu/d/0HVv2dC

Using HardwareSerial ? Already tried, no changes

And what would that be?

You mean you tried what exactly? Can you show the sketch + output you get this way?

I did a brief check but I can see only one hardware UART being used by the onboard GSM modem; the other two should be free. And even if they're not, for testing you can use them anyway with the GPIOs of your choice.

This one: https://amzn.eu/d/4OvnJ32