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

Thread: Teensy 4: No Blink or sound for Tutorial Part 1 05 'Do More While Playing'

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    2

    Teensy 4: No Blink or sound for Tutorial Part 1 05 'Do More While Playing'

    Hi

    I'm working through the audio board tutorial using a Teensy 4 and have stumbled at Part 1 05 'Do More While Playing'.

    The code below is a simplification of the 1.05 sketch that isolates the problem - that is: I can either play the sound -or- I can blink. But I can't do both!

    If I comment out the
    Code:
    pinMode(13, OUTPUT); // LED on pin 13
    , the sound will play. If I comment out the block starting
    Code:
    if (playSdWav1.isPlaying() == false) {...}
    the LED will blink, but I cannot play and blink together.

    Am I missing something obvious?

    Code:
    // Advanced Microcontroller-based Audio Workshop
    //
    // http://www.pjrc.com/store/audio_tutorial_kit.html
    // https://hackaday.io/project/8292-microcontroller-audio-workshop-had-supercon-2015
    // 
    // Part 1-3: First "Hello World" program, play a music file
    //
    // WAV files for this and other Tutorials are here:
    // http://www.pjrc.com/teensy/td_libs_AudioDataFiles.html
    
    #include <Audio.h>
    #include <Wire.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;
    
    // 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
    
    // Use these for the SD+Wiz820 or other adaptors
    //#define SDCARD_CS_PIN    4
    //#define SDCARD_MOSI_PIN  11
    //#define SDCARD_SCK_PIN   13
    
    elapsedMillis blinkTime;
    
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(8);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.2);
      SPI.setMOSI(SDCARD_MOSI_PIN);
      SPI.setSCK(SDCARD_SCK_PIN);
      if (!(SD.begin(SDCARD_CS_PIN))) {
        while (1) {
          Serial.println("Unable to access the SD card");
          delay(500);
        }
      }
      //Comment this line out, audio plays from SD card
      pinMode(13, OUTPUT); // LED on pin 13
      delay(2000);
    }
    
    void loop() {
    
      //Comment this block out and LED will blink.
      if (playSdWav1.isPlaying() == false) {
        Serial.println("Start playing");
        playSdWav1.play("SDTEST2.WAV");
        delay(10); // wait for library to parse WAV info
      }
      // do nothing while playing...
      // blink the LED without delays
      if (blinkTime < 250) {
        digitalWrite(13, LOW);
      } else if (blinkTime < 500) {
        digitalWrite(13, HIGH);
      } else {
        blinkTime = 0; // start blink cycle over again
      }
    
      
    }

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,490
    T_4 uses pin 13 for SCK - so pin blink needs to move to another pin and supplied LED.

    Is this a T_4.0 with a Rev D Audio board? Rev C or before won't work on T_4

    If so then the SPI for SD card needs to be these lines commented:
    Code:
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    Check the PJRC Audio card page to confirm - the T_4.0 with Rev D can use standard pins IIRC - but the page will indicate that for sure in the appropriate table.

  3. #3
    Junior Member
    Join Date
    May 2020
    Posts
    2
    Thanks for the reply - I noticed the pin changes for SCK on between Rev C and Rev D (I'm using Rev D) but the SD card worked with CS/MOSI/SCK pins as per Rev C but on Rev D, so I kinda went with it!

    I've now updated to:
    Code:
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    as per the specs here https://www.pjrc.com/store/teensy3_audio.html

    but I guess that means the on board LED is always off limits if using the SD card on Teesny4/Rev D?

    Quick follow up, just to improve my understanding: do you know why the SD card still worked with the old config?
    Last edited by greycells; 05-19-2020 at 11:10 PM. Reason: missing '/'

Posting Permissions

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