Hallo Zusammen
Ich versuche verzweifelt 2 Arudino Mega mit RS485 zu verbinden.
Hierfür habe ich die SoftwareSerial und den RS485_non_blocking von Nick Library
Der Sender sendet die Signale jedoch Empfange ich nichts.
RO = GPIO 2
RE = GPIO 4
DE = GPIO 2
DI= GPIO 3
VCC = 5VCC
B = B
A = A
GND = GND
A ->560 Ohm -> VCC
B -> 560 Ohm -> VCC
Sketch sender:
#include <Wire.h>
#include <SoftwareSerial.h>
#include <RS485_non_blocking.h>
unsigned long last_millis;
unsigned long last_millis_Debug;
struct {
byte signal1;
byte signal2;
byte signal3;
byte signal4;
} message;
const int tx_enabled = 4;
SoftwareSerial rs485 (2, 3); // RX receive pin, TX transmit pin
// Set Expander
/* *** Funktion Deklarationen *** */
size_t fWrite (const byte what) {
return rs485.write (what);
}
/* *** Funktion Deklarationen *** */
int fAvailable () {
return rs485.available ();
}
int fRead () {
return rs485.read ();
}
RS485 myChannel (fRead, fAvailable, fWrite, 20);
void setup ()
{
Serial.begin (38400); // Hardware Serial
rs485.begin (9600); // Software Serial
myChannel.begin();
Wire.begin();
Serial.println("Sender");
pinMode (tx_enabled, OUTPUT);
}
void loop ()
{
//Test Connection Timeout
if (millis() - last_millis >= 200) {//50
Serial.println("sende");
last_millis = millis();
last_millis_Debug = millis();
sendMessage(); // Sende-Funktion
}
}
void sendMessage()
{
message.signal1 = 1;
message.signal2 = 2;
message.signal3 = 3;
message.signal4 = 4;
digitalWrite(tx_enabled, HIGH);
myChannel.sendMsg ((byte*) &message, sizeof message); // Send my Message
digitalWrite(tx_enabled, LOW);
}
Sketch Empfänger:
#include <Wire.h>
#include <SoftwareSerial.h>
#include <RS485_non_blocking.h>
unsigned long fahrbefehl;
const int tx_enabled = 4;
SoftwareSerial rs485 (2, 3);
int fAvailable () {
return rs485.available ();
}
int fRead () {
return rs485.read ();
}
size_t fWrite (const byte what) {
return rs485.write (what);
}
RS485 myChannel (fRead, fAvailable, fWrite, 20);
void setup ()
{
rs485.begin (9600);
myChannel.begin ();
Wire.begin();
Serial.begin (38400); // Hardware Serial
Serial.println("Starte Empfänger");
pinMode (tx_enabled, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(tx_enabled, LOW);
}
void loop ()
{
if (millis() - fahrbefehl >= 10000) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
if (myChannel.update() ) {
digitalWrite(53, HIGH);
byte len = myChannel.getLength();
byte* p = myChannel.getData ();
for (; len > 0; len--) {
fahrbefehl = millis();
Serial.println("Update");
}
}
}
Ich hoffe es sind genügend Angeben vorhanden sodass mir jemand Helfen kann.
Für eure Hilfe bedanke ich mich schon im voraus.
Gruss Schnibli
