0

I am wanting to send a digital signal from one Arduino to another. The goal is for one Arduino send a HIGH signal to a pin on the receiving Arduino. While the pin is HIGH, do function

I initially successfully tested this by blinking the LED on pin 13 but then I tried to add the functionality I needed but I couldn't get the state to change of pin 12 to change.

The circuit is simple

GND <--> GND

pin 10 --> pin 12

I saw there is already a post with a similar title but it didn't help me.

Any ideas?


Host Arduino

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
//DIGITAL SIGNAL PIN
int pin = 10; 
void setup() {
 Serial.begin(9600);
 if (! musicPlayer.begin()) { // initialise the music player
 Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
 while (1);
 }
 Serial.println(F("VS1053 found"));
 if (!SD.begin(CARDCS)) {
 Serial.println(F("SD failed, or not present"));
 while (1); // don't do anything more
 }
 // list files
 printDirectory(SD.open("/"), 0);
 // Set volume for left, right channels. lower numbers == louder volume!
 musicPlayer.setVolume(20,20);
 // Timer interrupts are not suggested, better to use DREQ interrupt!
 //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int
 // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
 // audio playing
 musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
 pinMode(pin, OUTPUT);}
void loop() {
 digitalWrite(pin,LOW);
 Serial.print(digitalRead(pin));
 // Play one file, don't return until complete
 Serial.println(F("Playing track 001"));
 musicPlayer.playFullFile("track001.mp3");
 // Play another file in the background, REQUIRES interrupts!
 Serial.println(F("Playing track 002"));
 musicPlayer.startPlayingFile("track002.mp3");
 delay(100);
}
/// File listing helper
void printDirectory(File dir, int numTabs) {
 while(true) {
 File entry = dir.openNextFile();
 if (! entry) {
 // no more files
 //Serial.println("**nomorefiles**");
 break;
 }
 for (uint8_t i=0; i<numTabs; i++) {
 Serial.print('\t');
 }
 Serial.print(entry.name());
 if (entry.isDirectory()) {
 Serial.println("/");
 printDirectory(entry, numTabs+1);
 } else {
 // files have sizes, directories do not
 Serial.print("\t\t");
 Serial.println(entry.size(), DEC);
 }
 entry.close();
 }
}

Slave Arduino

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
//DIGITAL SIGNAL PIN
int inPin = 12 ;
int state;
void setup() {
 Serial.begin(9600);
 if (! musicPlayer.begin()) { // initialise the music player
 Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
 while (1);
 }
 Serial.println(F("VS1053 found"));
 if (!SD.begin(CARDCS)) {
 Serial.println(F("SD failed, or not present"));
 while (1); // don't do anything more
 }
 // list files
 printDirectory(SD.open("/"), 0);
 // Set volume for left, right channels. lower numbers == louder volume!
 musicPlayer.setVolume(20,20);
 // Timer interrupts are not suggested, better to use DREQ interrupt!
 //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int
 // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
 // audio playing
 musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
 pinMode(inPin, INPUT);
}
void loop() {
 state = digitalRead(inPin);
 Serial.println(digitalRead(state));
 if(state == HIGH){
 musicPlayer.playFullFile("track001.mp3");
 Serial.println(F("Playing track 001"));
 } 
}
/// File listing helper
void printDirectory(File dir, int numTabs) {
 while(true) {
 File entry = dir.openNextFile();
 if (! entry) {
 // no more files
 //Serial.println("**nomorefiles**");
 break;
 }
 for (uint8_t i=0; i<numTabs; i++) {
 Serial.print('\t');
 }
 Serial.print(entry.name());
 if (entry.isDirectory()) {
 Serial.println("/");
 printDirectory(entry, numTabs+1);
 } else {
 // files have sizes, directories do not
 Serial.print("\t\t");
 Serial.println(entry.size(), DEC);
 }
 entry.close();
 }
}
asked Sep 15, 2018 at 14:20
2
  • please post the actual question .... you either have a problem with changing the state of pin 12 or changing the state of pin 10 .... which one is it? ..... it is unclear which one is the output Commented Sep 15, 2018 at 14:33
  • What has changed between the LED test working, and the actual functionality not working? For the LED experiment to have worked, the input pin of the receiving Arduino must have followed the output from the sender. Did any wiring change? Pinmode? If not, then the problem is in the new coding. Commented Sep 15, 2018 at 15:19

2 Answers 2

1

One method is to use interrupts with a state machine. Here is a minimal example:

Master

#define pin 10 // connect to slave digital input pin
void setup(){
 pinMode(pin,OUTPUT);
 digitalWrite(pin,LOW);
}
void loop(){
if( // insert your condition to trigger the slave Arduino ){ 
 digitalWrite(pin,HIGH);
 delay(10); // short delay
 digitalWrite(pin,LOW);
 }
}

Slave

#define pin 2 // connect to master digital output "pin" 
unsigned int state;
void setup(){
 pinMode(pin,INPUT);
 state=0;
 attachInterrupt(digitalPinToInterrupt(pin),isr,RISING) // trigger ISR on rising edge of master voltage signal
}
void loop(){
if(state==1){ 
 // your code here 
 state=0; // reset when done
 }
}
void isr() {
 state=1;
}

Digital interrupts can be done on the Arduino UNO with pins 2,3. Don't forget to also connect a common electrical ground between Arduinos.

jsotola
1,5342 gold badges12 silver badges20 bronze badges
answered Sep 15, 2018 at 14:41
0

If you use SPI, you can't use pin 12 as GPIO. Pin 12 is SPI MISO.

answered Sep 15, 2018 at 14:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.