RS422 vs RS485 for newbie

cepics
Posts: 14
Joined: Sat Dec 08, 2018 10:13 am

RS422 vs RS485 for newbie

Postby cepics » Tue May 26, 2020 10:45 am

hi all,
I'm reading a serial line, on ESP32, with this RS422/TTL adaptor https://tse4.mm.bing.net/th?id=OIP.R140 ... Ha&pid=Api

with this code

Code: Select all

void setup() {

  Serial.begin(115200);
  delay(1000);

//              speed, mode,      rx, tx
  Serial2.begin(9600, SERIAL_8N1, 26, 32);
  delay(1000);

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

void recvBytesWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  byte startMarker = 0x7C; // "|"
  byte endMarker = 0x0A; // (LF) "/n"

  //  byte startMarker = 0x0A; // "/n"
  //  byte endMarker = 0x0D; // (CR) "/r"


  byte rb;

  while (Serial2.available() > 0 && newData == false) {
    rb = Serial2.read();

    if (recvInProgress == true) {
      if (rb != endMarker) {
        receivedBytes[ndx] = rb;
        ndx++;
        if (ndx >= numBytes) {
          ndx = numBytes - 1;
        }
      }
      else {
        receivedBytes[ndx] = '\0'; // terminate the string
        recvInProgress = false;

        numReceived = ndx;  // save the number for use when printing
        ndx = 0;
        newData = true;
      }
    }

    else if (rb == startMarker) {
      recvInProgress = true;
    }
  }
}

void showNewData() {
  if (newData == true) {

    //    Serial.print(" ... HEX Value.. ");
    for (byte n = 0; n < numReceived; n++) {
      Serial.print(receivedBytes[n], HEX);
      Serial.print(' ');

      if (receivedBytes[numReceived - 3] == 0x36 && receivedBytes[numReceived - 6] == 0x30) {
        unit = 0; // CM ARRI 60
      }

      if (receivedBytes[numReceived - 3] == 0x37 && receivedBytes[numReceived - 6] == 0x30) {
        unit = 1; //FT ARRI 70
      }

      if (unit == 0 && receivedBytes[numReceived - 6] == 0x31) {
        cm = receivedBytes[numReceived - 4] * 100 + receivedBytes[numReceived - 3] * 10 + receivedBytes[numReceived - 2];

      }
      if (unit == 1 && receivedBytes[numReceived - 6] == 0x31) {
        ft = receivedBytes[numReceived - 5] * 10 + receivedBytes[numReceived - 4];
        inc = receivedBytes[numReceived - 3] * 10 + receivedBytes[numReceived - 2];

      }
    }
    Serial.println();
    Serial.print ("cm ");
    Serial.println (cm);
    Serial.print ("ft ");
    Serial.println (ft);
    Serial.print ("inc ");
    Serial.println (inc);

    newData = false;

  }
}
and this connections:

machine----------------------------- RS422/TTL
grd ------------------------------------ A [.......] Y-----NC
sgl ------------------------------------- B [.......] Z----NC
12V ----- +12v


RS422/TTL ---------- arduino
TX ---------------------- RX
RX -----------------------TX
5V ---------------------- 5V
GRD -------------------- GRD


the newbie question is:

can I use instead an RS485 module based on SP485EEN-L ?? https://docs.m5stack.com/#/en/atom/tail485


tnks a lot

Beowulff
Posts: 17
Joined: Fri Mar 01, 2019 2:59 am

Re: RS422 vs RS485 for newbie

Postby Beowulff » Thu Jun 04, 2020 11:00 pm

I don't understand the question, but RS485 is a bus and RS422 is point-to-point.
Both are differential, but the protocols are generally much different.

A better diagram, and clearer explanation of what you are trying to do would help.

Who is online

Users browsing this forum: No registered users and 37 guests