UART DEC (Decimal) and String - Is it all the same when it gets transmitted

Hi,

I have a sensor module which communicates via TTL UART.
I have connected it to Serial1 of the Arduino Leonardo - I have used a voltage divider on the Arduino Tx pin to step it down to 3.3v on the high side.

Its been a bit of a struggle - The user manual is in Chinese, the seller (From alibaba) doesnt know how to use it.

Anyway, I've plugged it in and recieved a bunch of integers. I didnt know what these integers meant . I took a guess that it was Hexadecimal or decimal. Turns out the integers are DECIMAL ASCII. I converted them to the equivalent ASCII Character and they send a message:
"HW Version: 3
SN: 11112304324"

Next up, in the translated user manual (Translated on google translate), it says to take a reading send command $FR=1\r\n

I sent the following:
Serial1.print("$FR=1\r\n");

The module returns back a bunch of integers.
I translated them to text using the ASCII table, the translated text is:
Unknown cmd

Presumably this means unknown command. (This doesnt come up in the translated user manual).

I have two thoughts to try going forward:

  1. Send the command as DECIMAL? I couldnt find how to do this. Maybe it doesnt make sense. So my question to the community:
    1a. Does it make sense to convert a string to decimal and then send it through the UART? as in: Serial1.print("$FR=1\r\n",DEC) (Note this throws and error and im not sure any other way) or some command that converts string to decimal.

  2. Convert the string to equivalent ASCII DEC integers. Send the integers through?
    I'm not sure how to do this.
    Would I:
    2a. Find some command that does the conversion and then send the integers through? Noting that I have looked and didnt find the command.
    2b. Manually convert the command using the ASCII table. Then send through each integer.
    Do I send through each integer like this?
    Serial1.print("36") //$
    Serial1.print("70") //F
    Serial1.print("82") //R
    Serial1.print("61") //=
    Serial1.print("49") //1
    Serial1.print("13") // \r
    Serial1.print("10") //\n

I will try playing around some more when I get home but I think i'm misunderstanding some things about how data goes through the UART.

Thanks for any guidance and or help.

Can you show the raw data you receive.

Can you show the code you are using to interpret the incoming message? It's most likely that the outgoing message will use the same encoding.

Can you send a link to the manual you have.

That would certainly be my guess.

As for receiving a series of numbers, the problem is most likely how you are printing on the serial monitor. If those "numbers" are ASCII characters, use something like this instead (write the received characters directly to the screen).


while (Serial1.available()) Serial.write(Serial1.read());

Using this code:

void setup() {
Serial1.begin(9600);
Serial.begin(9600);
}

void loop() {
    while (Serial1.available()){
       Serial.print(Serial1.read());
       }

Serial1.print("$MSFR=3\r\n");

delay(1000);
}

I get the following returned in the serial monitor:
8511010711011111911032991091001310

If I use exact same code but change the Serial.print to Serial.write as per jremington, I get:
Unknown cmd

This is the translated document.
part1A_VM311.pdf (2.4 MB)

I'm using module VM311/VM3xx

I receive the information as per Section 3.1.1 of the manual, on startup. When I use Serial.print it throws out lots of integers.
When I use Serial.write it gives exactly as written in the manual.

Section 3.9.2 - That's where I got the command from for a single measurement.
Everytime I send:
Serial1.print("$MSFR=3\r\n");
I get "Unknown cmd" returned.

One more note: Section 3.11 mentions that when the sensor connection is not detected a 10hz periodic level signal is output. Visually, assessing, there is an onboard LED which flashes about 10hz. WHen I plug the sensor it, it changes to once flash every 3 or so seconds. I have measured the resistance of the sensor with a multimeter. It returns 3.5k ohms. Section 3.11 of the manual says it detects if resistance is between 50 ohms and 10k ohms. So it appears the sensor is being detected.

Lastly, there are other commands about resetting things to default settings Section 3.2 and 3.3 but I wasnt brave enough to do anything there in case I stuff something up.

you are transmitting the same command again and again in loop() which could be upsetting the sensor
as a simple test move the

Serial1.print("$MSFR=3\r\n");

into setup() and just display the received data in loop()

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