Go Down

Topic: MODBUS wind vane without datasheet (Read 713 times) previous topic - next topic

heinburgh

Many thanks for taking the time @pylon.

I changed the lines as you suggested, I have it switched back on my MEGA and tried the following code but without as much as a whisper coming back from the sensor.

I'm beginning to think I bought a set of duds.



Code: [Select]
#include <ModbusMaster.h>

#define MAX485_DE      3
#define MAX485_RE_NEG  2

ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
}

void setup()
{
  Serial.begin(19200);
  Serial1.begin(9600);
  Serial.println(F("BOOTING..."));
 
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  node.begin(2, Serial1); 

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}


void loop()
{
  uint8_t resultMain ;
 
  resultMain = node.readHoldingRegisters(0x0017, 1);
  if (resultMain == node.ku8MBSuccess)
  {
    Serial.println("Result: ");
    Serial.println(node.getResponseBuffer(0x00));
  }

  delay(1000);
}

heinburgh

#16
Sep 21, 2019, 10:21 pm Last Edit: Sep 21, 2019, 10:24 pm by heinburgh
Still trying to debug this issue: so when I run only this code in loop the tx LED lights up when I enter whatever text and press enter, as expected.

Code: [Select]
if(Serial1.available())
   Serial.write(Serial1.read());
 if(Serial.available())
   Serial1.write(Serial.read());



Now when I look at the MEGA while running the sketches I've been trying, the tx LED does not light up.

Does this mean that the byte array I'm sending to the sensor is not going through to the MAX485 correctly?

I've added a bit of code to print the values of the byte array on the serial monitor just to satisfy myself that the value are actually what they're meant to be.


Code: [Select]
int i;


void setup() {

 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 Serial.begin(9600);
 Serial1.begin(9600);   
}

void printHex(byte num)
{
 char hexCar[2];
 sprintf(hexCar, "%02X", num);
 Serial.print(hexCar);
}

void loop() {

 digitalWrite(2, HIGH); 
 digitalWrite(3, HIGH); 
 
 byte Anemometer_request[] = {0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E};
//  byte Anemometer_request[] = {0x01, 0x04, 0x00, 0x03, 0x00, 0xC1, 0xD5, 0xF9};
//  byte Anemometer_request[] = {0xFF, 0x06, 0x00, 0x03, 0x00, 0x00, 0x6C, 0x14};

 for(i=0; i<sizeof(Anemometer_request); i++)
 {
   printHex(Anemometer_request[i]);
   Serial1.write(Anemometer_request[i]);
 } 
 Serial1.flush();

 digitalWrite(2, LOW); 
 digitalWrite(3, LOW);
 
 Serial.println();                 
 delay(1000);
}

pylon

Quote
Now when I look at the MEGA while running the sketches I've been trying, the tx LED does not light up.
The TX LED of the Mega? That's only active if the main serial interface is used.

Does your RS485 module has a TX LED? Doesn't hat light up if you send commands?

Which ModbusMaster library are you using? The one from the IDE Library Manager?

heinburgh

The TX LED of the Mega?
Yes. My fault, I assumed those LED's would light up during action on any of the HWserial ports.


Does your RS485 module has a TX LED? Doesn't hat light up if you send commands?
Nope, just a chunk of metal unfortunately.

Which ModbusMaster library are you using? The one from the IDE Library Manager?
I think I tried four different ones. The one I spent most time with was <ModbusMaster.h> and the other one I spent a lot of time with just sent the request directly to the hardware serial port (an on to the MAX485 board.)

heinburgh

#19
Oct 03, 2019, 08:12 pm Last Edit: Oct 03, 2019, 08:13 pm by heinburgh
i just received another manual, and between the three manuals I've been sent by the sellers of these wind vanes there are several different ways of making up the magic request.


pylon

Quote
i just received another manual, and between the three manuals I've been sent by the sellers of these wind vanes there are several different ways of making up the magic request.
That page simply describes the basic message format for Modbus functions 3 and 6. Your library knows how to deal with this.

Quote
The one I spent most time with was <ModbusMaster.h> and the other one I spent a lot of time with just sent the request directly to the hardware serial port (an on to the MAX485 board.)
I asked which ModbusMaster library you used. You didn't answer that.

heinburgh

Sorry - I'm using Modbusmaster by Doc Walker version 2.0.1

pylon

Quote
Sorry - I'm using Modbusmaster by Doc Walker version 2.0.1
That one handles Modbus communication correctly.

Print out the value of "resultMain" and post the value.

heinburgh

Loop hangs when when I call this line:

resultMain = node.readHoldingRegisters(0x0017, 1);

heinburgh

Sorry - minor mistake (Serial1.begin(9600) was commented out)


resultMain: 226

heinburgh

Am I right when I say it means this:

static const uint8_t    ModbusMaster::ku8MBResponseTimedOut = 0xE2
    ModbusMaster response timed out exception. More...

heinburgh

Here's the code I'm running:

Code: [Select]


#include <ModbusMaster.h>

#define MAX485_DE      3
#define MAX485_RE_NEG  2

ModbusMaster node;

void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
  Serial.println(F("PINS 2, 3 HIGH"));
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
  Serial.println(F("PINS 2, 3 LOW"));
}

void setup()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);


  Serial.begin(19200);
  Serial1.begin(9600);

  // Modbus slave ID 1
  node.begin(2, Serial1);   // wind sensor id = 1

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}


void loop()
{
  uint8_t resultMain ;

  resultMain = node.readHoldingRegisters(0x0017, 1);
 
  Serial.print(F("resultMain: "));
  Serial.println(resultMain);
 
  if (resultMain == node.ku8MBSuccess)
  {
    Serial.println("Result: ");
    Serial.println(node.getResponseBuffer(0x00));
  } 

  delay(1000);
}

heinburgh

In this code the Serial port settings are not set anywhere. The manual says it has to be 8N1. Is there a way to set this in the code?

wildbill

Yes, you can specify it in the Serial.begin call, but there's no need - 8N1 is the default.

heinburgh

#29
Oct 05, 2019, 08:53 pm Last Edit: Oct 05, 2019, 09:02 pm by heinburgh
Ok, got that, thanks. Still no closer to get a chirp back from these wind vanes.

Another manual I got my hands on below - would this ModbusMaster library take care of EVERYTHING? All I've done is to specify the wind vane address through "node.begin(2, Serial1);" and the register to read through "resultMain = node.readHoldingRegisters(0x0017, 1);". Apart from this no other details are contained in the sketch. With the specifications given in this manual, isn't there anything else I need to specify in the code?

Current feedback from vane is still E2: timeout




Go Up