0

I am trying to interface this sensor, https://www.robotous.com/forcetorquesensor (RTF60-HA01-C), with the Arduino Mega. The sensor has an input voltage of 5Vs and communicates using CAN/RS232/RS422. I am using the RS232 and have connected wires properly and have tried to establish Serial Communication using the below code.

#include<String.h>
# define BuffSize 32

byte buff[BuffSize];
unsigned char data_field[16];
byte comm[11]  = {0x55, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA};
// SOP == 0x55, EOP == 0xAA, Checksum == summation of each data in data_field
void setup() {

  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial2.begin(115200);
  for (int i = 0; i < BuffSize; i++) {
    buff[i] = 13; //Number to initialise buffer
  }

}

  void loop() {
    // put your main code here, to run repeatedly:

     Serial2.write(comm, 11);
    //Serial.println(Serial2.available());
    if (Serial2.available() > 0) {
      //int read = Serial2.readBytes(buff, BuffSize);
        String output = "";
        for(int i=0;i<BuffSize;i++){
        buff[i]=Serial2.read();
        output = output + buff[i] + "|";
     }
  //Serial.println(read);
    Serial.flush();

    Serial.println(output);
    Serial.println();

    }
  }

The output I receive is just 0s and the occasional 10. Like below

0|0|0|0|0|0|0|0|10|0|0|0|0|0|0|0|0|10|0|0|0|0|0|0|0|0|10|255|255|255|255|255|

I am new to this and hope this is not a stupid question. Let

1

The Serial RX and TX pins of an Arduino are not RS-232 compatible without using some type of circuit to give you the proper voltage levels.

**RS-232 logic and voltage levels**
0 (space)   Asserted    +3 to +15 V
1 (mark)    Deasserted  −15 to −3 V 

Connecting the RX/TX pins of an Arduino directly to an RS-232 device may fry your Arduino in addition to just not working for communication. This circuit given below is an example what you'll need. There are pre-made adapter boards available for a few dollars.

enter image description here

0

You obviously haven't understood the way this device communicates over serial. You don't just throw an "11" at it to get it going - you have to craft a proper command packet and send that, and the device then starts responding with response packets that you must parse properly.

A command packet starts with 0x55, then has the command and data (8 bytes in total), then a checksum and EOP byte (0xAA).

For example:

0x55, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B, 0xAA

When reading you do not look for "at least one byte" then try and read 32 bytes. That's just never going to work. You need to wait for 0x55 to arrive, then wait for each of the 16 following command+data bytes to arrive, one at a time (they do NOT arrive all at once!), and store them - then calculate the checksum for those command and data bytes, and read the next byte and make sure it matches the checksum. Finally, confirm you have a proper packet by reading the EOP byte of 0xAA.

Ideally, you want to implement a sliding window algorithm whereby you have an array of 19 bytes and incoming bytes filter down from one end of the array to the other. When the first byte is 0x55 and the last byte is 0xAA, and the penultimate byte equals the (truncated) total of bytes 2 to 17 inclusive, do you have an actual packet and can act on the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.