Reading serial from a laser mic

I have an micro-epsilon laser micrometer. I'm attempting to read the serial output. It's rs422, and I have a rs422 to ttl adapter connected to an Arduino Nano using SoftSerial.

laser mic is set to ASCII, 38400, 8N1.

with the attached code I'm reading a repeating series of numbers on the serial monitor:

0 103 179 86 118 214 191 191 191 191 191 229 (repeats)

when the laser mic display is showing 0.2963"

I would like to see something like 2963 or similar in the serial monitor :slight_smile:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 3); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(38400);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(38400);
  Serial.println("Hello, LaserMic!");
}


void loop() {
    if (mySerial.available() > 0) {
        int ch = mySerial.read();
        // show the byte on serial monitor
        Serial.println(ch, DEC);
    }
}

I've attached the appropriate 2 pages of the manual covering the data specification. I would love some ideas to try.

microepsilonlasermic.pdf (125 KB)

sspence65:

int ch = mySerial.read();

Serial.println(ch, DEC);

change int to char.
DEC is redundant

Have you downloaded the serial protocol specification for the device?

Have you downloaded the serial protocol specification for the device?

The serial specification was attached to my post.

ASCII format
Twelve characters are always output as a minimum with the first five figures as standard
corresponding to the digital value of the measurement and being continuously output.

Perehama:
change int to char.
DEC is redundant

char ch = mySerial.read();

Serial.println(ch);

prints repeating backwards question marks

It's simpler to print the values in hex, rather than decimal - it will help you follow the values more easily.

int ch = mySerial.read();

Serial.println(ch, HEX);

The operator needs to see the actual micrometer reading in inches and MM.

sspence65:
The operator needs to see the actual micrometer reading in inches and MM.

I know that - I'm trying to help you to decode the serial stream. That's easier in hex than it is in decimal.
(they're "mm", not "MM")

sspence65:

char ch = mySerial.read();

Serial.println(ch);




prints repeating backwards question marks

In the "options menu" of the datasheet, one can select binary or ascii output. As I don't have a laser, I can't try the code myself... leaving the code alone (with char instead of int), have you tried playing with the options to see how they affect what is received by the Arduino?
In ASCII mode, you should see 5 numerals, tab, 5 numerals
It will be a number between 0 and 65535 with 65520 being the top measurement and the upper numbers being error codes.
If you see 5 numbers on the serial monitor repeated, instead of question marks or other stuff, you are reading the data correctly...
You will need to convert the ascii into number values by subtracting 48 and multiplying by the place value... then add those to an unsigned int...
once you have them stored in the unsigned int, you can perform the calculation to the float you want...

float measuredValue = unsignedIntValue * 40.824 / 65519 - 0.4204872

The closest I can get is 0.346" with those numbers (0x39c0, assuming binary, not ASCII protocol), but I'm a bit confused about the second, third and fourth triplets.

Rather than printing the numbers as you receive them, can you buffer them and then print?

(The protocol definition is a bit confusing - it refers to "DV", then uses "DW", and doesn't explain what "seg 1..4" refer to)

Quick / simple things to check:

  1. Lower the baud rate
  2. Swap RS422 polarity

TolpuddleSartre:
I know that - I'm trying to help you to decode the serial stream. That's easier in hex than it is in decimal.
(they're "mm", not "MM")

ok, cool. and yess, knew it was mm :slight_smile:

Perehama:
In the "options menu" of the datasheet, one can select binary or ascii output. As I don't have a laser, I can't try the code myself... leaving the code alone (with char instead of int), have you tried playing with the options to see how they affect what is received by the Arduino?
In ASCII mode, you should see 5 numerals, tab, 5 numerals
It will be a number between 0 and 65535 with 65520 being the top measurement and the upper numbers being error codes.
If you see 5 numbers on the serial monitor repeated, instead of question marks or other stuff, you are reading the data correctly...
You will need to convert the ascii into number values by subtracting 48 and multiplying by the place value... then add those to an unsigned int...
once you have them stored in the unsigned int, you can perform the calculation to the float you want...

float measuredValue = unsignedIntValue * 40.824 / 65519 - 0.4204872

using int I get numbers, using char I get reverse question marks. It looks like the 0 is the stop character, so I need to look for a zero, grab the next 5 readings, and start again at the next zero.

Which protocol have you got selected?
I've been assuming binary.

(I don't believe @Perehama' interpretation is correct)

sspence65:
ok, cool. and yess, knew it was mm :slight_smile:

TolpuddleSartre:
It's simpler to print the values in hex, rather than decimal - it will help you follow the values more easily.

int ch = mySerial.read();

Serial.println(ch, HEX);

I get repeating combinations of

0 67 B3 56 D6 ED BF BF BF BF BF E5 with .2968 on the display

and

0 B3 F6 D6 16 D6 BF BF BF BF BF E5 with .4990 on the display

TolpuddleSartre:
Which protocol have you got selected?
I've been assuming binary.

(I don't believe @Perehama' interpretation is correct)

I mentioned it was set for ASCII, not Binary.

gfvalvo:
Quick / simple things to check:

  1. Lower the baud rate
  2. Swap RS422 polarity
  1. what is wrong with 38400? lower data rate means missed changes, but I don't need fast changes.
  2. numbers change when I add more height, and the polarity is set according to the datasheet. Tx - Rx, Rx to Tx.

sspence65:
what is wrong with 38400?

Read about the upper limit on baud rate for the software serial library you are using.

  1. what is wrong with 38400? l

You're using software serial.

sspence65:
I mentioned it was set for ASCII, not Binary.

You'll have noticed that you're seeing neither TAB, not CR.

How's the buffering code coming along?