Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Teensy 4 with UDA1334A I2S decoder - MCLK not needed?

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    8

    Teensy 4 with UDA1334A I2S decoder - MCLK not needed?

    I've endeavoured to search the forum but couldn't find a direct answer to this.

    Is there any reason why the Teensy audio library wouldn't work with the UDA1334A I2S decoder? I'm thinking specifically the Adafruit I2S Stereo Decoder UDA1334A breakout board, which I've used successfully with an RPi. Unlike the SGTL5000, this board doesn't require an MCLK input as I believe it generates it's own MCLK from BCLK.

    If I adopt the following pin connections, is that going to cause any problems with a Teensy 4 or any of the audio library tutorials (I appreciate I'll have to replace any functionality which references the SGTL5000 control object)?

    UDA1334A pin connections:

    VIN - 3.3V - 5V
    GND - GND
    DIN - OUT1A on Teensy 4 (pin 7)
    WSEL - LRCLK1 on Teensy 4 (pin 20)
    BCLK - BCLK1 on Teensy 4 (pin 21)
    MCLK1 on Teensy 4 (pin 23) can be left disconnected

    Many thanks.

  2. #2
    Junior Member
    Join Date
    Nov 2018
    Posts
    18
    I'm running the uda1334 with teensy 3.6 without connecting MCLK and it's running fine. I think it would work out the same with T4.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    8
    Quote Originally Posted by Frassil View Post
    I'm running the uda1334 with teensy 3.6 without connecting MCLK and it's running fine. I think it would work out the same with T4.
    Thanks very much for the reply. Would you be able to share your specific Teensy 3.6 connection setup and a sample sketch that works?

    I've tried with both a Teensy 3.6 and Teensy 4.0 using the test code reproduced below (it's basically the standard Teensy Audio Tutorial but using an IR remote as actuator rather than push buttons and pots). The code works fine using the Teensy 3.6 DAC as output, and also using the Teensy SGTL5000 I2S Audio Shield (Rev3), but if I configure it for I2S output to the UDA1334 using the pinouts indicated I get nothing. I'm also finding the USB connection always drops out and I can't get any Serial debug output. Am I missing some kind of UDA1334 initialisation command(s) here equivalent to an AudioShield.enable() routine - I can't see anything obvious in the datasheet?

    Any help gratefully received.

    Code:
    /*
      Teensy Audio Library test of different audio outputs:
    
      a) I2S (e.g. UDA1334A breakout board or Teensy Audio Shield)
      b) USB
      c) Teensy 3.6 built-in DAC
    
      Based on Teensy Audio Library SamplePlayer example, but using
      Elegoo IR Keypad and TSOP38238 IR Receiver as actuator
    
      UDA1334A Connections:
        VIN - 3.3V on Teensy
        GND - GND on Teensy
        DIN - OUT1A on Teensy (pin 7)
        WSEL - LRCLK1 on Teensy (pin 20)
        BCLK - BCLK1 on Teensy (pin 21)
        MCLK1 on Teensy (pin 23) can be left disconnected
    
      Teensy 3.6 DAC Connections:
        Audio output - DAC0 (pin 21) on Teensy
    
      TSOP38238 Connections:
      TSOP38238 module with curved face forward, from left to right:
        Pin1 (Signal) - pin 2 on Teensy
        Pin2 (GND) - GND on Teensy
        Pin3 (VCC) - 3.3V on Teensy
    
    */
    
    //#define DACOUT
    //#define I2SOUT_SGTL5000
    #define I2SOUT_UDA1334
    //#define USBOUT // if using USB out, set Tools...USB Type to 'Audio'
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <IRremote.h>
    #include "IRElegoo.h"
    
    // WAV files converted to code by wav2sketch
    #include "AudioSampleSnare.h"        // http://www.freesound.org/people/KEVOY/sounds/82583/
    #include "AudioSampleTomtom.h"       // http://www.freesound.org/people/zgump/sounds/86334/
    #include "AudioSampleHihat.h"        // http://www.freesound.org/people/mhc/sounds/102790/
    #include "AudioSampleKick.h"         // http://www.freesound.org/people/DWSD/sounds/171104/
    #include "AudioSampleGong.h"         // http://www.freesound.org/people/juskiddink/sounds/86773/
    #include "AudioSampleCashregister.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
    
    // 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
    
    #define IRRECV_PIN       2
    #define LED_PIN          LED_BUILTIN
    
    // Create the IR Receiver
    //
    IRrecv irrecv(IRRECV_PIN);
    decode_results results;
    
    // Create the Audio components.  These should be created in the
    // order data flows, inputs/sources -> processing -> outputs
    //
    AudioPlayMemory    sound0;
    AudioPlayMemory    sound1;  // six memory players, so we can play
    AudioPlayMemory    sound2;  // all six sounds simultaneously
    AudioPlayMemory    sound3;
    AudioPlayMemory    sound4;
    AudioPlayMemory    sound5;
    AudioPlaySdWav     wav1;
    AudioMixer4        mix1;    // two 4-channel mixers are needed in
    AudioMixer4        mix2;    // tandem to combine 6 audio sources
    AudioAmplifier     amp1;
    #if defined(I2SOUT_SGTL5000)
    AudioOutputI2S     audio;
    #elif defined(I2SOUT_UDA1334)
    AudioOutputI2S     audio;
    #elif defined(USBOUT)
    AudioOutputUSB     audio;
    #elif defined(DACOUT)
    AudioOutputAnalog  audio;
    #endif
    
    // Create Audio connections between the components
    //
    AudioConnection c1(sound0, 0, mix1, 0);
    AudioConnection c2(sound1, 0, mix1, 1);
    AudioConnection c3(sound2, 0, mix1, 2);
    AudioConnection c4(sound3, 0, mix1, 3);
    AudioConnection c5(mix1, 0, mix2, 0);   // output of mix1 into 1st input on mix2
    AudioConnection c6(sound4, 0, mix2, 1);
    AudioConnection c7(sound5, 0, mix2, 2);
    AudioConnection c8(wav1, 0, mix2, 3);
    AudioConnection c9(mix2, amp1);
    AudioConnection c10(amp1, 0, audio, 0);
    AudioConnection c11(amp1, 0, audio, 1);
    
    #if defined(I2SOUT_SGTL5000)
    AudioControlSGTL5000 audioShield;
    #endif
    
    float vol = 1.0;
    bool pwr = true;
    
    void setup() {
    
      Serial.begin(9600);
      irrecv.enableIRIn();
      pinMode(LED_PIN, OUTPUT);
      AudioMemory(10);
    
      // Setup built-in SD card reading
      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");
          delay(500);
        }
      }
    
      // Turn on the audio shield output
    #if defined(I2SOUT_SGTL5000)
      audioShield.enable();
      audioShield.volume(0.5);
    #endif
    
      // Reduce the gain on mixer channels, so more than 1
      // sound can play simultaneously without clipping
      mix1.gain(0, 0.4);
      mix1.gain(1, 0.4);
      mix1.gain(2, 0.4);
      mix1.gain(3, 0.4);
      mix2.gain(1, 0.4);
      mix2.gain(2, 0.4);
      mix2.gain(3, 0.4);
      amp1.gain(1.0);
    
    }
    
    void loop() {
    
      if (irrecv.decode(&results)) {
    
        switch (results.value) {
          case BTN_0:
            //Serial.println("Snare");
            sound0.play(AudioSampleSnare);
            break;
          case BTN_1:
            //Serial.println("TomTom");
            sound1.play(AudioSampleTomtom);
            break;
          case BTN_2:
            //Serial.println("HiHat");
            sound2.play(AudioSampleHihat);
            break;
          case BTN_3:
            //Serial.println("Kick");
            sound3.play(AudioSampleKick);
            break;
          case BTN_4:
            //Serial.println("Gong");
            sound4.play(AudioSampleGong);
            break;
          case BTN_5:
            //Serial.println("Cash Register");
            sound5.play(AudioSampleCashregister);
            break;
          case BTN_6:
            //Serial.println("WAV file on SD card");
            wav1.play("SDTEST1.WAV");
            break;
          case BTN_7:
            //Serial.println("WAV file on SD card");
            wav1.play("SDTEST2.WAV");
            break;
          case BTN_8:
            //Serial.println("WAV file on SD card");
            wav1.play("SDTEST3.WAV");
            break;
          case BTN_9:
            //Serial.println("WAV file on SD card");
            wav1.play("SDTEST4.WAV");
            break;
          case BTN_VINC:
            //Serial.println("Volume up");
            if (vol < 1.0) {
              vol += 0.1;
              amp1.gain(vol);
            }
            break;
          case BTN_VDEC:
            //Serial.println("Volume down");
            if (vol > 0.0) {
              vol -= 0.1;
              amp1.gain(vol);
            }
            break;
          case BTN_FNC:
            //Serial.println("Stop all playback");
            sound0.stop();
            sound1.stop();
            sound2.stop();
            sound3.stop();
            sound4.stop();
            sound5.stop();
            wav1.stop();
            break;
          case BTN_PWR:
            pwr = !pwr;
            digitalWrite(LED_PIN, pwr); // used to provide visual check of IR connectivity
            break;
          default:
            // Serial.println("Unknown button");
            break;
        }
    
        irrecv.resume();
    
      }
    
    }
    Last edited by semucon; 10-11-2019 at 12:35 AM.

  4. #4
    Junior Member
    Join Date
    Nov 2018
    Posts
    18
    From what i can recall, your wiring seems correct. I can't right now check my wiring but can reply latter about that.
    How long wires to do you have between the UDA1334 and the Teensy? They should be as short as possible!

  5. #5
    Junior Member
    Join Date
    Oct 2017
    Posts
    8
    Quote Originally Posted by Frassil View Post
    From what i can recall, your wiring seems correct. I can't right now check my wiring but can reply latter about that.
    How long wires to do you have between the UDA1334 and the Teensy? They should be as short as possible!
    Thanks again.

    In terms of the code, do I take it there's no need for any additional board initialisation or control class instantiation with the UDA1334 and Teensy Audio Library? You just wire up the DIN, BCLK and WSEL (LRCLK) and away you go?

    In terms of wiring, I appreciate the need to keep I2S and SPI wires as short as possible. I don't have much experience with Arduino I2S devices but have used SPI OLED displays extensively and know that standard breadboard fly leads won't always cut it. I've tried various configurations for testing purposes:
    1. Teensy 3.2 with Teensy Audio Shield/SD card reader connected via rigid male/female PCB headers - this works perfectly.
    2. Teensy 3.6 & inbuilt SD card reader and Teensy Audio Shield (i.e. no SPI to audio shield) and 4cm breadboard fly leads - works fairly reliably.
    3. Teensy 3.6 with Teensy Audio Shield/SD card reader and 4cm fly leads - works intermittently (SPI seems to be more of a problem than I2S).
    4. Teensy 4.0 with Teensy Audio Shield/SD card reader and 4cm fly leads - works intermittently.
    5. Teensy 3.2, 3.6 or 4.0 and UDA1334 board with 4cm fly leads - no joy (no audio or response at all), and USB connection always drops out after program is loaded.


    Obviously I'd be using a rigidly soldered configuration in any final jig, but I'd like to confirm if the UDA1334 board works with the Teensy Audio Library first.

    FYI I have managed to get the UDA1334 board working (to a fashion) with a clone Arduino Zero (SAMD21) board using this resource: https://tigoe.github.io/SoundExamples/i2s.html, but the Teensy hardware and audio library are obviously vastly superior.

  6. #6
    Junior Member
    Join Date
    Oct 2017
    Posts
    8
    For anyone interested, turns out it was a (well documented) PC/USB issue, not an audio library issue . I reinstalled the latest stable Teensyduino 1.48 (I think I was on a beta for IDE 1.8.10 before) and everything works perfectly now with the UDA1334A board and Teensy 3.2, 3.6 and 4.0 using the code and pinouts indicated above.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •