Arduino UNO, Modbus , RS485, Solar Irradiance sensor

Hello Guys,

I am working with arduino for 3 years, but until now i have never come accross a sensor based on (Modbus TRU, RS485). This month a project has been landed on my table.

Board : Arduino UNO
Additional Hardware: MAX485 (TTL to RS485 level)
Sensor: digital Silicon Irradiance Sensor

I have unterstood how to connect the hardware with each other, but i dont know how can i read the data from sensor. Please any one can guide me or write me the steps.
I would be really thankful.

If you are using an UNO and want to use RS485, then you should probably have an RS485 line driver like this one:


There are others available - some don't require the RE & DE signals as the Tx / Rx switching is handled automatically on-board.

More importantly, you need the manual from the manufacturer that details the serial parameters that their modbus interface uses ( baud rate, data bits, parity, stop bits etc), and the register addresses for the various parameters that you want to extract from the sensor.

The data sheet you linked does not state the exact nature of the pyranometer output. RS485 is not mentioned.

Please post a link to the data sheet explaining the output of the device you actually have.

@jremington @markd833

Thank you very very much for quick response.
I have invested some more time and found out the datasheet (attached). In the ArduinoModbus library, I have an example (ModbusRTUTemperatureSensor.ino) to read the temperature and hum sensor. According to this, i need the sensor id, holding resister adress etc.
Still i am confused what parameters i need ! I need to modify the following chunk. I want to read

  1. Irradiance in W per meter sq and
  2. cell temperature.

Following chunk has been taken from above mentioned example where temperature and humidity being measured. Now i need to modify it so that i could measure

  1. Irradiance in W per meter sq and
  2. cell temperature.

Specification_Si-RS485_MODBUS.pdf (155.3 KB)

if (!ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 2)) {
    Serial.print("failed to read registers! ");
    Serial.println(ModbusRTUClient.lastError());
  }

I believe the examples in the ArduinoModbus library are primarily aimed at the Arduino MKR series of boards. They may work with an Arduino UNO.

There is also a library called ModbusMaster, which I have running on an UNO from time to time whilst trying to help users who are using one of the NPK soil sensors. This is a chopped down version of my code to read from the NPK sensor:

// Attempt to access a JXCT NPK sensor to read Nitrogen, Potassium & Phosphorus
// values using an Arduino UNO clone.
//
// This attempt uses the AltSoftSerial & ModbusMaster libraries.
// Get AltSoftSerial at https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
//
// RS485 module wired up as:
// RS485 DI signal to pin 9
// RS485 RO signal to pin 8
// RS485 RE signal to pin 7
// RS485 DE signal to pin 6
// RS485 VCC to 5V
// RS485 GND to GND
//
// NOTE: I do not have this sensor, so I simulated it using the evaluation version of WinModbus.

#include <ModbusMaster.h>
#include <AltSoftSerial.h>

#define MAX485_DE      6
#define MAX485_RE_NEG  7

AltSoftSerial swSerial;
ModbusMaster node;

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

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

void setup() {
  Serial.begin( 9600 );

  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  // Modbus communication runs at 9600 baud
  swSerial.begin(9600);

  // Modbus slave ID of NPK sensor is 1
  node.begin(1, swSerial);

  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

void loop() {
  uint8_t result;

  // NITROGEN
  result = node.readHoldingRegisters(0x1E, 1);
  if (result == node.ku8MBSuccess)
  {
    Serial.print("   Nitrogen: ");
    Serial.print(node.getResponseBuffer(0x0));
    Serial.println(" mg/kg");
  }

  Serial.println();
  delay(2000);
}

The code sets up a baud rate of 9600 baud (same as your sensors default) and a node ID of 1 (same as your sensors default).

Off the top of my head, I think you would need to change this line:

result = node.readHoldingRegisters(0x1E, 1);

to something like this to read the "Irradiance in W/m2" register:

result = node.readHoldingRegisters(0x0000, 1);

This is for another sensor than the one you linked to in post #1, it's from a completely different manufacturer. Which one do you have actually?

For setting the bus protocol parameter the sensor offers the function code 0x46 of the Modbus protocol.

I hope you don't have to change the serial parameters because this device uses a non-standard Modbus function code which most Modbus libraries don't support.

I agree with @markd833 to better not use the ArduinoModbus library on the UNO. That library isn't resource-friendly it wastes too much memory on an UNO.

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