Problema con 2 sSerial

Salve nel mio progetto devo usare 2 sSerial per far funzionare 2 miniplayer ma non riesco a farlo funzionare, qualcuno può aiutarmi?
Mi dice errore s1.

/**
 * Gestisce un LED in PWM per simulare alba e tramonto
 * accende le luci delle case
 * simula un fuoco
 * 
 * sole: pwm pin 5
 * case: pin 4
 * fuoco: pwm pin 6
 * 
 * con mp3 player 1 (dfminiplayer)
 * collegato sui pin:
 * 10 rx <- tx player 
 * 11 tx -> rx player

 * con mp3 player 2 (dfminiplayer)
 * collegato sui pin:
 * 2 rx <- tx player 
 * 3 tx -> rx player
 * 
 *  neopixel su pin 7
 */
#include <FastLED.h>
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
int h = 0;
int s = 255;

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial sSerial1(10, 11); // RX, TX
SoftwareSerial sSerial2(2, 3); // RX, TX

DFRobotDFPlayerMini myDFPlayer1;
int trid1 = 0;
#define MAXTRACKS 2
int tracks1[] = {1,2};

DFRobotDFPlayerMini myDFPlayer2;
int trid2 = 0;
#define MAXTRACKS 2
int tracks2[] = {1,2};

void setup() {
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

  FastLED.addLeds<WS2812, 7, GRB>(leds, NUM_LEDS);
  fill_solid(leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
    
  randomSeed(analogRead(A0));
  Serial.begin(9600);
  
  sSerial1.begin(9600);

  while (!sSerial1) delay(1);
  Serial.println(F("Presepe 2026 V2 S1"));

  sSerial2.begin(9600);

  while (!sSerial2) delay(1);
  Serial.println(F("Presepe 2026 V2 S2"));

  if (!myDFPlayer1.begin(sSerial1)) {
    Serial.println(F("Error S1"));
    while(true);
  }

  if (!myDFPlayer2.begin(sSerial2)) {
    Serial.println(F("Error S2"));
    while(true);
  }

  Serial.println(F("ready!"));
  myDFPlayer1.volume(12);
  myDFPlayer2.volume(12);

  delay(1000);
  myDFPlayer1.play(tracks1[0]);
  myDFPlayer2.play(tracks2[0]);
  trid1++;
  trid2++;
}

unsigned long tc, t1, t2;

void loop() {
  tc = millis();
  if ((tc - t1) > 60000) {    
    //Serial.print("t1: ");
    //Serial.println(t1);
    t1 = millis();
  }
  
  if ((tc - t2) > 100) {   
     
    //alba
    taskPwm(6, tc-t1, 0, 6000, 0, 255);  
    //giorno
    taskPin(6, tc-t1, 6000, 24000, HIGH);  
    //tramonto
    taskPwm(6, tc-t1, 24000, 34000, 255, 0);   
    //notte
    taskPin(6, tc-t1, 34000, 60000, LOW);  

    //neopixel
    //alba
    taskNPAlba1(tc-t1, 0, 3000);
    taskNPAlba2(tc-t1, 3000, 6000);
    //giorno
    taskNPGiorno(tc-t1, 6000, 24000);
    //tramonto
    taskNPTramonto1(tc-t1, 24000, 26000);
    taskNPTramonto2(tc-t1, 26000, 29000);
    taskNPTramonto3(tc-t1, 29000, 34000);
    //notte
    taskNPNotte(tc-t1, 34000, 60000);

    //accende e spegne le case
    taskPin(4, tc-t1, 0, 3000, HIGH);
    taskPin(4, tc-t1, 3000, 28000, LOW);  
    taskPin(4, tc-t1, 28000, 60000, HIGH);

    //il fuoco
    fuoco(5);

    //musica
    music();

    //Serial.println(tc-t1);
    t2 = millis();
  } 
}

void taskPwm(int pin, unsigned long t, unsigned long t1, unsigned long t2, int l1, int l2){
  if (t >= t1 && t < t2) {
    int pwm = map(t-t1, 0, t2-t1, l1, l2);
    analogWrite(pin, pwm);
  }
}

void taskPin(int pin, unsigned long t, unsigned long t1, unsigned long t2, int stato){
  if (t >= t1 && t < t2) {
    digitalWrite(pin, stato);    
  }
}

void fuoco(int pin){
  analogWrite(pin, random(256)); 
}

void music() {
  //suona una dopo l'altra le tracce presenti sulla sdcard  
  int st1 = myDFPlayer1.readState();
  int st2 = myDFPlayer2.readState();
  //Serial.println(st);
  //513 è in play
  //512 ha finito
  if ( (st1 == 512))
  if ( (st2 == 512)) {
    //ha terminato
    myDFPlayer1.play(tracks1[trid1]);
    myDFPlayer2.play(tracks2[trid2]);
    Serial.print("track: ");
    Serial.println(tracks1[trid1]);
    Serial.println(tracks2[trid2]);
    trid1++;
    trid2++;
    if (trid1 >= MAXTRACKS) trid1 = 0;
    if (trid2 >= MAXTRACKS) trid2 = 0;  
  } else if (st1 == 513) {
    //playing...
  } else if (st2 == 513) {
    //playing...
  }
}


void taskNPAlba1(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    h = map(t-t1, 0, t2-t1, 160, 200);
    fill_solid(leds, NUM_LEDS, CHSV(h, s, 255));
    FastLED.show();
  }
}
void taskNPAlba2(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    s = map(t-t1, 0, t2-t1, 255, 0);
    fill_solid(leds, NUM_LEDS, CHSV(h, s, 255));
    FastLED.show();
  }
}
void taskNPGiorno(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    h = 64; //giallo
    s = 0;
    fill_solid(leds, NUM_LEDS, CRGB::White);
    FastLED.show();
  }
}
void taskNPNotte(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    h = 160; //giallo
    fill_solid(leds, NUM_LEDS, CRGB::Blue);
    FastLED.show();
  }
}
void taskNPTramonto1(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    s = map(t-t1, 0, t2-t1, 0, 255);
    fill_solid(leds, NUM_LEDS, CHSV(h, s, 255));
    FastLED.show();
  }
}
void taskNPTramonto2(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    h = map(t-t1, 0, t2-t1, 64, 0);
    fill_solid(leds, NUM_LEDS, CHSV(h, s, 255));
    FastLED.show();
  }
}
void taskNPTramonto3(unsigned long t, unsigned long t1, unsigned long t2){
  if (t >= t1 && t < t2) {
    h = map(t-t1, 0, t2-t1, 255, 60);
    fill_solid(leds, NUM_LEDS, CHSV(h, s, 255));
    FastLED.show();
  }
}

