I'm trying to connect to a wind direction sensor via the Arduino Uno.
This sensor supports Modbus protocol. Connect the device to the computer and the modbuspoll software output :
This code:
#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 8 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
SoftwareSerial RS485Serial(RX, TX);
void setup() {
pinMode(RTS_pin, OUTPUT);
Serial.begin(9600);
Serial.println("Anemometer");
// Start the Modbus serial Port, for anemometer
RS485Serial.begin(9600);
delay(1000);
}
void loop() {
digitalWrite(RTS_pin, RS485Transmit); // init Transmit
byte Anemometer_request[] = {0x02, 0x03, 0x00, 0x01, 0x00, 0x02, 0x95, 0xf8}; // inquiry frame
RS485Serial.write(Anemometer_request, sizeof(Anemometer_request));
RS485Serial.flush();
digitalWrite(RTS_pin, RS485Receive); // Init Receive
byte Anemometer_buf[8];
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(" m/s");
Serial.println();
delay(1000);
}
This output:
I have a problems : I get error code 83