here's something to try..
#include <HardwareSerial.h>
#define BUF_SIZE 20
#define TIMEOUT 100
#define USE_CAST true
#define WIND 0
#define REG_2 1
#define REG_3 2
#define REG_4 3
#define REG_5 4
#define REG_6 5
#define REG_7 6
#define RXD2 22 //16
#define TXD2 21 //17
HardwareSerial mod(1);
//all together.. 7 in 1, first 7 registers from device address 1..
const byte dataMod[7][8]={
{0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A},//wind speed
{0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA},//reg 2
{0x01, 0x03, 0x00, 0x02, 0x00, 0x01, 0x25, 0xCA},//reg 3
{0x01, 0x03, 0x00, 0x03, 0x00, 0x01, 0x74, 0x0A},//reg 4
{0x01, 0x03, 0x00, 0x04, 0x00, 0x01, 0xc5, 0xcb},//reg 5
{0x01, 0x03, 0x00, 0x05, 0x00, 0x01, 0x94, 0x0b},//reg 6
{0x01, 0x03, 0x00, 0x06, 0x00, 0x01, 0x64, 0x0b}};//reg 7
//same but address 255 (broadcast) any connected sensor
//should respond, the sensor will replace the 255 with their
//currently configured address, change USE_CAST to true to use
const byte dataMod_B[7][8]={
{0xFF, 0x03, 0x00, 0x00, 0x00, 0x01, 0x91, 0xD4},//wind speed
{0xFF, 0x03, 0x00, 0x01, 0x00, 0x01, 0xC0, 0x14},//reg 2
{0xFF, 0x03, 0x00, 0x02, 0x00, 0x01, 0x30, 0x14},//reg 3
{0xFF, 0x03, 0x00, 0x03, 0x00, 0x01, 0x61, 0xD4},//reg 4
{0xFF, 0x03, 0x00, 0x04, 0x00, 0x01, 0xD0, 0x15},//reg 5
{0xFF, 0x03, 0x00, 0x05, 0x00, 0x01, 0x81, 0xD5},//reg 6
{0xFF, 0x03, 0x00, 0x06, 0x00, 0x01, 0x71, 0xD5}};//reg 7
//incoming buffer
byte buf[BUF_SIZE];
void setup() {
Serial.begin(9600);
//check different bauds could be 4800
mod.begin(9600,SERIAL_8N1,RXD2,TXD2);
Serial.println("Ready..");
}
void loop() {
uint16_t val;
Serial.println("Wind Speed: ");
val = GetModVal(WIND);
float Val1 = val * 0.1;
Serial.print(Val1);
Serial.println(" %");
Serial.println("-----");
delay(5000);
}
uint16_t GetModVal(byte val) {
uint32_t startTime = 0;
uint8_t byteCount = 0;
memset(buf,0,sizeof(buf));//empty incoming..
//send request..
delay(10);
if (USE_CAST)
mod.write(dataMod_B[val], sizeof(dataMod_B[val])); else
mod.write(dataMod[val], sizeof(dataMod[val]));
mod.flush();//wait for outgoing to be sent..
//recv response until timeout expires..
Serial.print("Response in HEX: ");
startTime = millis();
while (millis() - startTime <= TIMEOUT) {
if (mod.available() && byteCount < sizeof(buf)) {
buf[byteCount++] = mod.read();
printHexByte(buf[byteCount - 1]);
}
}
Serial.println();
//combine 2 byte into word..
return (uint16_t)(buf[3] << 8 | buf[4]);
}
void printHexByte(byte b)
{
Serial.print(b , HEX);
Serial.print(':');
}
should read your wind speed..
try different bauds, I got the sketch using modbus broadcast so any device should respond..
can maybe use this to test sensor anyways..
good luck.. ~q