I am trying to set up this sensor, but the z-uno doesn’t support SoftwareSerial. So how do I do this then?
Sorry for the quirky links, but I am not allowed to set more than two links in a topic (new user)...
z-uno.z-wave. me
I am adapting this sketch:
create.arduino.cc/projecthub/philippedc/arduino-esp8266-rs485-modbus-anemometer-45f1d8
Hardware
Wind Sensor (SEN0483) using the RS485 to RS232 (DFR0845)
github. com/DFRobotdl/RS485_Wind_Speed_Transmitter
Arduino Example for communication (NOT z-uno)
Example for Raspberry Pi
Here is what I have.
Code
// V3.0
ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_FREQUENTLY_AWAKE);
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_VELOCITY, SENSOR_MULTILEVEL_SCALE_METERS_PER_SECOND, SENSOR_MULTILEVEL_SIZE_FOUR_BYTES, SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, getterWind),
ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_VELOCITY, SENSOR_MULTILEVEL_SCALE_METERS_PER_SECOND, SENSOR_MULTILEVEL_SIZE_FOUR_BYTES, SENSOR_MULTILEVEL_PRECISION_ONE_DECIMAL, getterGust)
);
#include <SoftwareSerial.h> // https://github.com/PaulStoffregen/SoftwareSerial
#define RX 10 //Serial Receive pin
#define TX 11 //Serial Transmit pin
#define RTS_pin 9 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
SoftwareSerial RS485Serial(RX, TX);
long counter = 0;
long endCounter = 600; //seconds for report interval
float lastValue = 0;
float currentValue = 0;
float sumWind = 0;
float meanWind = 0;
float gust = 0;
void setup() {
pinMode(RTS_pin, OUTPUT);
// Start the built-in serial port, for Serial Monitor
Serial.begin(9600);
// Start the Modbus serial Port, for anemometer
RS485Serial.begin(9600);
delay(1000);
}
void loop() {
digitalWrite(RTS_pin, RS485Transmit); // init Transmit
byte Anemometer_request[] = {0x01, 0x03, 0x00, 0x16, 0x00, 0x01, 0x65, 0xCE}; // 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);
//just for reference, has to be set as currentValue below
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();
if (counter < endCounter) {
currentValue = 10; // Set here value from serial device
// Gust higher or not?
if (currentValue > lastValue) {
lastValue = currentValue;
}
sumWind = sumWind + currentValue;
counter = counter + 1;
gust = lastValue; //m/s
delay(100);
}
else {
//Calculate new wind values
meanWind = sumWind / endCounter;
zunoSendReport(2);
zunoSendReport(1);
lastValue = 0;
sumWind = 0;
counter = 0;
delay(100);
}
}
long getterWind(void) {
return meanWind;
}
long getterGust(void) {
return gust;
}