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.