TAIL485



  • hi all,
    I'm reading a serial machine data out , on ATOM, with this RS422/TTL YL-128 adaptor
    datasheet

    with this code

    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 ---------- ATOM
    TX ---------------------- RX
    RX -----------------------TX
    5V ---------------------- 5V
    GRD -------------------- GRD

    the newbie question is:

    can I use instead RS485 module based on SP485EEN-L ??

    tnks a lot



  • nobody?


  • M5Stack

    The RS422 module you are using is not compatible with our RS485