I am working on project using Hukseflux SR05-D2A2 thermal sensors. These sensors support Modbus communication through a TTL interface. The objective is to read the value at a specific address in the sensor (in my case, it is the register holding the irradiation value measured by the sensor).
Reading from one sensor is easily done as follows:
Connect the TTL interface of the sensor with a microcontroller's serial pins (Arduino for example).
Use a library that implements the Modbus communication functions (for example, ModbusMaster for Arduino) to issue requests.
Read the data received on the receiver pin of the Arduino.
Everything works well in this case. However, when trying to connect 2 sensors to 1 master (Arduino), I am having problems. I have tried to connect both TXs and RXs of the 2 sensors together and then to the Arduino's RX and TX respectively. Then, I tried to send requests for the sensors by using their addresses, and I am getting an error. Here is the code:
#include <ModbusMaster.h>
#define Common 13
// instantiate ModbusMaster object
ModbusMaster node;
void preTransmission()
{
digitalWrite(Common, 1);
}
void postTransmission()
{
digitalWrite(Common, 0);
}
void setup()
{
uint8_t result;
pinMode(Common, OUTPUT);
digitalWrite(Common, 0);
// Communication of the arduino and the serial monitor
Serial.begin(19200);
//Communication of arduino with sensors
Serial1.begin(19200, SERIAL_8E1);
// Modbus slave ID 1
node.begin(1, Serial1);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
do
{
result = node.readInputRegisters(0x0000, 1);
Serial.println(result);
Serial.println(node.getResponseBuffer(0x00));
} while (result != 0);
delay(1000);
//Modbus ID slave 2
node.begin(2, Serial1);
node.preTransmission(preTransmission2);
node.postTransmission(postTransmission2);
do
{
result = node.readInputRegisters(0x0000, 1);
Serial.println(result);
Serial.println(node.getResponseBuffer(0x00));
} while (result != 0);
}
void loop()
{
}
I would appreciate it if anybody could suggest solutions to this problem. Note that I am open for using pyModbus to communicate with the sensors using a Raspberry Pi if anybody can suggest a solution that uses it.