MODBUS wind vane without datasheet

Pin 1 is the one by the small round indent, if I googled right. Nothing there at all. Pin 4 shows the strings exactly as they're coming from Serial TX.

The problem must be on the wind vane side since I'm not getting any corresponding values on its version of the max485 pins. Only some different values with framing errors on first and last values.

The signals reach the wind vane ok, I get the same values as that which is leaving the MEGA. This is just on the plug coming in from the harness. But somehow the signals get messed up somewhere after that.

SUCCESS!!!

The problem was in two places. The MEGA I'm using has its Serial1 TX and RX opposite to what they are marked. So I was transmitting on the RX line.

After fixing this the signal reached the wind vane, but nothing happened. So this morning I tried another wind vane from the box, and voila. The wind vane I've been testing was faulty all along.

Thanks for your patience and inputs @pylon, you got me to use a logic analyser and I can see that this will help me a lot in future.

Cheers!
Hein

Screenshot 2019-11-01 at 08.36.10.png

Screenshot 2019-11-01 at 08.36.10.png

When I analyze the RS485 line A I get this, the same as incoming from Serial2 but with an added 0xFF appended to the end:

It's almost impossible to analyze the A and B wires with a logic analyzer because the don't base their voltage on GND but only the difference of the two is important.

On the wind vane side on the MAX485 compatible chip (cannot make out the ID) on pin 7 I constantly get this:

About what I would have expected.

pylon:
It's almost impossible to analyze the A and B wires with a logic analyzer because the don't base their voltage on GND but only the difference of the two is important.

Maybe the fact that analyzing the RS485 line A is so close to the TTL output of the MEGA holds a clue to why the wind vane isn't working as it should.

Maybe the fact that analyzing the RS485 line A is so close to the TTL output of the MEGA holds a clue to why the wind vane isn't working as it should.

No, it may simply show that you didn't measure what you thought you measured.

Measuring between A-line on the RS485 - TTL converter and ground?

Measuring between A-line on the RS485 - TTL converter and ground?

That won't tell you anything meaningful. Only the difference between A-line and B-line is relevant. So if you want to measure that you have to connect the GND of the scope to B and the tip to A, then you will see the signal but you cannot measure the other signals at the same time because they are relative to GND. And you shouldn't do above with a logic analyzer as they usually don't like to get negative inputs.

I´m using a wind vane (with RS485 and Arduino Uno) and every time I´m receiving the same values as well as Heinburgh (of course I put my datasheet inquiry frame).

Please find attached vane datasheet.

Thank you so much!

Wind_Transmitter_UG_485Type_v1.0.pdf (297 KB)

I´m using a wind vane (with RS485 and Arduino Uno) and every time I´m receiving the same values as well as Heinburgh

What code are you using? What hardware adapter are you using? How did you the wiring?

Thanks for your answer.

I attached the code, a connections pictures and scheme.

I am using Arduino Uno, MAX485 module and wind direction transmitter.

The issue is that I´m receiving the same direction values all the time.

Thank you so much!

vaneCode.ino (2.11 KB)

According to the datasheet you posted the default baud rate is 4800 but you're using 9600 in your code. Did you try 4800?

Your model looks the same as the one that I struggled with, and finally got to work. This is the code that worked.

I use a MEGA however, with 3 x HW Serial ports. For an UNO you'd have to use software serial.

#include <ModbusMaster.h>

#define MAX485_DE      4
#define MAX485_RE_NEG  5

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()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

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


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

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

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


void loop()
{
  uint8_t resultMain;

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

  delay(500);
}

Hello guys,

I have the same problem with my wind vane sensor.
I read all this topic but I didn't find a solution.

I'm using Arduino UNO and MAX485. I tried your code heinburgh but it's for MEGA.

Your mainly problem was the connexion between MEGA and MAX485 or the difference between A and B line?

I'm going to read again all this topic.

thanks guys.

Hello everyone!

I have good news! The vane is working.

Thank you Pylon, you were right. RS485´s baud rate has to be 4800 because It´s the default baud rate of my vane.

So, now it works perfectly when the wind direction changes.

Thanks guys!

Hello lm9989

Could you share your sketch?

I didn't find a solution for my wind vane.

I'm going to try with the baud rate at 4800.

Thank you.

Find attached the schema connections and the code.

You have to connect your vane to VCC, GND, A, B pins.

Best regards!

vaneCode.ino (3.01 KB)

