Hello,
I am posting this to help past me and others.
Long story short I wanted to build a weather station with the parts listed below but had trouble with a few things:
Arduino RS485 Shield DFR0259
RS485 SEN0482 Wind Direction senor
RS485 SEN0483 Wind Speed Sensor
Put the Arduino RS485 shield in “auto” mode
When uploading a sketch move the other switch to “off” and then back to “on” when the upload is complete
Because both sensors come by default with the same address you will need to change one. You can change either one. I used this code to change it:
byte address_ref_frame[] = {0x00, 0x10, 0x10, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0xFA, 0x00};
byte buf[11];
void setup(){
Serial.begin(9600);
Serial.println("Serial started");
Serial.println("-----------------------------------------------");
Serial.println("Send");
delay(1000);
Serial.write(address_ref_frame, sizeof(address_ref_frame));
Serial.flush();
Serial.readBytes(buf, 11);
delay(1000);
Serial.println("Buffer");
Serial.println(buf[0], HEX);
Serial.println(buf[1], HEX);
Serial.println(buf[2], HEX);
Serial.println(buf[3], HEX);
Serial.println(buf[4], HEX);
Serial.println(buf[5], HEX);
Serial.println(buf[6], HEX);
Serial.println(buf[7], HEX);
Serial.println(buf[8], HEX);
Serial.println(buf[9], HEX);
Serial.println(buf[10], HEX);
Serial.println(buf[11], HEX);
Serial.flush();
}
void loop(){
}
This will change the address from 02 to 03.
More info below:
This is the code that I used to read the wind speed sensor:
byte wind_speed_ref_frame[] = {0x02, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x39};
byte buf[8];
int speed_dec_value;
void setup()
{
Serial.begin(9600);
Serial.println("Start");
}
void loop()
{
Serial.println("-----------------------------------------------");
Serial.println("Sending read request");
delay(1000); // waiting for serial data to clear
Serial.write(wind_speed_ref_frame, sizeof(wind_speed_ref_frame));
Serial.flush();
Serial.readBytes(buf, 8);
delay(10);
speed_dec_value = buf[4], DEC;
Serial.println("");
Serial.print("Wind Speed: ");
Serial.print(speed_dec_value/10);
Serial.println(" m/s");
Serial.println("Buffer");
Serial.println(buf[0], HEX);
Serial.println(buf[1], HEX);
Serial.println(buf[2], HEX);
Serial.println(buf[3], DEC);
Serial.print(buf[4], DEC);
Serial.println(" !");
Serial.println(buf[5], DEC);
Serial.println(buf[6], HEX);
Serial.println(buf[7], HEX);
Serial.flush();
delay (3000);
}
This is the code that I used to read the wind direction sensor:
byte wind_direction_ref_frame[] = {0x03, 0x03, 0x00, 0x00, 0x00, 0x01, 0x85, 0xE8}; //0x03, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x39
byte buf[8];
int wind_direction;
static const char *direction_list[] = {"North", "Northeast by North", "Northeast", "Northeast by East", "East", "Southeast by East", "Southeast", "Southeast by South", "South",
"Southwest by South", "Southwest", "Southwest by West", "West", "Northwest by West", "Northwest", "Northwest by North", "Invalid reading"};
void setup()
{
Serial.begin(9600);
Serial.println("Start");
}
void loop()
{
Serial.println("-----------------------------------------------");
Serial.println("Sending read request");
delay(1000);
Serial.write(wind_direction_ref_frame, sizeof(wind_direction_ref_frame));
Serial.flush();
Serial.readBytes(buf, 8);
delay(1000);
wind_direction = buf[3], DEC;
Serial.println("");
Serial.print("Wind Direction: ");
Serial.println(direction_list[wind_direction]);
Serial.println("Buffer");
Serial.println(buf[0], HEX);
Serial.println(buf[1], HEX);
Serial.println(buf[2], HEX);
Serial.print(buf[3], HEX);
Serial.println(" !");
Serial.println(buf[4], HEX);
Serial.println(buf[5], HEX);
Serial.println(buf[6], HEX);
Serial.flush();
delay (3000);
}
Remember that
0x02, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x39 is the default frame to get the sensor values
0x00, 0x10, 0x10, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0xFA, 0x00 is the frame to change the address to 03
0x03, 0x03, 0x00, 0x00, 0x00, 0x01, 0x85, 0xE8 is the frame to get the sensor value after changing the address to 03
Shout out to Jenna for helping me out with the request frame after changing the address.
Have fun!