MODBUS wind vane without datasheet

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

lm9989 didn't succeed with heinburgh's code he used another baud rate. It seems there are a lot of different versions of this vane available, all configured a bit differently.

A timeout error means there is no communication to the vane. That might be because of a wrong baud rate, a wrong parity, a wrong Modbus ID or a wrong wiring. So you have a lot of screws to turn in your tries if you didn't get a clear manual from your vendor.

Hello,

I'm still trying to configure this weather vane sensor. I tried the sketch of the lm9989, I tried to change the baud rate but it does not work.

I give the technical sheet. Maybe it could help someone

Hi there
my english is very bad, i will translate it with google, sorry.
can that help, i have 5 photos from the manual.
See if that can help.

Marcel

I tried the sketch of the lm9989, I tried to change the baud rate but it does not work.

"It does not work" is a very detailed description of your problems...

See if that can help.

Help doing what? How about post the code you're using? Post the wiring diagram of your setup? Post the exact output of that sketch? Such stuff can help us to help you.

Hi,

yeah you right pylon, sorry, I was desperated.

Well I'm coming with more informations.

I'm tring to developp a marine station for my boat with many inputs, like compass, wind direction, anemometer and others calculated values.

I started with the anemometer and it runs well, I'm able to read values and to convert the value in "km/h" and "nds". The chinese datasheet help me to configure the "byte request" to read the right byte.

I'm using a MAX485 to interface the sensor and the arduino the both case (see pictures)

I give the code for anemometer :

#include <SoftwareSerial.h> 

#define RX        10    //Serial Receive pin
#define TX        9   //Serial Transmit pin
#define RTS_pin    8    //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(9600);   
  delay(50);
}

void loop() {

  digitalWrite(RTS_pin, RS485Transmit);     // init Transmit
  byte Anemometer_request[] = {0x01, 0x03, 0x00, 0x16, 0x00, 0x01, 0x65, 0xCE}; // inquiry frame
  RS485Serial.write(Anemometer_request, sizeof(Anemometer_request));
  RS485Serial.flush();
  
  digitalWrite(RTS_pin, RS485Receive);      // Init Receive
  byte Anemometer_buf[8];
  double Anemometer;
  double Vitesse;
  double Noeud;
  
  RS485Serial.readBytes(Anemometer_buf, 8);
 
  Serial.print("wind speed : ");
  for( byte i=0; i<7; i++ ) {
  Serial.print(Anemometer_buf[i], HEX);
  Serial.print(" ");
  }
  Serial.print(" ==> ");
  Serial.print(Anemometer_buf[4]);
  Serial.print("   ");
  Anemometer = Anemometer_buf[4];
  Anemometer = Anemometer/10;
  Serial.print(Anemometer);
  Serial.println(" m/s");

  Noeud = 1.94384*Anemometer;
  Serial.print("Noeud [nds]: ");
  Serial.println(Noeud);

  Vitesse = 3.6*Anemometer;
  Serial.print("Vitesse [km/h]: ");
  Serial.println(Vitesse);
  
  Serial.println();                  
  delay(50);

}

I would like to add that I requested to the supplier that the wind direction didn't work, so he sent me a new one. So I have two wind direction and both don't work. It's weird if the two sensors are broken.

I connect the wind direction like the anemometer. I unplug the power cable from anemo to wind dir.

This is my code for the wind dir. According to the datasheet the the request message is :

"{0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}"

It's an example so I'm really not sure it's correct. I tried to change some value but without success.
I invert RX, TX, verified the power, changed digital input on the Arduino.

#include <SoftwareSerial.h> 

#define RX        10    //Serial Receive pin
#define TX        9   //Serial Transmit pin
#define RTS_pin    8    //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("Wind Direction"); 

  // Start the Modbus serial Port, for WindDir
  RS485Serial.begin(9600);   
  delay(50);
}

void loop() {

  digitalWrite(RTS_pin, RS485Transmit);     // init Transmit
  byte WindDir_request[] = {0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}; // inquiry frame
  RS485Serial.write(WindDir_request, sizeof(WindDir_request));
  RS485Serial.flush();
  
  digitalWrite(RTS_pin, RS485Receive);      // Init Receive
  byte WindDir_buf[8];
  double WindDir;
  double Vitesse;
  double Noeud;
  
  RS485Serial.readBytes(WindDir_buf, 8);
 
  Serial.print("WindDir: ");
  for( byte i=0; i<7; i++ ) {
  Serial.print(WindDir_buf[i], HEX);
  Serial.print(" ");
  }
  Serial.print(" ==> ");
  Serial.print(WindDir_buf[2]);
  Serial.print("   ");
  WindDir = WindDir_buf[2];
  WindDir = WindDir/10;
  Serial.print(WindDir);
  
  Serial.println();                  
  delay(50);

}

I read all the topic and tried different code but without sucess.

Well, If someone need more information to help me, let me know.

I hope it's clear enough.

Thank you guys.

bye.

This is my code for the wind dir. According to the datasheet the the request message is :

"{0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}"

The documentation you posted says the default address is 1 but you use 2.

As both devices use the Modbus RTU protocol, I strongly suggest to use one of the corresponding libraries (p.e. ModbusMaster, available in the IDE library manager) and not constructing the byte sequences yourself manually (you probably fail as soon as you have to calculate the CRC).

Hi Pylon,

Thank you for your answer again.

yes it's right, I tried to change the address and it's just the actual code.

I'm going to check some examples of the ModbusMaster librairies and I come back with certainly some questions. :slight_smile:

thank you.

Hi pylon,

It works! THANK YOU!!!

If someone need the code and for information this is the wiring :

From MAX485 to Arduino UNO R3 :

DI : Digital 1 (TX)
DE : Digital 3
RE : Digital 2
RO : Digital 0 (RX)

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

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

  Serial.begin(9600);
  
  // Modbus slave ID 2
  node.begin(2, Serial);
  

  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}
//bool state = true;
void loop()
{
  uint8_t result;

  node.readHoldingRegisters(0x0017, 1);

  
  if (result == node.ku8MBSuccess)
  {
    Serial.print("Vbatt: ");
    Serial.println(node.getResponseBuffer(0x00));

  }
  delay(100);
}

Do you know if there is a solution to increase the resolution?
Because the sensor returns 16 values ​​and corresponds to a value every 22.5 °.

I guess not because it corresponds to the resolution of the sensor itself

thanks again

I guess not because it corresponds to the resolution of the sensor itself

Does that manual say something else? At least the part that you posted just specifies 16 values. So I guess it doesn't have more resolution. BTW, using that construction you won't get more accuracy even if the resolution would be higher.

@Emmeuh

can you please take a picture of your results?

I´m using the Wind Direction Sensor "3001-FX-RS-1" with the user manual (request frame : 0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E.

I started my project with the Anemometer, code below, and it works. Just changing the inqiry frame didnt work.

Please help me :wink:

Anemometer_RS485 - Pastebin.com

Post code here to the forum and not to some temporary web storage!

Also post a link to the manual of your device.