Hi, guys!
I try connect rs-ra-n01-al solar radiation sensor to arduino mega.
But I get ResponseTimedOut error on read some register.
I have manual about that sensor and take modbus codes, but it still doesn't come on.
There is an error on line 123 in your code. Also the green wire in your wiring diagram is connected to the wrong pin.
Bro you doesn't have my code and diagram.)
Ah, but @PaulRB just got his crystal ball back from service It might still be a bit hazy though.
Seriously, get the hint and post the requested information.
Oh, i'm sorry.
My code:
#include <Arduino.h>
#include <ModbusMaster.h>
ModbusMaster node;
long dataMillis;
void preTransmission()
{
digitalWrite(5, 1);
digitalWrite(6, 1);
}
void postTransmission()
{
digitalWrite(5, 0);
digitalWrite(6, 0);
}
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(5, 0);
digitalWrite(6, 0);
Serial.begin(9600);
while (!Serial)
;
Serial3.begin(4800);
node.begin(1, Serial3);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
dataMillis = millis();
}
void loop() {
if (millis() - dataMillis >= 5000) {
uint8_t resultMain = node.readHoldingRegisters(0x01, 16);
if (resultMain == node.ku8MBSuccess) {
while (node.available() > 0) {
Serial.print(node.receive());
Serial.print(" ");
}
Serial.println();
// uint16_t buffer = node.getResponseBuffer(0x00);
// if (buffer) Serial.println(buffer);
} else {
Serial.println(F(">>>>>> BAD RESULT"));
}
}
}
Guuuuys
Everything is working!
I'm sorry I took your time
Do you know what you did wrong and how you corrected it? It might be useful for others to know for the future.
Yees, of course.
Code has been correct, I Just wrong connect pins.
Diagram too been a correct.
Hi senior-vova
I bought the same sensor you used, but it has not worked, I wanted to ask you some questions in your diagram I see that the RS-485 converter is powered with 3.3 volts, but the voltage delivered by the sensor on pins A or B with respect to ground is 4.5v, so I assume that you fed it with 5v instead of 3.3v.
The result I get is the Bad Result text that you put at the end of the code, do you know if the library automatically sends the array values in hexadecimal?
As I tested the sensor with a RS-485 to usb converter and the communication works fine, do you think that something additional is missing?
I'm grateful for any help, which will help me to solve the problem.
Hi.
Power must be 3.3V.
Can u share code?
Hi
Sure,
#include <ModbusMaster.h>
ModbusMaster node;
long dataMillis;
void preTransmission()
{
digitalWrite(5, 1);
digitalWrite(6, 1);
}
void postTransmission()
{
digitalWrite(5, 0);
digitalWrite(6, 0);
}
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
digitalWrite(5, 0);
digitalWrite(6, 0);
Serial.begin(9600);
while (!Serial)
;
Serial1.begin(4800);
node.begin(1, Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
dataMillis = millis();
}
void loop() {
if (millis() - dataMillis >= 5000) {
uint8_t resultMain = node.readHoldingRegisters(0x01, 16);
if (resultMain == node.ku8MBSuccess) {
while (node.available() > 0) {
Serial.print(node.receive());
Serial.print(" ");
}
Serial.println();
}
else{
Serial.println(F(">>>>>> BAD RESULT"));
}
}
}
Hi guys
The response I am receiving seems to be InvalidSlaveID because it gives me the number 224 in decimal or E0 in hexadecimal, do you know how I can correct it, since the device ID is 1 by default.
Thanks for your help.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.