Buonasera e benvenuto nella sezione Italiana del forum,

cortesemente, come prima cosa, leggi attentamente il REGOLAMENTO di detta sezione, (... e, per evitare future possibili discussioni/incomprensioni, prestando molta attenzione al punto 15), dopo di che, come da suddetto regolamento (punto 16.7), fai la tua presentazione NELL'APPOSITA DISCUSSIONE spiegando bene quali esperienze hai in elettronica e programmazione, affinché noi possiamo conoscere la tua esperienza ed esprimerci con termini adeguati.

Grazie,

Guglielmo

P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposita discussione, nel rispetto del succitato regolamento nessuno ti risponderà (eventuali risposte o tuoi ulteriori post, verrebbero temporaneamente nascosti), quindi ti consiglio di farla al più presto. :wink:

Di che Arduino stiamo parlando?

Hai letto con attenzione il reference della SoftwareSerial? Sei conscio che si può ricevere attivando UNA sola SoftwareSerial per volta?

Guglielmo

Se stai usando una UNO vale quello che ti ha scritto @gpb01 ossia hai delle limitazioni.
In tal caso usa o un Mega che ha 3 UART separate, o sacrifica la seriale USB (che tanto nello sketch non mi sembra che tu stia usando) ossia i pin 0 e 1 per una seriale ed una sola SoftwareSerial.

In realtà la usa...

Serial.println(F("Presepe 2026 V2 S1"));
Serial.println(F("Presepe 2026 V2 S2"));
Serial.println(F("Error S1"))
Serial.println(F("Error S2"))
Serial.print("track: ");
Serial.println(tracks1[trid1]);
Serial.println(tracks2[trid2]);

https://docs.arduino.cc/learn/built-in-libraries/software-serial/
https://docs.arduino.cc/tutorials/communication/TwoPortReceive/

Però potresti eliminare i messaggi sulla seriale e aggiungere un LCD. Per risparmiare pin puoi usarne uno I2C.

Si, intendevo che l'uso della seriale non era per nulla di "operativo", quindi si, concordo, può usare un LCD I2C per le info di funzionamento. Oppure usare una Mega (consigliato), Nano Every o Leonardo ad esempio.

Premetto che non ho ben chiaro come funzioni la gestione del cambio traccia sui lettori

Comunque non è quello il problema di adesso

Coneiderando che sulle sSerial non si può né ricevere ne trasmettere contemporaneamente e hanno anche problemi con l'uso dei timer, io vedo una sola soluzione e una sola mezza soluzione

La prima è l'uso di una mega

L’altra è abilitare, prima di ogni comando su un lettore, la ricezione alla sua sSerial associata

Così potrebbe funzionare

Consiglio di provare disabilitando i giochi di luce

Ah, anche passare ad un ESP32 potrebbe essere utile visto che ha 3 UART (di cui 2 utilizzabili separatamente della seriale USB) quindi potrebe risolvere il problema in un modo più pratico.
Ulteriori info: