It might be possibe by using SoftwareSerial and defining MY_RS485_HWSERIAL to use the SoftwareSerial instance.``````
Insert Code Here
Its too hard to me.
Thanks for help.
It might be possibe by using SoftwareSerial and defining MY_RS485_HWSERIAL to use the SoftwareSerial instance.``````
Insert Code Here
Its too hard to me.
Thanks for help.
Which bootloader should I use? Is it necessary in my case? Does users mysensors change the bootloader?
Joints should be ok, use thermal glue. I don't know what the bootloader is. This is the arduino pro mini. Atmega 328P 5v 16mhz processor. AVrisp mkII programmer
I have 10 DHT sensors. From time to time a few lost suggestion, each time the same. In one of them I uploaded a watchdog, it worked a bit and also crashed. The one with the watchdog causes errors. Compilation is going well.
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin management on defined pin
#define MY_RS485_DE_PIN 2
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 9600
// Enable this if RS485 is connected to a hardware serial port
//#define MY_RS485_HWSERIAL Serial1
#define MY_NODE_ID 2
#include <SPI.h>
#include <MySensors.h>
#include <DHT.h>
#include <avr/wdt.h>
// Set this to the pin you connected the DHT's data pin to
#define DHT_DATA_PIN 3
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
#define CHILD_ID_HUM 1
#define CHILD_ID_TEMP 2
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
void presentation()
{
// Send the sketch version information to the gateway
sendSketchInfo("TemperatureAndHumidity", "1.1");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
}
void setup()
{
dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
metric = getControllerConfig().isMetric;
wdt_enable(WDTO_2S);
// Setup locally attached sensors
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
send(msgTemp.set(temperature, 1));
Serial.print("T: ");
Serial.println(temperature);
}
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT");
} else if (humidity != lastHum) {
lastHum = humidity;
send(msgHum.set(humidity, 1));
Serial.print("H: ");
Serial.println(humidity);
}
sleep(SLEEP_TIME); //sleep a bit
wdt_reset();
// Send locally attached sensor data here
}
Hi.
I would like to connect an 8 channel relays to arduino nano. I use rs485 communication. Rs485 uses pins 2,8,9. How to make 2,3,4 used? I miss pins.
Thx.
I think that after arduino upgrade to 1.8.10 there were problems with libraries. I have a problem running Air Humidity - DHT. Its standard code.
Arduino: 1.8.10 (Windows 10), Board: "Arduino Nano, ATmega328P"
sketch_nov14a:74:5: error: no matching function for call to 'DHT::DHT()'
DHT dht;
^~~
In file included from D:\Arduino_temp\sketch_nov14a\sketch_nov14a.ino:44:0:
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:49:4: note: candidate: DHT::DHT(uint8_t, uint8_t, uint8_t)
DHT(uint8_t pin, uint8_t type, uint8_t count=6);
^~~
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:49:4: note: candidate expects 3 arguments, 0 provided
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate: constexpr DHT::DHT(const DHT&)
class DHT {
^~~
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate expects 1 argument, 0 provided
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate: constexpr DHT::DHT(DHT&&)
D:\Arduino_temp\libraries\DHT-sensor-library-master/DHT.h:47:7: note: candidate expects 1 argument, 0 provided
D:\Arduino_temp\sketch_nov14a\sketch_nov14a.ino: In function 'void setup()':
sketch_nov14a:92:7: error: 'class DHT' has no member named 'setup'
dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor
^~~~~
sketch_nov14a:93:30: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
^~~~~~~~~~~~~~~~~~~~~~~~
sketch_nov14a:98:13: error: 'class DHT' has no member named 'getMinimumSamplingPeriod'
sleep(dht.getMinimumSamplingPeriod());
^~~~~~~~~~~~~~~~~~~~~~~~
D:\Arduino_temp\sketch_nov14a\sketch_nov14a.ino: In function 'void loop()':
sketch_nov14a:105:7: error: 'class DHT' has no member named 'readSensor'
dht.readSensor(true);
^~~~~~~~~~
sketch_nov14a:108:27: error: 'class DHT' has no member named 'getTemperature'; did you mean 'readTemperature'?
float temperature = dht.getTemperature();
^~~~~~~~~~~~~~
readTemperature
sketch_nov14a:119:25: error: 'class DHT' has no member named 'toFahrenheit'
temperature = dht.toFahrenheit(temperature);
^~~~~~~~~~~~
sketch_nov14a:135:24: error: 'class DHT' has no member named 'getHumidity'; did you mean 'readHumidity'?
float humidity = dht.getHumidity();
^~~~~~~~~~~
readHumidity
Multiple libraries were found for "SPI.h"
Used: D:\Arduino\hardware\arduino\avr\libraries\SPI
Multiple libraries were found for "MySensors.h"
Used: D:\Arduino_temp\libraries\MySensors-master
Multiple libraries were found for "DHT.h"
Used: D:\Arduino_temp\libraries\DHT-sensor-library-master
Not used: D:\Arduino_temp\libraries\arduino-DHT-master
Multiple libraries were found for "Adafruit_Sensor.h"
Used: D:\Arduino_temp\libraries\Adafruit_Unified_Sensor
exit status 1
no matching function for call to 'DHT::DHT()'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
It did not help. I still have to press the reset. I have domoticz for windows for testing. Could this be a problem?
sensor<=NUMBER_OF_RELAYS;
Did I type here the number of relays?
It's my debug code:
0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RSNGA---,VER=2.3.0
0;255;3;0;9;4 TSM:INIT
0;255;3;0;9;6 TSF:WUR:MS=0
0;255;3;0;9;9 TSM:INIT:TSP OK
0;255;3;0;9;11 TSM:INIT:GW MODE
0;255;3;0;9;14 TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;18 MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.3.0
0;255;3;0;9;22 MCO:BGN:STP
0;255;3;0;9;28 MCO:BGN:INIT OK,TSP=1
And when push button on node:
0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RSNGA---,VER=2.3.0
0;255;3;0;9;4 TSM:INIT
0;255;3;0;9;6 TSF:WUR:MS=0
0;255;3;0;9;9 TSM:INIT:TSP OK
0;255;3;0;9;11 TSM:INIT:GW MODE
0;255;3;0;9;14 TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;18 MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.3.0
0;255;3;0;9;22 MCO:BGN:STP
0;255;3;0;9;28 MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;135435 TSF:MSG:READ,10-10-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
0;255;3;0;9;135441 TSF:MSG:BC
0;255;3;0;9;135444 TSF:MSG:FPAR REQ,ID=10
0;255;3;0;9;135447 TSF:PNG:SEND,TO=0
0;255;3;0;9;135451 TSF:CKU:OK
0;255;3;0;9;135453 TSF:MSG:GWL OK
0;255;3;0;9;135762 TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
0;255;3;0;9;137466 TSF:MSG:READ,10-10-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
0;255;3;0;9;137473 TSF:MSG:PINGED,ID=10,HP=1
0;255;3;0;9;137494 TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
0;255;3;0;9;137525 TSF:MSG:READ,10-10-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
0;255;3;0;9;137550 TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
0;255;3;0;9;137578 TSF:MSG:READ,10-10-0,s=255,c=0,t=18,pt=0,l=5,sg=0:2.3.0
10;255;0;0;18;2.3.0
0;255;3;0;9;137603 TSF:MSG:READ,10-10-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
10;255;3;0;6;0
0;255;3;0;9;139631 TSF:MSG:READ,10-10-0,s=255,c=3,t=11,pt=0,l=5,sg=0:Relay
10;255;3;0;11;Relay
0;255;3;0;9;139657 TSF:MSG:READ,10-10-0,s=255,c=3,t=12,pt=0,l=3,sg=0:1.0
10;255;3;0;12;1.0
0;255;3;0;9;139680 TSF:MSG:READ,10-10-0,s=1,c=0,t=3,pt=0,l=0,sg=0:
10;1;0;0;3;
0;255;3;0;9;139703 TSF:MSG:READ,10-10-0,s=2,c=0,t=3,pt=0,l=0,sg=0:
10;2;0;0;3;
0;255;3;0;9;139725 TSF:MSG:READ,10-10-0,s=3,c=0,t=3,pt=0,l=0,sg=0:
10;3;0;0;3;
0;255;3;0;9;139749 TSF:MSG:READ,10-10-0,s=4,c=0,t=3,pt=0,l=0,sg=0:
10;4;0;0;3;
0;255;3;0;9;139771 TSF:MSG:READ,10-10-0,s=5,c=0,t=3,pt=0,l=0,sg=0:
10;5;0;0;3;
0;255;3;0;9;139794 TSF:MSG:READ,10-10-0,s=6,c=0,t=3,pt=0,l=0,sg=0:
10;6;0;0;3;
0;255;3;0;9;139820 TSF:MSG:READ,10-10-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
0;255;3;0;9;139843 TSF:MSG:SEND,0-0-10-10,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
I have a gateway rs-485. After connecting to domoticz, he reports without a problem. The relay module is connected to it. He does not start automatically. You have to do the restet with the button. I have a watchdog, but it does not help.
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* REVISION HISTORY
* Version 1.0 - Henrik Ekblad
*
* DESCRIPTION
* Example sketch showing how to control physical relays.
* This example will remember relay state after power failure.
* http://www.mysensors.org/build/relay
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin management on defined pin
#define MY_RS485_DE_PIN 12
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 9600
#include <avr/wdt.h>
// Enable repeater functionality for this node
#define MY_REPEATER_FEATURE
#define MY_NODE_ID 10
#include <MySensors.h>
#define RELAY_PIN 2 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 6 // Total number of attached relays
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
void before()
{
for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Then set relay pins in output mode
pinMode(pin, OUTPUT);
// Set relay to last known state (using eeprom storage)
digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
}
}
void setup()
{
wdt_enable(WDTO_4S);
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Relay", "1.0");
for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
// Register all sensors to gw (they will be created as child devices)
present(sensor, S_BINARY);
}
}
void loop()
{
//do stuff here
wdt_reset();
}
void receive(const MyMessage &message)
{
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
And gateway:
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* DESCRIPTION
* The RS485 Gateway prints data received from sensors on the serial link.
* The gateway accepts input on seral which will be sent out on
* the RS485 link.
*
* Wire connections (OPTIONAL):
* - Inclusion button should be connected between digital pin 3 and GND
* - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series
*
* LEDs (OPTIONAL):
* - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
* - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
* - ERR (red) - fast blink on error during transmission error or recieve crc error
*
* If your Arduino board has additional serial ports
* you can use to connect the RS485 module.
* Otherwise, the gateway uses AltSoftSerial to handle two serial
* links on one Arduino. Use the following pins for RS485 link
*
* Board Transmit Receive PWM Unusable
* ----- -------- ------- ------------
* Teensy 3.0 & 3.1 21 20 22
* Teensy 2.0 9 10 (none)
* Teensy++ 2.0 25 4 26, 27
* Arduino Uno 9 8 10
* Arduino Leonardo 5 13 (none)
* Arduino Mega 46 48 44, 45
* Wiring-S 5 6 4
* Sanguino 13 14 12
*
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin management on defined pin
#define MY_RS485_DE_PIN 2
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 9600
// Enable this if RS485 is connected to a hardware serial port
//#define MY_RS485_HWSERIAL Serial1
// Enable serial gateway
#define MY_GATEWAY_SERIAL
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
#include <MySensors.h>
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors
}
void loop()
{
// Send locally attached sensor data here
}```
Thx for help
It might be possibe by using SoftwareSerial and defining MY_RS485_HWSERIAL to use the SoftwareSerial instance.``````
Insert Code Here
Its too hard to me.
Thanks for help.