Hello,
I have a Teensy setup with the Audio Adaptor Board and am able to play sound. I'm looking to be able to send a message to the Teensy to tell it which audio to play. In my project I'm using the I2C for other communications and would like to use the audio Teensy also as an I2C slave to receive the play command.
I'm able to use the Teensy as an I2C slave stand alone, and as an audio player stand alone. However when I try to do both, using the Teensy as an I2C slave fails. I see errors on the sending master side when trying to talk to the Teensy. In the Teensy code snippet below, once sgtl5000_1.enabled() is called the Teensy no longer works as a I2C slave. (Audio is still playable. I have the play code stripped out the example below.)
Should this work? My suspicion is that it doesn't because when the sgtl is enabled the Teensy now acts as an I2C master to talk to the Audio Board and can no longer work as a slave. Is this presumption correct or is the problem something else. Any suggestions on fixing this? Ideally I'd like to talk to the Teensy as an I2C slave to trigger the audio.
I have a Teensy setup with the Audio Adaptor Board and am able to play sound. I'm looking to be able to send a message to the Teensy to tell it which audio to play. In my project I'm using the I2C for other communications and would like to use the audio Teensy also as an I2C slave to receive the play command.
I'm able to use the Teensy as an I2C slave stand alone, and as an audio player stand alone. However when I try to do both, using the Teensy as an I2C slave fails. I see errors on the sending master side when trying to talk to the Teensy. In the Teensy code snippet below, once sgtl5000_1.enabled() is called the Teensy no longer works as a I2C slave. (Audio is still playable. I have the play code stripped out the example below.)
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN 10
#define SDCARD_MOSI_PIN 7
#define SDCARD_SCK_PIN 14
// GUItool: begin automatically generated code
AudioPlaySdWav playSdWav1; //xy=167,181
AudioMixer4 mixer1; //xy=368,155
AudioAnalyzePeak peak2; //xy=418,342
AudioAnalyzePeak peak1; //xy=419,305
AudioOutputI2S i2s1; //xy=546,193
AudioConnection patchCord1(playSdWav1, 0, peak1, 0);
AudioConnection patchCord2(playSdWav1, 0, mixer1, 0);
AudioConnection patchCord3(playSdWav1, 1, peak2, 0);
AudioConnection patchCord4(playSdWav1, 1, mixer1, 1);
AudioConnection patchCord5(mixer1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=165,264
// GUItool: end automatically generated code
// Receive interrupt callback
void on_receive(int num_bytes) {
while (Wire.available()) {
char c = Wire.read();
Serial.print(c);
}
}
// Send interrupt callback
void on_request() {
Serial.print("request\n");
}
void setup() {
Wire.begin(0x35);
Wire.onReceive(on_receive);
Wire.onRequest(on_request);
AudioMemory(10);
// When enabled using Teensy as I2C slave no longer works
// When commented out I2C slave receive is OK
sgtl5000_1.enable();
Serial.print("Setup complete\n");
}
void loop() {
// Unused
}
Should this work? My suspicion is that it doesn't because when the sgtl is enabled the Teensy now acts as an I2C master to talk to the Audio Board and can no longer work as a slave. Is this presumption correct or is the problem something else. Any suggestions on fixing this? Ideally I'd like to talk to the Teensy as an I2C slave to trigger the audio.