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;
-
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.
-
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).
-
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