Buonasera a tutti,
Non riesco a campire come scambiare i dati tra due arduino UNO collegati tramite due RS485
Master:
#include <SoftwareSerial.h>
#define SSerialRX 10
#define SSerialTX 11
#define SSerialTxControl 3
#define RS485Transmit HIGH
#define RS485Receive LOW
#define LED 13
SoftwareSerial rs485(SSerialRX, SSerialTX); // RX, TX
int byteSend;
byte curr[] = {0, 1, 2, 3};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
pinMode(LED, OUTPUT);
rs485.begin(9600);
}
void loop() {
//invio curr[0]
// put your main code here, to run repeatedly:
digitalWrite(SSerialTxControl, RS485Transmit);
rs485.write(curr[0]);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(SSerialTxControl, RS485Receive);
delay(500);
//invio curr[1]
// put your main code here, to run repeatedly:
digitalWrite(SSerialTxControl, RS485Transmit);
rs485.write(curr[1]);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(SSerialTxControl, RS485Receive);
delay(500);
//invio curr[2]
// put your main code here, to run repeatedly:
digitalWrite(SSerialTxControl, RS485Transmit);
rs485.write(curr[2]);
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(SSerialTxControl, RS485Receive);
delay(500);
//invio curr[3]
// put your main code here, to run repeatedly:
digitalWrite(SSerialTxControl, RS485Transmit);
rs485.write(curr[3]);
digitalWrite(LED, LOW);
delay(500);
digitalWrite(SSerialTxControl, RS485Receive);
}
mentre lo slave mi dovrebbe solo stampare il byte ricevuto
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial rs485(SSerialRX, SSerialTX); // RX, TX
byte byteReceived;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
rs485.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(rs485.available()){
byteReceived = rs485.read();
Serial.println(char(byteReceived));
delay(10);
//digitalWrite(13,byteReceived);
}
}
Nel monitor dell'ide mi stampa solo il carattere ?....Grazie mille.