General Arduino

Arduino blocked on bus line

userHead Mariani.Luciano 2023-11-20 01:35:07 135 Views0 Replies

Hi, I'm Italian so I used the translator to write. I have a problem with this sketch. I have two Arduino Megas, one master, one slave. If I press the button on the slave, the DFPlayer plays the Mp3 file I set. If I press the button on the master with the Wire.write command. the cards are blocked can you help me on my project thanks.

 

// Master


 

#include <Wire.h>


 

void setup() {

  pinMode(2, INPUT_PULLUP);

  Wire.begin();

 

}


 

void loop() {

 

  if (digitalRead(2) == LOW){

    Wire.beginTransmission(2);

    Wire.write("play");

    Wire.endTransmission();

 

  }


 

}

 

 

 

//Slave

#include <Wire.h>

#include <DFRobotDFPlayerMini.h>

#include <SoftwareSerial.h>

SoftwareSerial ss(10,11);

DFRobotDFPlayerMini mp3;


 

void setup() {

   ss.begin(9600);

   Serial.begin(9600);

   Serial.println("running");

 if (!mp3.begin(ss)){

   Serial.println("controllo cavi");

   while(true);

   }

   

    Serial.println("DFPlayer Mini On Line");

    pinMode(2, INPUT_PULLUP);

    Wire.begin(2);

    Wire.onReceive(ricevi);

    mp3.volume(20);


 

}


 

void loop() {

   if (digitalRead(2) == LOW){

    mp3.play(1);

    Serial.println("Mp3 play");

    }

   }

void ricevi(){

  String comando = "";

   while   (Wire.available()){

    comando += char(Wire.read());

    }

  if (comando == "play"){

  mp3.play(1);

  Serial.println("Mp3 play Wire");

  }

}

 

 

I'm not a programmer so please understand if there are errors.