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.