Modbus RTU Client With Giga R1

Hi all,

I am trying to use a Giga R1 to communicate Modbus RTU with a water quality analyser.

I found an excellent library SensorModbusMaster from Sarah Damiono GitHub - EnviroDIY/SensorModbusMaster: An Arduino library to act as Modbus Master to control a sensor/slave
and with the code below

// ---------------------------------------------------------------------------
// Include the base required libraries
// ---------------------------------------------------------------------------

#include <Arduino.h>
#include <SensorModbusMaster.h>


// ---------------------------------------------------------------------------
// Set up the sensor specific information
//   ie, pin locations, addresses, calibrations and related settings
// ---------------------------------------------------------------------------

// Define the sensor's modbus address
byte modbusAddress = 0x01;    // The SONDE SlaveID
long modbusBaudRate = 19200;  // SONDE Baud Rate

// Use Hardware Serial 1 Port
HardwareSerial& modbusSerial = Serial1;

// Construct the modbus instance
modbusMaster modbus;

// ==========================================================================
// VOID SETUP
// ==========================================================================
void setup() {

  Serial.begin(9600);
  
  // RS-485 Setup For SONDE - Baud=19200, 8 bits, Even Parity, 1 Stop Bit
  modbusSerial.begin(modbusBaudRate, SERIAL_8E1);

  // Start the modbus instance
  modbus.begin(modbusAddress, modbusSerial, -1);
}

// ==========================================================================
// VARIABLES
// ==========================================================================

float temperature;
float conductivity;
float pH;
float RDOConc;
float Turbidity;
float NH3N;
float SpecCond;
float Resistivity;
float Salinity;
float TotDissolvedSolids;
float Density;
float RDOSat;
float O2PartPress;
float NH4mv;
float TotNH3N;
float NH4N;

// ==========================================================================
// VOID LOOP
// ==========================================================================
void loop() {

  // Get Temperature From Address 5450 (32 Bit)
  temperature = modbus.float32FromRegister(0x03, 5450);

  // Get Actual Conductivity From Address 5506 (32 Bit)
  conductivity = modbus.float32FromRegister(0x03, 5506);

  // Get SpecCond from Address 5513 (32 Bit)
  SpecCond = modbus.float32FromRegister(0x03, 5513);

  // Get Resistivity from Address 5520 (32 Bit)
  Resistivity = modbus.float32FromRegister(0x03, 5520);

  // Get Salinity from Address 5525 (32 Bit)
  Salinity = modbus.float32FromRegister(0x03, 5525);

  // Get Total Dissolved Solids from Address 5534 (32 Bit)
  TotDissolvedSolids = modbus.float32FromRegister(0x03, 5534);

  // Get Density from Address 5541 (32 Bit)
  Density = modbus.float32FromRegister(0x03, 5541);

  // Get pH from Address 5562 (32 Bit)
  pH = modbus.float32FromRegister(0x03, 5562);

  // Get RDOC from Address 5583 (32 Bit)
  RDOConc = modbus.float32FromRegister(0x03, 5583);

  // Get RDOSat from Address 5590 (32 Bit)
  RDOSat = modbus.float32FromRegister(0x03, 5590);

  // Get Turbidity from Address 5618 (32 Bit)
  Turbidity = modbus.float32FromRegister(0x03, 5618);

  // Get O2PartPress from Address 5653 (32 Bit)
  O2PartPress = modbus.float32FromRegister(0x03, 5653);

  // Get NH4N from Address 5716 (32 Bit)
  NH4N = modbus.float32FromRegister(0x03, 5716);

  // Get NH4mv from Address 5723 (32 Bit)
  NH4mv = modbus.float32FromRegister(0x03, 5723);

  // Get NH3N from Address 5730 (32 Bit)
  NH3N = modbus.float32FromRegister(0x03, 5730);

  // Get Total NH3N from Address 5737 (32 Bit)
  TotNH3N = modbus.float32FromRegister(0x03, 5737);

  // Serial Print For Diagnostics

  Serial.print("Temperature: ");
  Serial.println(temperature);
  Serial.print("Actual Conductivity: ");
  Serial.println(conductivity);
  Serial.print("SpecCond: ");
  Serial.println(SpecCond);
  Serial.print("Resistivity: ");
  Serial.println(Resistivity);
  Serial.print("Salinity: ");
  Serial.println(Salinity);
  Serial.print("Total Dissolved Solids: ");
  Serial.println(TotDissolvedSolids);
  Serial.print("Density: ");
  Serial.println(Density);
  Serial.print("pH: ");
  Serial.println(pH);
  Serial.print("RDOC: ");
  Serial.println(RDOConc);
  Serial.print("RDOSat: ");
  Serial.println(RDOSat);
  Serial.print("Turbidity: ");
  Serial.println(Turbidity);
  Serial.print("O2PartPress: ");
  Serial.println(O2PartPress);
  Serial.print("NH4N: ");
  Serial.println(NH4N);
  Serial.print("NH4mv: ");
  Serial.println(NH4mv);
  Serial.print("NH3N: ");
  Serial.println(NH3N);
  Serial.print("Total NH3N: ");
  Serial.println(TotNH3N);
}

