Hello everyone,
I am working on a project that intends to read and save values from a wind vane.
Here are the components/references:
- Other forum post on a similar issue: Modbus communication arduino
- ELEGOO nano board CH 340
- RS485 transceiver module: https://www.amazon.com/Transceiver-Instrument-Communication-Development-Accessories/dp/B094MKRTRC/ref=asc_df_B094MKRTRC/?tag=hyprod-20&linkCode=df0&hvadid=693287646213&hvpos=&hvnetw=g&hvrand=5378832160833854071&hvpone=&hvptwo=&hvqmt=&hvdev=c&hvdvcmdl=&hvlocint=&hvlocphy=9033288&hvtargid=pla-2201656692428&psc=1&mcid=9034e5e1b1123fa1a6daa4f1755cdbe3&gad_source=1&gclid=Cj0KCQjwltKxBhDMARIsAG8KnqUZZrRo0SYCsRvodOIOSVMP9DjOCZvO_TNeUxO3MSFdHecGCJctrPkaAuWVEALw_wcB#customerReviews
- Wind vane: RS485 Wind Direction Sensor/Transmitter V2 Wiki - DFRobot
I am currently attempting to use the Modbus Master library: GitHub - 4-20ma/ModbusMaster: Enlighten your Arduino to be a Modbus master
The primary issue I am having is interpreting the slave response frame, as no matter which of the addresses I use from the data sheet I am not getting a different output when I rotate the wind vane. I am also not sure if I am reading from the correct register or printing out the desired frame (I am interested in the 360 degree wind direction).
I also understand that there is some example code that comes with the wind vane wiki, however it is not out of the box configured for the nano and it is not obvious to me how I could alter the source code to make it work for that board, hence the use of the other library.
Here is my code:
#include <ModbusMaster.h>
/*
Using the RS485 transceiver module, Rx/Tx is hooked up to the hardware
serial port at 'Serial" to DI (driver input, connected to Tx) and RO
(receiver ouput, connected to Rx).
The data enable and receiver enable pins are connected as follows:
*/
#define MAX485_DE 4
#define MAX485_RE_NEG 5
// instantiate the ModbusMaster object
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_RE_NEG, OUTPUT);
// initialize in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
// Modbus communication runs at 9600 baud
Serial.begin(9600);
// Modbus slave ID of wind vane is 2
node.begin(2, Serial);
// Callbacks allow us to configure the RS485 transceiver correctly
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result;
uint16_t data[7]; // slave response frame for buffer is 7 bytes according to data sheet
// read wind direction value at register 0x0000
result = node.readHoldingRegisters(0x0000, 1);
if (result == node.ku8MBSuccess)
{
//Serial.println("Wind direction of 360 degrees (hex): ");
Serial.println(node.getResponseBuffer(0x0));
}
Serial.println();
delay(1000);
}
And here is the wiring diagram:
Any help would be greatly appreciated, I am very much a beginner to all of this. Thank you in advance!

