Wire1 and Wire2 Stop Functioning When Second WAV File is Played on Audio Sheild

bcaldw1

Member
I am using a Teensy 4.1 and the Audio shield with a simple program that mixes two WAV files. Also connected are two I2C devices, one on Wire1 and the other on Wire2. (One is a button input device and the other is output relay device.)

If I am playing one of the WAV files (either one), everything works as expected. If I play both WAV files at the same time, the other two I2C devices stop working. Once one of the second WAV files stops playing (either one) the other I2C devices start working again.

Also, this is the same whether I use the SD card on the Teensy 4.1 or the Audio Shield SD card.

Looking at the input I2C device data through the serial monitor, it looks like Wire1 and Wire2 are getting corrupted data when a second WAV is played/mixed.

Any idea what I might be doing wrong? What am I missing? Is this normal? I can provide any other information as needed.
 
Before we can really help you, you need to follow the Forum rule at the head of each page, viz "Always post complete source code & details to reproduce any issue!".
If we can't see what your doing or your code it's virtually impossible to be of much help other than randomly suggesting solutions.
If we can reproduce your problem that can lead to the quickest solution.
 
Before we can really help you, you need to follow the Forum rule at the head of each page, viz "Always post complete source code & details to reproduce any issue!".
If we can't see what your doing or your code it's virtually impossible to be of much help other than randomly suggesting solutions.
If we can reproduce your problem that can lead to the quickest solution.

Agreed, I see I failed following that rule. Thank you for the correction! 👍
 
I am using the Teensy 4.1 with the Audio shield, and the Serial Wombat I2C input device.

I have two rotary encoders and one button setup successfully with the I2C Serial wombat device, connected to Wire2.

The following is my code:

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <SerialWombat.h>


// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=131,100
AudioPlaySdWav           playSdWav2;     //xy=143,392
AudioMixer4              mixer1;         //xy=940,212
AudioMixer4              mixer2;         //xy=942,303
AudioOutputI2S           i2s1;           //xy=1106,249
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 1);
AudioConnection          patchCord2(playSdWav1, 1, mixer2, 1);
AudioConnection          patchCord3(playSdWav2, 0, mixer1, 2);
AudioConnection          patchCord4(playSdWav2, 1, mixer2, 2);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer2, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=418,517
// GUItool: end automatically generated code


// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

char Static_WAV[] = "Static.wav"; //"SDR_Static01.wav";

const int NUMBER_OF_ELEMENTS = 4;
const int MAX_SIZE = 12;

char Music_WAVs [NUMBER_OF_ELEMENTS] [MAX_SIZE] = { 
 { "SDTEST1.WAV" }, 
 { "SDTEST2.WAV" }, 
 { "SDTEST3.WAV" }, 
 { "SDTEST4.WAV" }
 };

int Pos = 0;

SerialWombatChip sw;    //Declare a Serial Wombat
SerialWombatDebouncedInput redButton(sw);

SerialWombatQuadEnc qeBasic1(sw);
SerialWombatQuadEnc qeBasic2(sw);

void setup() {

  Serial.begin(9600);

  // Audio Shield Setup
  AudioMemory(10);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
 
  {// Serial Wombat I2C Initialization
    Wire2.begin();
    sw.begin(Wire2,0x6B);  //Initialize the Serial Wombat library to use the primary I2C port, SerialWombat is address 6B
  }
  
  redButton.begin(0);
  
  qeBasic1.begin(18, 19);  // Initialize a QE on pins 0 and 1
  qeBasic2.begin(16, 17);  // Initialize a QE on pins 2 and 3

  // Initialize SD Card reader  
  SPI.setMOSI(SDCARD_MOSI_PIN);
  SPI.setSCK(SDCARD_SCK_PIN);
  if (!(SD.begin(SDCARD_CS_PIN))) {
    // stop here, but print a message repetitively
    while (1) {
      //Serial.println("Unable to access the SD card 1");
      delay(500);
    }
  }

  // ISSUE:
  // Remarking out playSdWav1.play or playSdWav2.play allows I2C interface device to work
  // Playing both WAVs causes I2C device to show wild/random input data, with all normal input (buttons/encoder) no longer having any effect
  // Once one or both WAV files are done playing, the I2C input device works properly

  playSdWav1.play(Music_WAVs[Pos]);
  delay(5);
  Pos++;

  playSdWav2.play(Static_WAV);
  delay(5);

}

void loop() {

    Serial.print(redButton.readDurationInTrueState_mS());
    Serial.print(" ");    
    Serial.print(qeBasic1.read() % 4);
    Serial.print(" ");    
    Serial.print(qeBasic2.read());
    Serial.println("");

}

I can provide any further information as needed. (Please let me know if I missing any other forum required items.) :)

Any thoughts would be appreciated.
 

Yes, it is the Serial Wombat 18AB I2C.

Serial Wombat 18AB I2C / UART Smart I/O GPIO and Analog Expander for Arduino (2 Pack, Red Label)

https://a.co/d/dqyYzgA

It works quite well with de-bouncing switches and encoders, among other things. And it works very well with the Teensy also, up until I want to play two WAVs at once. Then it goes haywire.
 
Is this the library you're using (version 2.0.8 from Arduino IDE's library manager)?

screenshot.png
 
Back
Top