I find this works perfectly with a Mega2560 on Serial1 using a MAX485 485>TTL converter, however if I use the same code on Serial1 of the Giga R1, I get no response.

The MAX485 is 5v supply and I realise that the Giga is 3.3v logic and so I used a voltage divider of a 1K and 2K resistor on the RX pin of the Giga. But failed to get any response from the Modbus.

I next tried the MAX485 on 3.3v supply and although the RX/TX LED's are dimmer, I still get a response with the correct data from the Modbus when using the Mega2560 but again nothing on the Giga.

After looking at previous posts, I see other people have had a similar problem, but never seemed to find a solution.

The way I see it there are 3 possibilities;

  1. My voltage divider was not good enough and perhaps used the wrong value resistors. I have measured the voltage at the RX pin and am seeing 3.5 - 4 volts so I might have fried something. I have ordered a level shifter now but I may need another Giga as well.

  2. There is a difference in how ARM architecture works compared to the AVR. I have tried using all the hardware Serial ports and none give me a response (Now using the MAX485 on 3.3v).

  3. The software library is not compatible with the Giga. But this goes back to possibility 2. So not sure if anyone can recommend a tried and tested Modbus RTU client with the Giga.

As anyone else experienced problems with the Giga Serial ports? This is something I would normally just keep trying until I find the problem, but this is a priced job and so my boss will be tapping his feet soon.

Many thanks for any help.
Dave

Hi Dave,

This may be of interest microcontroller - MCU working at 3.3V and RS485 driver at 5V - how does this circuit work? - Electrical Engineering Stack Exchange

I'm current using a schottky diode with my serial half-duplex comms from GIGA to an RC transceiver that's powered from a 2s lipo (so 7-8v) without issue

Thanks for that Steve,

A further update. I have brought in a Giga I had at home and tried this one with the MAX485 at 3.3v and still no response. This rules out the voltage and is definitely an issue with the serial on the Giga. I currently get no TX LED which is probably why I get no RX LED (It's not sending a request). Are you using RS232 or RS485? If you are using RS485, could you let me know what library you are using. I might even be able to use 232, I will have to look at the manual, but this is also using half duplex, so your library could be my solution.

Thanks Again
Dave

Sorry Steve,

I read your reply again and now see it's an RC (It's early). Thanks anyway.
I would still reach out to anyone who has a solution.

Thanks
Dave

My GIGA connects directly to the RC transceiver. It has its own protocol (ibus, for which I've crafted my own lib) so that'll be of no use to you. The similarity in our setups is just the need to clamp down the RX uart to 3.3v for half-dup. My diode is between the RX and TX pins with the black end on the TX side.

What pins are you using for serial?

Hi Kmin,

I am using Serial 1 (Pins 18 & 19). I have also tried Serial 2 and 3

Dave

Pins D18/D19 is Serial2
Pins D0/D1 is Serial1

Hi Kmin,

You are a star! Thankyou so much. It's working.

Is this a board marking error? Because that is so confusing.
This is only the 2nd time using the Giga and so unfamiliar with the board. But to have serial 1 in the same place as the Mega, but calling it serial 2 is really misleading.

Thanks again for you help. I will now have a more relaxed day.
Dave

I don't even own a Giga...
But I agree, quite confusing labeling