Browse Source

Merge branch 'nano-revision-2.0'

entprellung
Stephan Richter 10 months ago
parent
commit
247f061c2f
  1. 33
      Software/LCDReceiver/LCDReceiver.ino
  2. 28
      Software/Sender/Sender.ino
  3. 116
      Software/TempSender/TempSender.ino

33
Software/LCDReceiver/LCDReceiver.ino

@ -9,18 +9,19 @@ @@ -9,18 +9,19 @@
#include <LiquidCrystal.h>
#include <SoftRS485.h>
#define Max485_RO 3 // read-output of Max485
#define Max485_RE 5 // not-read-enable of Max485
#define Max485_DE 9 // data enable of Max485
#define Max485_DI 8 // data input of Max485
#define Max485_RO 2 // read-output of Max485
#define Max485_RE 3 // not-read-enable of Max485
#define Max485_DE 8 // data enable of Max485
#define Max485_DI 9 // data input of Max485
#define LCD_RS 4
#define LCD_EN 6
#define LCD_D4 7
#define LCD_D5 11
#define LCD_D6 12
#define LCD_D7 13
#define LCD_RS 10
#define LCD_EN 11
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 7
#define PROGRAM "RS485-Nano 2.1 / LCDReceive 1.2"
// initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to
@ -34,14 +35,11 @@ void setup() { @@ -34,14 +35,11 @@ void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
Serial.println("LCDReceive 1.2");
lcd.print("LCDReceive 1.2");
printMessage(PROGRAM);
}
void loop() {
if (available485()) {
String s = get485message();
void printMessage(String s){
Serial.println(s);
lcd.clear();
lcd.setCursor(0, 0);
@ -52,5 +50,10 @@ void loop() { @@ -52,5 +50,10 @@ void loop() {
s.trim();
lcd.print(s);
}
}
void loop() {
if (available485()) {
printMessage(get485message());
}
}

28
Software/Sender/Sender.ino

@ -1,22 +1,23 @@ @@ -1,22 +1,23 @@
/*
* Demonstrates how to use LCDisplay in conjunction with SoftRS485:
* Demonstrates how to use Read Buttons in conjunction with SoftRS485:
*
* The main _loop_ of this program listens on the RS485 bus.
* Whenever a message is received from the bus, it is displayed on the LCD.
* If a button is pressed, a corresponding flag is set.
* The main loop checks for the state of those flags and
* sends a message on the RS485 bus whenever a flag is set.
*/
// include the library code:
#include <SoftRS485.h>
#define PROGRAM "RS485-Nano 2.0.1"
#define PROGRAM "RS485-Nano 2.1 / Sender 1.1"
#define BTN_INT 2 // button interrupt pin
#define Max485_RO 3 // read-output of Max485
#define Max485_RE 5 // not-read-enable of Max485
#define Max485_DE 9 // data enable of Max485
#define Max485_DI 8 // data input of Max485
#define BTN_INT 3 // button interrupt pin
#define Max485_RO 2 // read-output of Max485
#define Max485_RE 3 // not-read-enable of Max485
#define Max485_DE 8 // data enable of Max485
#define Max485_DI 9 // data input of Max485
#define TRESHOLD 100000 // 100ms
#define TRESHOLD 200000 // 200ms
#define ID 0
// 0=Test
// 1=Arbeitszimmer
@ -31,7 +32,7 @@ unsigned long times[8]; @@ -31,7 +32,7 @@ unsigned long times[8];
void setup() {
void setup(){
Serial.begin(115200);
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization:
pinMode(BTN_INT,INPUT_PULLUP);
@ -82,8 +83,13 @@ void send(int btn){ @@ -82,8 +83,13 @@ void send(int btn){
void loop(){
unsigned long now = micros();
boolean pause = true;
for (int i=0;i<8;i++){
if (states[i]){
if (pause){
delay(5);
pause=false;
}
if (now - times[i] > TRESHOLD){
#ifdef SEND_485
send(i+1);

116
Software/TempSender/TempSender.ino

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
/*
* Demonstrates how to use Read Buttons in conjunction with SoftRS485:
*
* If a button is pressed, a corresponding flag is set.
* The main loop checks for the state of those flags and
* sends a message on the RS485 bus whenever a flag is set.
*/
// include the library code:
#include <SoftRS485.h>
#include <AM2302-Sensor.h>
#define PROGRAM "RS485-Nano 2.1 / TempSender 1.1"
#define BTN_INT 3 // button interrupt pin
#define Max485_RO 2 // read-output of Max485
#define Max485_RE 3 // not-read-enable of Max485
#define Max485_DE 8 // data enable of Max485
#define Max485_DI 9 // data input of Max485
#define DHT_PIN 4
#define TRESHOLD 100000 // 100ms
#define PERIOD 100000000 // 100s
#define ID 3
// 0=Test
// 1=Arbeitszimmer
// 2=Küche
// 3=Bad
//#define LOG_TO_SERIAL
#define SEND_485
AM2302::AM2302_Sensor am2302{DHT_PIN};
boolean states[8];
unsigned long times[8];
unsigned long sensor_time = PERIOD;
void setup(){
Serial.begin(115200);
am2302.begin();
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization:
pinMode(BTN_INT,INPUT_PULLUP);
pinMode(14,INPUT_PULLUP);
pinMode(15,INPUT_PULLUP);
pinMode(16,INPUT_PULLUP);
pinMode(17,INPUT_PULLUP);
pinMode(18,INPUT_PULLUP);
pinMode(19,INPUT_PULLUP);
pinMode(20,INPUT_PULLUP);
pinMode(21,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2),isr,FALLING);
// Print a message to the LCD.
Serial.println(PROGRAM);
#ifdef LOG_TO_SERIAL
Serial.println("14 15 16 17 18 19 20 21");
#endif
}
void isr(){
states[0] = !digitalRead(14);
states[1] = !digitalRead(15);
states[2] = !digitalRead(16);
states[3] = !digitalRead(17);
states[4] = !digitalRead(18);
states[5] = !digitalRead(19);
states[6] = !(analogRead(20)>200);
states[7] = !(analogRead(21)>200);
#ifdef LOG_TO_SERIAL
for (int i=0;i<8;i++){
Serial.print(" "); Serial.print(states[i]); Serial.print(" ");
}
Serial.println();
#endif
}
#ifdef SEND_485
void send(int btn){
String s = "{nano:"+String(ID)+",btn:"+String(btn)+"}";
for (int i = 0; i<10; i++){
if (send485(s.c_str())) break;
Serial.println("collision detected, trying again:");
}
}
#endif
void loop(){
unsigned long now = micros();
for (int i=0;i<8;i++){
if (states[i]){
delay(1);
if (now - times[i] > TRESHOLD){
#ifdef SEND_485
send(i+1);
#endif
times[i] = now;
}
states[i] = 0;
}
}
if (now - sensor_time > PERIOD){
sensor_time = now;
auto status = am2302.read();
if (status == 0){
String s = "{nano:"+String(ID)+",temp:"+String(am2302.get_Temperature())+",humi:"+String(am2302.get_Hunidity())+"}";
send485(s.c_str());
#ifdef LOG_TO_SERIAL
Serial.println(s);
#endif
}
}
}
Loading…
Cancel
Save