Multiple rs485 6-wire sensors to Arduino Giga

Hello. I have ordered 3 rs485 laser distance sensors that I would like to connect to an arduino Giga R1 and be able to do 2 functions from the arduino. First is to re-zero each sensor, and second is to request a distance reading from each sensor and receive that distance reading. I have looked at a lot of tutorials, but haven't come across any that use a sensor with 6 wires. Also the arduino Giga has 4 UARTS, but do I only need 2 serial ports when using addressable rs485 sensors?
The shields I have got are:
https://www.aliexpress.com/item/1005006007545162.html?spm=a2g0o.productlist.0.0.1a49mNAamNAaTw&mp=1

The sensor details are:
Brown DC12~24V
Black switch output 1 (Not sure where to connect this)
Pink MF (Not sure where to connect either)
Grey RS485(A+) (connect to Shield----> Arduino)
Shielded RS485(B-) (connect to Shield----> Arduino)
Blue 0V

The full specs are here: https://www.gangwhooscam.com/laser_sensor.pdf

And the code (using TX0 1 and RX0 0)

#include <ModbusMaster.h>


#define MAX485_DE      1
#define MAX485_RE_NEG  0

// instantiate ModbusMaster objects
ModbusMaster node1;
ModbusMaster node2;
ModbusMaster node3;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  // Init in receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  // Modbus communication at 115200 baud
  Serial.begin(115200);

  // Sensor1 Modbus slave ID 1
  node1.begin(1, Serial);
  node1.preTransmission(preTransmission);
  node1.postTransmission(postTransmission);
}
  // Sensor2 Modbus slave ID 2
  node2.begin(2, Serial);
  node2.preTransmission(preTransmission);
  node2.postTransmission(postTransmission);
}
  // Sensor3 Modbus slave ID 3
  node3.begin(3, Serial);
  node3.preTransmission(preTransmission);
  node3.postTransmission(postTransmission);
}
  bool state1 = true;
  bool state2 = true;
  bool state3 = true;
  // Toggle the coils at address 0x0005 (Rezero)
  node1.writeSingleCoil(0x0005, true);
  node2.writeSingleCoil(0x0005, true);
  node3.writeSingleCoil(0x0005, true);	


void loop()
{
  uint8_t result1;
  uint8_t result2;
  uint8_t result3;
  
  // Toggle the coils at address 0x0002 (Distance request)
  result1 = node.writeSingleCoil(0x0002, state1);
  state1 = !state1;
  result2 = node.writeSingleCoil(0x0002, state2);
  state2 = !state2;
  result3 = node.writeSingleCoil(0x0002, state3);
  state3 = !state3;

  // Read the results - I think this may be wrong
  result1 = node1.readInputRegisters();
  result2 = node2.readInputRegisters();
  result3 = node3.readInputRegisters();
  if (result1 == node1.ku8MBSuccess)
  {
    Serial.print("sensor1 value: ");
    Serial.println(result1);
  }
  if (result2 == node2.ku8MBSuccess)
  {
    Serial.print("sensor2 value: ");
    Serial.println(result2);
  }
  if (result3 == node3.ku8MBSuccess)
  {
    Serial.print("sensor3 value: ");
    Serial.println(result3);
  }

  delay(1000);
}

I clicked too soon sorry. Any help is greatly appreciated. Thanks

No experience of a giga or a 6-wire laser sensor BUT looking at the "user manual", I think you can ignore the MF wire (seems to be a multifunction wire and is either a discrete input or a discrete output depending on the sensor version you have) and the switch wire.

Your laser sensor is a modbus device so should be relatively easy to get working. As it uses an RS-485 interface, you can connect all 3 sensors to one serial port - just make sure that they have different device addresses. You need to read the "user manual" as it seems to indicate that you can change the address of the sensor.

All the examples use sensor address 0x01 so I would start with one sensor using that address. Once you have the code for that sensor working, then it should be trivial to allow it to work with a sensor at address 0x02 and 0x03.

I would also stick with a baud rate of 9600 as that's quite common - unless you need a much faster serial link.

The RS485 modules you linked to are auto-switching units so you don't need to control the direction of the data via a couple of pins like the usual MAX485 based modules.

Have a search to see if there is a modbus library specifically for the Giga. I've no experience so can't comment. Using a modbus library will take care of most of the comms for you.

I recommend you to start just with one sensor.
Serial is your usb serial port, you should use serial1 for modbus with some lower baudrate (you can set it on sensor display menu).

Also I think readInputRegisters should have parameters.
The request specifies the starting register address and the number of registers.

ps. interesting project

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.