Reading serial from a laser mic

TolpuddleSartre:
You're using software serial.

Arduino says 57600 is the upper limit. I will try a lower number anyway.

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

How's the buffering code coming along?

Yes, I noticed. Dropping the speed to 9600 for S&G's. How would you suggest I code a buffer?

sspence65:
How would you suggest I code a buffer?

An array of, say 32 characters, fill it, then print it.

Arduino says 57600 is the upper limit

I wouldn't trust that number, if you're doing simultaneous printing, which you are.

I dropped it down to 9600. I have a repeating 0 4B FF 7D 0 4B FF 7D 0 etc ....

It's not looking good, is it?
Is that with the buffering code?

I think you may need an inversion. Does the software serial support that?

is this (buffer) what you are referring to?

char string[32];
char byteRead;

int availableBytes = mySerial.available();
for(int i=0; i<availableBytes; i++)
{
   string[i] = mySerial.read();
   string[i+1] = '\0'; // Append a null
}

sspence65:
is this (buffer) what you are referring to?

I don't know - you're the one writing the snippets.
(I hope available() never returns 32)

sspence65:
2. numbers change when I add more height, and the polarity is set according to the datasheet. Tx - Rx, Rx to Tx.

The fact that your output changes to different inexplicable numbers when you change the input is not exactly a resounding endorsement of your setup. My point was that RS422 uses differential signaling. Have you tried reversing the "+" and "-" inputs to the RS422 --> Serial TTL converter?

Also, post a link to the converter itself.

Try inverse logic:

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

Wiring and pinouts:

micro-epsilon:

pin 8 (T-) to rs422 R-
pin 7 (R-) to rs422 T-
pin 21 (T+) to rs422 R+
pin 20 (R+) to rs422 T+
pin 22 (GND) to rs422 gnd

RS422 / TTL:
VCC to arduino 5v
GND to arduino GND
TX to arduino D4
RX to arduino D3

picture and micro epsolin wiring spec attached.

microepsilonlasermic-pinout.pdf (98.9 KB)

Did you try the inversion mentioned in reply 28 (and earlier)?

TolpuddleSartre:
Did you try the inversion mentioned in reply 28 (and earlier)?

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

Does not compile. "inverse_logic not declared in this scope."

{face-palm}

TolpuddleSartre:
{face-palm}

That code line was from uxomm's post. If uxomm did not mean me to use that specific line of code, why post it?

Maybe uxomm meant:

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

SoftwareSerial mySerial(4, 3,  1);   // RX, TX, inverse_logic=true

changed the repeating hex I'm displaying, but still no 09 or 0D.

How should I code the buffer previously mentioned?

changed the repeating hex I'm displaying

But you're not sharing?

How should I code the buffer previously mentioned?

As previously directed.

TolpuddleSartre:
But you’re not sharing?
As previously directed.

F3 4A 42 FF 63 21 82 (repeats)

I was not previously directed how to create and stuff a buffer. If you could give me a working example I’d be grateful. Obviously if I knew how to do this I would not be asking, so some direction with less snark would be appreciated.

It’s a bit of a silly request, asking for a “working example”, because, obviously, I don’t have your hardware.

I’m also not sure what “snark” is, apart from being something you hunt.
It doesn’t sound very nice though.

The following code is uncompiled, so obviously also untested, and comes with no warranties whatsoever.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 3);
const int BUFFER_LEN = 32;

void setup() 
{
  Serial.begin(38400);
  mySerial.begin(38400); // YOUR CONFIGURED LINE SPEED HERE
  Serial.println(F("Read"));
}

void loop() 
{
  char buffer [BUFFER_LEN];
  int index = 0;
  while (index < BUFFER_LEN)
  {
    while (mySerial.available() == 0)	{}
    buffer [index++] = mySerial.read();
  }

  for (int i = 0; i < BUFFER_LEN; i++)
  {
    if (buffer [i] < 16) 
      Serial.print ('0');
    Serial.print((int)buffer [i], HEX);
    Serial.print (' ');
  }
  Serial.println ();
}

I want to help here, and I've looked at this thread many times.

Where I am hung up is that I do not see any posts of data that match the protocol documented by microepsilon.

I am not trying to be snarky...

In both the ascii and binary outputs, it only documents, to my understanding, a multi-segment operating mode.

In both output methods, there is documented a quintet of numbers for each segment.

You have a quintet of numbers, which repeat, leading me to assume this is a single-segment setup, although I am unsure what a segment is...

In ascii mode, I would expect each number in the quintet should to be between 48 and 57.

In binary mode, maybe you have a 5-segment setup, but the leading bits do not match both the high byte and low byte.

Until the data received matches the protocol, decoding it will be a mystery to me.

implementing a serial buffer, I now have something that looks like what is displayed on the epsilon screen, sort of. I’m using single segment, ascii.

This just in …
12765
12765

the uE display actually says +0.2965’

#include <SoftwareSerial.h>

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

const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data

boolean newData = false;

void setup() {
  // Open serial communications 
  Serial.begin(9600);

  Serial.println("Hello, LaserMic!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  
  
}



void loop() {
    recvWithEndMarker();
    showNewData();
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '13';
    char rc;
    
    while (mySerial.available() > 0 && newData == false) {
        rc = mySerial.read();

        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}