Projekt aufgeräumt
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
56
Software/LCDReceiver/LCDReceiver.ino
Normal file
56
Software/LCDReceiver/LCDReceiver.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Demonstrates how to use LCDisplay 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.
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#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 LCD_RS 4
|
||||
#define LCD_EN 6
|
||||
#define LCD_D4 7
|
||||
#define LCD_D5 11
|
||||
#define LCD_D6 12
|
||||
#define LCD_D7 13
|
||||
|
||||
|
||||
|
||||
// initialize the library by associating any needed LCD interface pin with the arduino pin number it is connected to
|
||||
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
init485(Max485_RO,Max485_RE,Max485_DE,Max485_DI); // library initialization:
|
||||
invert485polarity(true);
|
||||
// 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");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (available485()) {
|
||||
String s = get485message();
|
||||
Serial.println(s);
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print(s);
|
||||
if (s.length()>16) {
|
||||
lcd.setCursor(0, 1);
|
||||
s=s.substring(16);
|
||||
s.trim();
|
||||
lcd.print(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
Software/ManualSend/ManualSend.ino
Normal file
85
Software/ManualSend/ManualSend.ino
Normal file
@@ -0,0 +1,85 @@
|
||||
/*// This sketch allows manual setting of the RS485-connected pins via serial terminal commands
|
||||
|
||||
Commands are:
|
||||
r+ – enable read mode (^RE ← LOW)
|
||||
r- – disable read mode (^RE ← HIGH)
|
||||
w+ – enable write mode (DE ← HIGH)
|
||||
w- – disable write mode (DE ← LOW)
|
||||
h – send HIGH level on DI
|
||||
l – send LOW level on DI
|
||||
|
||||
//*/
|
||||
|
||||
#if defined(ARDUINO_AVR_UNO)
|
||||
#define RS485_RO 5
|
||||
#define RS485_RE 4
|
||||
#define RS485_DE 3
|
||||
#define RS485_DI 2
|
||||
#define BOARD "Arduino Uno"
|
||||
#endif
|
||||
#if defined(ARDUINO_AVR_NANO)
|
||||
#define RS485_RO 3
|
||||
#define RS485_RE 2
|
||||
#define RS485_DE 4
|
||||
#define RS485_DI 5
|
||||
#define BOARD "Arduino Nano"
|
||||
#endif
|
||||
|
||||
String command = "";
|
||||
bool doPrint = false;
|
||||
// the setup function runs once when you press reset or power the board
|
||||
void setup() {
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
pinMode(RS485_RO, INPUT);
|
||||
pinMode(RS485_RE, OUTPUT);
|
||||
pinMode(RS485_DE, OUTPUT);
|
||||
pinMode(RS485_DI, OUTPUT);
|
||||
digitalWrite(RS485_RE,LOW);
|
||||
digitalWrite(RS485_DE,LOW);
|
||||
digitalWrite(RS485_DI,LOW);
|
||||
Serial.begin(115200);
|
||||
Serial.println(F("this is Projekte/Arduino/MAX485/ManualSend"));
|
||||
Serial.println(F("send any of the followning commands:"));
|
||||
Serial.println(F("- r+ (enable read)\n- r- (disable read)\n- w+ (enable write)\n- w- (disable write)\n- h (for high)\n- l (for low)"));
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
while (Serial.available()){
|
||||
char inChar = (char)Serial.read();
|
||||
if (inChar == '\n') {
|
||||
process(command);
|
||||
command = "";
|
||||
doPrint = true;
|
||||
} else {
|
||||
command += inChar;
|
||||
}
|
||||
}
|
||||
if (doPrint){
|
||||
printState();
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void printState(){
|
||||
Serial.print("RE = ");
|
||||
Serial.print(1-digitalRead(RS485_RE));
|
||||
Serial.print(", DE = ");
|
||||
Serial.print(digitalRead(RS485_DE));
|
||||
Serial.print(", DI = ");
|
||||
Serial.print(digitalRead(RS485_DI));
|
||||
Serial.print(", RO = ");
|
||||
Serial.println(digitalRead(RS485_RO));
|
||||
}
|
||||
|
||||
void process(String command){
|
||||
Serial.print(F("received:"));
|
||||
Serial.println(command);
|
||||
if (command == "r+") digitalWrite(RS485_RE,LOW);
|
||||
if (command == "r-") digitalWrite(RS485_RE,HIGH);
|
||||
if (command == "w+") digitalWrite(RS485_DE,HIGH);
|
||||
if (command == "w-") digitalWrite(RS485_DE,LOW);
|
||||
if (command == "h") digitalWrite(RS485_DI,HIGH);
|
||||
if (command == "l") digitalWrite(RS485_DI,LOW);
|
||||
printState();
|
||||
}
|
||||
4
Software/ManualSend/Readme.md
Normal file
4
Software/ManualSend/Readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Erkenntnisse:
|
||||
|
||||
1. Wenn alle Treiber inaktiv sind, also bei allen Teilnehmer DI = Low ist, kommt vom RO ein High-Signal
|
||||
2. das High-Signal ist dominant, d.h. wenn mehrere Teilnehmer senden, und mindestens ein Teilnehmer eine 1 auf den Bus legt, erhalten alle am RO einen HIGH-Pegel
|
||||
96
Software/Sender/Sender.ino
Normal file
96
Software/Sender/Sender.ino
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Demonstrates how to use LCDisplay 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.
|
||||
*/
|
||||
|
||||
// include the library code:
|
||||
#include <SoftRS485.h>
|
||||
|
||||
#define PROGRAM "RS485-Nano 2.0.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 TRESHOLD 100000 // 100ms
|
||||
#define ID 0
|
||||
// 0=Test
|
||||
// 1=Arbeitszimmer
|
||||
// 2=Küche
|
||||
// 3=Bad
|
||||
|
||||
//#define LOG_TO_SERIAL
|
||||
#define SEND_485
|
||||
|
||||
boolean states[8];
|
||||
unsigned long times[8];
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
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,CHANGE);
|
||||
// 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]){
|
||||
if (now - times[i] > TRESHOLD){
|
||||
#ifdef SEND_485
|
||||
send(i+1);
|
||||
#endif
|
||||
times[i] = now;
|
||||
}
|
||||
states[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user