Hey Everyone! I have been trying to communicate a Suto S220 sensor with an Arduino UNO R4 using a MAX485 module. I have attached the program, Sensor Datasheet and the circuit diagram here as well.
No matter what I try, I keep getting the Error : E2
The screenshot of your serial monitor suggests that you are using the same serial port for diagnostic printing that you are using for your modbus comms. That's usually a bad idea.
I'm not familiar with the UNO R4. I know it's much more advanced than the original UNO. Does it not have any additional hardware serial ports?
Error code E2 = response timeout - i.e. the sensor didn't respond to the request.
Are you sure that your sensor ID is 27? The default is usually 1, unless you've changed it.
Page 24 of your datasheet says that the response time is 1 second. I hope that is the time the sensor takes to calculate a new value rather than the time taken to respond to the modbus message!
One thing I would suggest is that it would help you a lot if you were able to buy a USB-RS485 dongle. They are pretty cheap and it will allow your PC to talk to the sensor using one of the free modbus programs. It's a lot easier to adjust parameters in a PC program than to keep recompiling Arduino code.
Once you get the sensor working with the PC program, you will know the correct serial comms parameters as well as the sensor ID.
If you do get hold of one of the USB-RS485 dongles, then it ma be worth asking the sensor manufacturer if they have a PC program that will communicate with the sensor. That too will give you confidence that the sensor is working and likely expose the device ID and register addresses too.
I think it is a good suggestion to use software serial to monitor the sensor and hardware serial for debugging. Of course, check your baud rates and everything.
The other thing that stands out to me here is that, according to the schematic, the ground on your sensor isn't connected to the rest of the system. I would recommend ensuring that the ground on your sensor is at the same voltage level as the ground on your arduino and your RS485 converter. Keep your additional power supply isolated, but connect all of the grounds together. A floating ground may be enough to wreck your data.
Thank you so much for the feedback Jim. I have been actually using the Holding Registers, just was trying something in the code and forgot to edit it out.
I'm gonna make the changes from your previous suggestion and hopefully it works! Again, thank you.
Why you deleted the response line from your code??
You are blind without it, you don't get any feedback from the library indicating what is your problem. Serial.println(result, HEX);
put it back where it was and post what error you get.
Did you wire your RO to 0 and DI to 1 ?
Did you physically bridge RE and DE to single pin2 ?