I'm trying to integrate a Pyranometer (Apogee SP-522) that transmits data using Modbus onto an MKR1010 with MKR 485 Shield
The Shield is placed on top of the MKR 1010 and here is the schematic for the current circuit that is connected
The output is being displayed on the Serial Monitor while the board is connected to the computer
Currently, it is stuck at "Failed to read registers" and the lasterror is Connection Timed Out.
I have tried many different variations, changing the register values according to the manual but nothing seems to work.
Some advice/ help would be greatly appreciated and thank you for taking the time to read through this!
Apologies I could only link 2 links as I'm a new user, do let me know if any other information is required.
Does the company that made the sensor have any PC based tools available to talk to the sensor?
You should be able to use one of the PC based modbus tools to talk to the sensor. It's a lot easier/quicker to determine if you have the right baud rate and device address than it is to use the "burn and learn" approach on an Arduino.
Once you have comms to your sensor, you will know the baud rate and device address are correct, which will give you 2 of the variables needed for Arduino modbus.
Yea definitely it would be quicker but its extra costs haha. If possible, would be better to connect straight to the Arduino. Maybe I'll have to contact their support soon
I would think any old USB to RS485 dongle would work. They are very cheap on eBay and the like - around 3GBP or 4USD.
I would also grab their software too if it's free.
EDIT: I just grabbed their DSI software tool and it looks like it may be trying to detect their specific USB-Modbus dongle. If that's the case, then we can try and figure it out without their help as I suspect that their dongle won't be cheap.
Update: Just tried it out on the sensor and it's still showing connection timed out.
Serial monitor output:
Failed to read registers
Last Error = Connection timed out
0.00
At this point, have a feeling it's more to the sensor rather than the code. Might be contacting Apogee for their technical support to make sure I'm interfacing the sensor correctly
You have 2 MKR boards stacked together so I think we can discount internal wiring. Your fritzing drawing shows a common ground with the sensor.
I guess it's an oversight but I can't see a supply to your MKR boards in your Fritzing diagram.
If you can get hold of a cheap USB-RS485 dongle you can monitor the RS485 bus and then determine if the MKR is transmitting correctly, or if the sensor is responding correctly.
Tx - Transmitting, Rx - Receiving
Tx values being transmitted are Slave addr: 0x01, read holding reg: 0x03, start addr: 0x28, no. of registers: 0x01
When i transferred these values over to Arduino
if (!ModbusRTUClient.requestFrom(0x01, HOLDING_REGISTERS, 0x28, 0x01))
{
Serial.println("Failed to read registers");
Serial.print(F("Last Error = "));
Serial.println(ModbusRTUClient.lastError());
}
and
if (!ModbusRTUClient.requestFrom(0x01, 0x03, 0x28, 0x01))
{
Serial.println("Failed to read registers");
Serial.print(F("Last Error = "));
Serial.println(ModbusRTUClient.lastError());
}
The first gave me an error of "Illegal Function" and the second gave an error of "Invalid CRC" even though the values transmitted are the same as the ones on the dongle.
That's great. You now have confidence that the sensor is working as it should.
Are you sure that they are. Sometimes the register address is out by 1 - it's a Modbus "feature" from way back! You should be able to use your USB RS485 dongle to listen in on the RS485 bus. Any simple terminal program that can display Hex values should work nicely. There are several out the but for simplicity I prefer Hercules.
You should be able to determine if the Arduino is sending the same command message as the PC program did and if the sensor is responding to it or not.
Hello, an update, I got the Arduino to read the sensor values!
Followed your advice to listen to the values from the Arduino using the USB RS485 dongle and turns out it was missing a few bits at the back. Tried different formats to request the information but didn't work.
Out of options, I increased the baudrate and it started to receive the values from the sensor.
Thank you so much for your help with everything! Really appreciate it loads!