I still have a few questions:
Use: https://github.com/mysensors/Arduino/tree/development/libraries/MySensors.
1) Architecture: Do I understand correctly, example test:
raspberry pi domoticz [USB] <---- USB RS232 built-in Arduino nano ----> (hardware RS232, PIN: tx/rx) Arduino Nano (Gatwey RS485) (AltSoftSerial, PIN: 2,7,8) <---- RS485 AltSoftSerial ----> (AltSoftSerial, PIN: 2,7,8) Arduino Pro Mini <------ PIN 3, DHT22
2) Gatwey RS485 Arduino Nano:
- USB port of the Arduino Nano plugs in to Raspberry PI and set MySensors USB gateway in Domoticz ?
- Gatwaey to communicate with RS485 uses AltSoftSerial ? Whta PIN ? R0 / DI ?
- Gatwey Arduino Nano to communicate with Raspberry PI (Domoticz) use hardware USB (built in RS232) ?
- Gatweway don't have Debug mode (no free RS) ? When uploading have I must turn of debug mode in MyConfig.h when use RS485?
- DE PIN 2 ?
- RO PIN 8 ?
- DI PIN 9 ?
- PIN 2/8/9 connected directly without pull-up resistors or current limiting ?
/**
...
* 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 <----- Form https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html .... (& other ATMEGA328)
* 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 serial gateway
#define MY_GATEWAY_SERIAL
// Flash leds on rx/tx/err
#define MY_LEDS_BLINKING_FEATURE
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// 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
#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 <SPI.h>
#include <MySensor.h>
void setup() {
// Setup locally attached sensors
}
void presentation() {
// Present locally attached sensors
}
void loop() {
// Send locally attached sensor data here
}
3) Sensor Arduino Pro mini
- What uses to communicate with RS485 bus ? Hardware RS232 Pin RX /TX or AltSoftSerial Pin 2/7/8 ?
- If use AltSoftSerial: PIN 2/8/9 connected directly without pull-up resistors or current limiting ?
- When uploading have I must turn of debug mode in MyConfig.h when use RS485?
/**
...
// Enable RS485 transport layer
#define MY_RS485
// Define this to enables DE-pin manag ement on defined pin
#define MY_RS485_DE_PIN 2
// Set RS485 baud rate to use
#define MY_RS485_BAUD_RATE 9600
#include <SPI.h>
#include <MySensor.h>
#include <DHT.h>
#define MY_NODE_ID 15
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3
unsigned long SLEEP_TIME = 2000; // Sleep time between reads (in milliseconds)
// Initialize sensors
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
// Debug
//#include <SoftwareSerial.h>
//SoftwareSerial mySerial(3, 4); // RX, TX
void setup()
{
//mySerial.begin(4800);
//mySerial.println("Hello, world?");
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
metric = getConfig().isMetric;
}
void presentation() {
// Send the Sketch Version Information to the Gateway
sendSketchInfo("Falskiego LED salon", "1.0");
// 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 loop()
{
delay(dht.getMinimumSamplingPeriod());
// Fetch temperatures from DHT sensor
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));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
}
// Fetch humidity from DHT sensor
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));
#ifdef MY_DEBUG
Serial.print("H: ");
Serial.println(humidity);
#endif
}
sleep(SLEEP_TIME); //sleep a bit
}