Hello all
I am also using the same chinese wind direction module. The module is not replying. Can anybody help. I tried to apply all solutions mentioned above.
Following are mine circuit connections.
DI is connected to Mega2560 TX3
RO is connected to RX3
DE and RE are short together and connected with pin # 4

I also this code and it replies bad results

#include <ModbusMaster.h>

#define MAX485_DE 4
#define MAX485_RE_NEG 5

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()
{
pinMode(MAX485_RE_NEG, OUTPUT);
pinMode(MAX485_DE, OUTPUT);

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

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

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

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

void loop()
{
uint8_t resultMain;

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

if (resultMain == node.ku8MBSuccess)
{
Serial.print("Result: ");
Serial.println(node.getResponseBuffer(0x00));
}
else
Serial.println(F(">>>>>> BAD RESULT"));

delay(500);
}

With the following code I receive 0 readable bytes as per mentioned requested frame in chinese datasheet.

include <SoftwareSerial.h> // GitHub - PaulStoffregen/SoftwareSerial: SoftwareSerial library used on Teensy

#define RX 10 //Serial Receive pin
#define TX 11 //Serial Transmit pin
#define RTS_pin 9 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW

SoftwareSerial RS485Serial(RX, TX);

void setup() {

pinMode(RTS_pin, OUTPUT);

// Start the built-in serial port, for Serial Monitor
Serial.begin(9600);
Serial.println("Anemometer");

// Start the Modbus serial Port, for anemometer
RS485Serial.begin(2400);
delay(1000);
}

void loop() {

digitalWrite(RTS_pin, RS485Transmit); // init Transmit
byte Anemometer_request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B}; // inquiry frame by lm9989
// byte Anemometer_request[] = {0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}; // inquiry frame by chinese manual
RS485Serial.write(Anemometer_request, sizeof(Anemometer_request));
RS485Serial.flush();
delay(1000);
digitalWrite(RTS_pin, RS485Receive); // Init Receive
byte Anemometer_buf[9];
RS485Serial.readBytes(Anemometer_buf, 9);

Serial.print("wind speed : ");
for( byte i=0; i<7; i++ ) {
Serial.print(Anemometer_buf*, HEX);*

  • Serial.print(" ");*
  • }*
  • Serial.print(" ==> ");*
  • Serial.print(Anemometer_buf[4]);*
  • Serial.print(" m/s");*
  • Serial.println(); *
  • delay(100);*
    }
    any help will be appreciated.

Edit your post an insert code tags!

The others had success at 4800 baud why are you using 9600 baud? Did you really read the thread?

I tried 4800. I also tried 2400. But the response is same
I used this code by heinburgh and it replies bad results

#include <ModbusMaster.h>

#define MAX485_DE      4
#define MAX485_RE_NEG  5

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()
{
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

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


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

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

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


void loop()
{
  uint8_t resultMain;

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

  delay(500);
}

With the following code I receive 0 readable bytes as per mentioned requested frame in chinese datasheet.

include <SoftwareSerial.h>  // https://github.com/PaulStoffregen/SoftwareSerial

#define RX        10    //Serial Receive pin
#define TX        11    //Serial Transmit pin
#define RTS_pin    9    //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

SoftwareSerial RS485Serial(RX, TX);

void setup() {

  pinMode(RTS_pin, OUTPUT); 
 
  // Start the built-in serial port, for Serial Monitor
  Serial.begin(9600);
  Serial.println("Anemometer");

  // Start the Modbus serial Port, for anemometer
  RS485Serial.begin(2400);   
  delay(1000);
}

void loop() {

  digitalWrite(RTS_pin, RS485Transmit);     // init Transmit
  byte Anemometer_request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x02, 0xC4, 0x0B}; // inquiry frame by lm9989
//  byte Anemometer_request[] = {0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}; // inquiry frame by chinese manual
  RS485Serial.write(Anemometer_request, sizeof(Anemometer_request));
  RS485Serial.flush();
  delay(1000);
  digitalWrite(RTS_pin, RS485Receive);      // Init Receive
  byte Anemometer_buf[9];
  RS485Serial.readBytes(Anemometer_buf, 9);
 
  Serial.print("wind speed : ");
  for( byte i=0; i<7; i++ ) {
  Serial.print(Anemometer_buf, HEX);
  Serial.print(" ");
  }
  Serial.print(" ==> ");
  Serial.print(Anemometer_buf[4]);
  Serial.print(" m/s");
  Serial.println();                 
  delay(100);

}

I have checked that last working code by heinburgh in post #51 replies E2 which means Timeout Error. Can anybody help me.