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

Thread: teensy 4 + audio rev d, tutorial issues?

  1. #1
    Junior Member
    Join Date
    Feb 2020

    teensy 4 + audio rev d, tutorial issues?

    I have just started with teensy, have been looking at the audio tutorial. This largely appears to be written as for earlier version. I have managed many of the examples, mostly with success. (At the same time as getting my setup organised!)

    sdcard play is working and playing all files., but the two examples for "blink while playing" seem to stick at initial play of the first file. Question is:- are these known to work, or is it possibly not something I am doing? Is it possible I have an incorrect (wrong or too early version) of teensyduino?

    If the examples are known to work on teensy 4 then I will look again at my setup, etc...
    Cannot see anything in the forum relevant to teensy 4 and audio board revD


  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Indeed, the audio tutorial was written (and the video created) in late 2015. That was before Teensy 4.0 or even Teensy 3.5 and 3.6 existed.

    Yes, that's expected because the SD card is using pin 13 on Rev D with Teensy 4.0. Controlling that pin for LED blinking will interfere with access to the card.

    The Rev C audio shield uses pin 14 for the SD card clock.

  3. #3
    Junior Member
    Join Date
    Feb 2020
    Thanks for the quick answer - I will try modifying the code....

    Awesome sound so far with such a small package.

    I hope to use the power of the "4" to try a selective hearing project, to select different frequencies and to try removing unwanted background music.

  4. #4
    Junior Member
    Join Date
    Feb 2020
    I modified the example so it works, I put a separate LED on out3. It works, so I believe I changed the address for sd card correctly:-

    // Advanced Microcontroller-based Audio Workshop
    // Part 1-5: Respond to Pushbuttons & Volume Knob
    // Modified for teensy 4.0 and audio shield
    // Do more while playing.  Monitor pushbuttons and adjust
    // the volume.  Whe the buttons are pressed, stop playing
    // the current file and skip to the next or previous.
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    #include <Bounce.h>
    AudioPlaySdWav           playSdWav1;
    AudioOutputI2S           i2s1;
    AudioConnection          patchCord1(playSdWav1, 0, i2s1, 0);
    AudioConnection          patchCord2(playSdWav1, 1, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;
    Bounce button0 = Bounce(0, 15);
    Bounce button2 = Bounce(2, 15);  // 15 = 15 ms debounce time
    // Use these with the Teensy Audio Shield rev D (I think! RR)
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  11
    #define SDCARD_SCK_PIN   13
    #define ledPin           3
    void setup() {
      if (!(SD.begin(SDCARD_CS_PIN))) {
        while (1) {
          Serial.println("Unable to access the SD card");
      pinMode(ledPin, OUTPUT);
      pinMode(0, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
    int filenumber = 0;  // while file to play
    const char * filelist[4] = {
    elapsedMillis blinkTime;
    void loop() {
      if (playSdWav1.isPlaying() == false) {
        const char *filename = filelist[filenumber];
        filenumber = filenumber + 1;
        if (filenumber >= 4) filenumber = 0;
        Serial.print("Start playing ");
        delay(10); // wait for library to parse WAV info
      // blink the LED without delays
      if (blinkTime < 250) {
        digitalWrite(ledPin, LOW);
      } else if (blinkTime < 500) {
        digitalWrite(ledPin, HIGH);
      } else {
        blinkTime = 0; // start blink cycle over again
      // read pushbuttons
      if (button0.fallingEdge()) {
        Serial.println("Button (pin 0) Press");
      if (button2.fallingEdge()) {
        Serial.println("Button (pin 2) Press");
        filenumber = filenumber - 2;
        if (filenumber < 0) filenumber = filenumber + 4;
      // read the knob position (analog input A2)
      int knob = analogRead(A2);
      float vol = (float)knob / 1280.0;
      //Serial.print("volume = ");

Posting Permissions

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