Collegamento Arduino R4 wi-fi a pc

Ciao a tutti, ho acquistato Arduino UNO R4 wifi per pilotare una centralina per il mio presepe ma non riesco a collegarlo al pc (con sistema operativo win11) per caricare lo sketch.
Quando provo a caricare lo sketch mi dà il seguente messaggio di errore:

exit status 1

Compilation error: no match for 'operator!' (operand type is 'SoftwareSerial')

le mie conoscenze sono poche e non so come fare, potreste aiutarmi per favore?

Si prega di utilizzare la lingua inglese nella parte inglese del forum.

La domanda è stata spostata nella parte italiana del forum.

@niklas74:

:warning:
Ti segnalo che, nella sezione in lingua Inglese, si può scrivere SOLO in Inglese ... quindi, per favore, la prossima volta presta più attenzione in quale sezione metti i tuoi post; questa volta esso è stato spostato, da un moderatore della sezione di lingua Inglese, nella sezione di lingua Italiana ... la prossima volta potrebbe venire direttamente eliminato. Grazie.

Guglielmo

Mmmm ... non è che stai cercando di usare un codice scritto per Arduino UNO R3 (utilizzante la SoftwareSerial) con Arduino UNO R4?

Metti il codice che stai cercando di compilare (mi raccomando, come da regolamento, racchiuso nei tag CODE e ben indentato).

Guglielmo

Chiedo scusa per l'accaduto. Avevo provato a inserire il post nella parte in italiano ma non ci sono riuscito non mi dava il comando per postarlo

si è così, il codice è stato scritto per Arduino UNO R3. Purtroppo sono ignorante in materia e ho acquistato la versione di Arduino UNO R4. Non sapevo fosse incompatibile.

/**
 * 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 (dfminiplayer)
 * collegato sui pin:
 * 10 rx <- tx player 
 * 11 tx -> rx player
 * 
 *  neopixel su pin 7
 */
#include <FastLED.h>
#define NUM_LEDS 16
CRGB leds[NUM_LEDS];
int h = 0;
int s = 255;

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
SoftwareSerial sSerial(10, 11); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int trid = 0;
#define MAXTRACKS 4
int tracks[] = {1,3,5,7};

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);
  
  sSerial.begin(9600);
  while (!sSerial) delay(1);
  Serial.println(F("Presepe V2.0"));

  if (!myDFPlayer.begin(sSerial)) {
    Serial.println(F("Error"));
    while(true);
  }
  Serial.println(F("ready!"));
  myDFPlayer.volume(30);

  delay(1000);
  myDFPlayer.play(tracks[0]);
  trid++;
}

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 st = myDFPlayer.readState();
  //Serial.println(st);
  //513 è in play
  //512 ha finito
  if ( (st == 512)) {
    //ha terminato
    myDFPlayer.play(tracks[trid]);
    Serial.print("track: ");
    Serial.println(tracks[trid]);
    trid++;
    if (trid >= MAXTRACKS) trid = 0;  
  } else if (st == 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; //blu
    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();
  }
}

Arduino UNO R4 ha DUE seriali vere, quindi NON ti serve la SoftwareSerial, eliminala ...
... dopo di che, la Serial si riferisce alla USB, mentre i pin 0 ed 1 sono la Serial1. Collega la scheda player su tali pin e utilizza, come detto, la Serial1 :wink:

Guglielmo

Grazie per il suggerimento, ma purtroppo non so farlo... non so come si scrive

Buonasera Guglielmo, per favore mi potresti aiutare? ho provato a correggere in qualche modo, dopo una serie di tentativi mi dà il seguente errore: Compilation error: exit status1

il codice è questo:

#include <DFRobotDFPlayerMini.h>

/**
 * 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 (dfminiplayer)
 * collegato sui pin:
 * 10 rx <- tx player 
 * 11 tx -> rx player
 * 
 *  neopixel su pin 7
 */
#include <FastLED.h>
#define NUM_LEDS 16
#define myserial Serial1
CRGB leds[NUM_LEDS];
int h = 0;
int s = 255;

Serial1.begin(9600)
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"
Serial1 sSerial(0, 1); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
int trid = 0;
#define MAXTRACKS 4
int tracks[] = {1,3,5,7};

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);
  
  Serial1.begin(9600);
  while (!Serial1) delay(1);
  Serial.println(F("Presepe V2.0"));

  if (!myDFPlayer.begin(Serial1)) {
    Serial.println(F("Error"));
    while(true);
  }
  Serial.println(F("ready!"));
  myDFPlayer.volume(30);

  delay(1000);
  myDFPlayer.play(tracks[0]);
  trid++;
}

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 st = myDFPlayer.readState();
  //Serial.println(st);
  //513 è in play
  //512 ha finito
  if ( (st == 512)) {
    //ha terminato
    myDFPlayer.play(tracks[trid]);
    Serial.print("track: ");
    Serial.println(tracks[trid]);
    trid++;
    if (trid >= MAXTRACKS) trid = 0;  
  } else if (st == 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; //blu
    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();
  }
}

NO, no, la Serial1 la usi come usi la Serial ... NON è una classe che devi istanziare ... è il nome di una VERA seriale ... sai usare la Serial? Ecco quella invia e riceve via USB, Serial1 invia e riceve dai pin 0 e 1 che, sulla R4 NON sono collegati alla USB come sulla R3.

Quindi, ad esempio potrai fare, come fai per la Serial:

Serial1.begin(9600);

e poi per leggere/scrivere farai le solite Serial.1read() o Serial1.print().

Comunque, se guardi negli esempi della libreria di DFRobots trovi:

DFRobotDFPlayerMini/examples/GetStarted/GetStarted.ino

... che è un esempio in cui si usa O la SoftwareSerial (per le schede che hanno solo UNA seriale) OPPURE la Serial1 (per le schede che hanno due seriali).

Attenzione, ribadisco che nella R4 il pin 0 è RX di Serial1 e pin 1 è il TX di Serial1, quindi ... dovrai usare tali pin.

Guglielmo

Per curiosità, Guglielmo, ti risulta che su R4 ci sia anche (solo come nome/alias) SerialUSB ?
Per alcune board hanno dichiarato SerialUSB (non ricordo, forse la Leonardo ? )

@nid69ita: SI, se ben ricordo, Serial non è altro che il frutto di una #define che ridefinisce la SerialUSB in Serial. :roll_eyes:

Guglielmo

... ho visto che in Arduino.h, del core Renesas, ci sono queste righe:

#define Serial  SerialUSB
#define Serial1 _UART1_
#define Serial2 _UART2_
#define Serial3 _UART3_
#define Serial4 _UART4_
#define Serial5 _UART5_

Il codice che la gestisce è basato sulla "tinyUSB" :wink:

Guglielmo

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.