Hi,
Could someone help me ?
I want to make 5 nanos communicating through RS485 protocol with my Arduino Uno master.
This part is working great by using the code of Gammon Forum : Electronics : Microprocessors : RS485 communications
Now, I want my Uno to communicate those datas (from nanos) to an ESP32 through UART.
My problem is : when I do my Uno send data to my ESP32, the Uno can no anymore communicate avec Nanos through RS485 protocol.
Would you have an idea of my issue ?
My code:
#include "RS485_protocol.h"
#include <SoftwareSerial.h>
//#include <LedsHorloge.h>
//#include "FastLED.h"
#include "debug.h"
#define TOTAL_NUMBER_RC 5
const byte ENABLE_PIN = 3;
const byte LED_PIN_ERREUR = 10;
byte RCnumberCalled = 1;
SoftwareSerial rs485 (5, 6);
int etatEsclave[TOTAL_NUMBER_RC][2] ;
int flagRedemarrageJeu = 0;
void fWrite (const byte what)
{
rs485.write (what);
}
int fAvailable ()
{
return rs485.available ();
}
int fRead ()
{
return rs485.read ();
}
///////////////////////////////////////////////////////////////////////////
// SET UP
///////////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(9600);
rs485.begin (28800);
pinMode (ENABLE_PIN, OUTPUT);
pinMode (LED_PIN_ERREUR, OUTPUT);
Serial.println("START");
} // FIN SET UP
///////////////////////////////////////////////////////////////////////////
// LOOP
///////////////////////////////////////////////////////////////////////////
void loop()
{
byte msg [] = { RCnumberCalled,
flagRedemarrageJeu
};
digitalWrite (ENABLE_PIN, HIGH);
sendMsg (fWrite, msg, sizeof msg);
// ---- When I add this snippet of code my Uno can no anymore communicate with my Nanos ---
SoftwareSerial Ardu2Esp (8, 9);
Ardu2Esp.begin(9600);
Ardu2Esp.write(0x01);Ardu2Esp.flush();
Serial.println("Donnees envoyees vers ESP");
digitalWrite (ENABLE_PIN, LOW);
byte buf [7]; numéro des cartes Arduino
byte received = recvMsg (fAvailable, fRead, buf, sizeof buf);
digitalWrite (LED_PIN_ERREUR, received == 0); // turn on LED if error
if ( received && buf[0]==RCnumberCalled )
{
etatEsclave[RCnumberCalled-1][0] = buf[1] ;
delay(50);
int valAUn = 0 ;
if ( flagRedemarrageJeu==1 )
{
for ( int j=0 ; j<TOTAL_NUMBER_RC; j++ )
{
if ( etatEsclave[j][0]==1 )
{ /
valAUn = 1;
}
}
if ( valAUn==0 )
flagRedemarrageJeu = 0;
}
}
if ( buf[2]==1 && flagRedemarrageJeu==0 )
{
flagRedemarrageJeu = 1 ;
}
etatEsclave[RCnumberCalled-1][1] = etatEsclave[RCnumberCalled-1][0] ;
RCnumberCalled++;
}
if (RCnumberCalled>TOTAL_NUMBER_RC)
{
RCnumberCalled=1;
}
} // FIN LOOP()