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:
I would like to see something like 2963 or similar in the serial monitor
#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.
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.
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...
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)
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")
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...
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.