Hi,
I want to build a device that can measure the direction of the wind. I decided to go with the following wind direction measurement sensor:
I found out that the device communicates with rs485 protocol, so I also got the following rs485 module:
I don't have a lot of experience with this type of communication but still tried to program some code with the help of other similar posts to this. This is my code:
#include <SoftwareSerial.h>
#define RX 10 //Serial Receive pin --> connected to RXD of rs485 module
#define TX 11 //Serial Transmit pin --> connect to TXD of rs485 module
byte Anemometer_request[] = {0x02, 0x03, 0x00, 0x17, 0x00, 0x01, 0x34, 0x0E}; // request_frame
byte Anemometer_buf[7]; // receive_frame
SoftwareSerial rs485serial(RX, TX); // SoftwareSerial initialisation
void setup() {
Serial.begin(9600);
rs485serial.begin(9600);
delay(1000);
}
void loop() {
rs485serial.write(Anemometer_request, sizeof(Anemometer_request)); // request
rs485serial.flush(); // wait for the request to be sent
delay(500);
while(rs485serial.available()){
rs485serial.readBytes(Anemometer_buf, sizeof(Anemometer_buf)); // read
}
Serial.println("Data: "); // print out data
for (byte i=0; i<7; i++){
Serial.println(Anemometer_buf[i], HEX);
}
Serial.println(" ");
delay(4000);
}
I hooked up an 11.1v lipo battery to a boost converter and set the voltage around 16 volts. This should be enough to power the wind direction sensor which is rated from 12v to 24v. I also, of course, hooked up the 485-A to A and 485-B to B. Here is the wiring from the rs485 module to my Arduino:
GND --> Arduino GND
VCC --> Arduino 5v
TX --> Arduino TX pin
RX --> Arduino RX pin
But instead of getting data, the Serial monitor outputs:
Data:
0
0
0
0
0
0
0
I'd be really grateful if somebody had an idea of what was going wrong here. One thing I find strange is, that my RS485 to TTL module doesn't have a receive enable and transmit enable pin. I guess it switches automatically? One thing that seems to be working is the TXD led on my rs485 module, whenever I send a request.
In the attachments, I have also added the manual for my wind direction sensor.
Thanks for reading this!
John