CodeMonster
Member
I'm using a Teensy 3.2 w/ Audio Adapter as a slave to another Teensy 3.2. (The Teensy w/ audio board works on its own perfectly.) This is part of a much larger project but I've stripped the rest of it down to just the following.
I want to press the button on the Master and Wire.write(1) and have the Slave receive it and start playing a file. I tested the send/receive code and it works. When I add the audio initialization in the Setup() function, the Slave locks up. I narrowed it down to the "sgtl5000_1.enable();" line.
Is there a problem with using 2 Teeny's like this with an audio board? I'm using arbitrary addresses of 5 and 8. I couldn't find anywhere where it matters what the addresses are. I tried other addresses with the same results.
Any help would be appreciated.
// ***************************MASTER CODE
#include <Wire.h>
// I2C addresses
const int masterAddress = 5;
const int slaveAddress = 8;
// Fire
const int fireButton = 11;
int fireState = LOW;
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial
void setup()
{
Wire.begin (masterAddress);
pinMode(fireButton, INPUT);
if (DEBUG) { // If we want to see the pin values for debugging...
Serial.begin(9600); // ...set up the serial ouput on 0004 style
}
}
// Main program
void loop()
{
fireState = digitalRead(fireButton);
if (fireState == HIGH) {
Fire();
}
delay(500);
if (DEBUG) Serial.println(fireState);
}
void Fire() {
if (fireState == HIGH)
{
// Request Fire from Slave
Wire.beginTransmission (slaveAddress);
Wire.write (1);
Wire.endTransmission ();
delay(100);
}
}
// *****************SLAVE CODE
#include <Wire.h>
#include <Audio.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
const int masterAddress = 5;
const int slaveAddress = 8;
void setup() {
// put your setup code here, to run once:
Wire.begin (slaveAddress);
Wire.onReceive (receiveEvent);
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.0);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop() {
}
void receiveEvent (int intCount)
{
Serial.println("Received request");
sgtl5000_1.volume(.3);
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("SDTEST2.WAV");
delay(10); // wait for library to parse WAV info
}
} // end of receiveEvent
I want to press the button on the Master and Wire.write(1) and have the Slave receive it and start playing a file. I tested the send/receive code and it works. When I add the audio initialization in the Setup() function, the Slave locks up. I narrowed it down to the "sgtl5000_1.enable();" line.
Is there a problem with using 2 Teeny's like this with an audio board? I'm using arbitrary addresses of 5 and 8. I couldn't find anywhere where it matters what the addresses are. I tried other addresses with the same results.
Any help would be appreciated.
// ***************************MASTER CODE
#include <Wire.h>
// I2C addresses
const int masterAddress = 5;
const int slaveAddress = 8;
// Fire
const int fireButton = 11;
int fireState = LOW;
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial
void setup()
{
Wire.begin (masterAddress);
pinMode(fireButton, INPUT);
if (DEBUG) { // If we want to see the pin values for debugging...
Serial.begin(9600); // ...set up the serial ouput on 0004 style
}
}
// Main program
void loop()
{
fireState = digitalRead(fireButton);
if (fireState == HIGH) {
Fire();
}
delay(500);
if (DEBUG) Serial.println(fireState);
}
void Fire() {
if (fireState == HIGH)
{
// Request Fire from Slave
Wire.beginTransmission (slaveAddress);
Wire.write (1);
Wire.endTransmission ();
delay(100);
}
}
// *****************SLAVE CODE
#include <Wire.h>
#include <Audio.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioPlaySdWav playSdWav1;
AudioOutputI2S i2s1;
AudioConnection patchCord1(playSdWav1, 0, i2s1, 0);
AudioConnection patchCord2(playSdWav1, 1, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1;
const int masterAddress = 5;
const int slaveAddress = 8;
void setup() {
// put your setup code here, to run once:
Wire.begin (slaveAddress);
Wire.onReceive (receiveEvent);
Serial.begin(9600);
AudioMemory(8);
sgtl5000_1.enable();
sgtl5000_1.volume(0.0);
SPI.setMOSI(7);
SPI.setSCK(14);
if (!(SD.begin(10))) {
while (1) {
Serial.println("Unable to access the SD card");
delay(500);
}
}
}
void loop() {
}
void receiveEvent (int intCount)
{
Serial.println("Received request");
sgtl5000_1.volume(.3);
if (playSdWav1.isPlaying() == false) {
Serial.println("Start playing");
playSdWav1.play("SDTEST2.WAV");
delay(10); // wait for library to parse WAV info
}
} // end of receiveEvent