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

Thread: Distorted sound and no peak level on TFT while trying tutorial Part_3_03_TFT_Display

  1. #1

    Distorted sound and no peak level on TFT while trying tutorial Part_3_03_TFT_Display

    I soldered an Audio Adapter Board on top of a Teensy 3.5, and the whole thing on top of an Adafruit Perma Proto board. Then I hooked up the same TFT as used in the tutorial (Color 320x240 Display, 2.2 inch, ILI9341 Controller, without Touch screen, https://www.pjrc.com/store/display_ili9341.html) I play WAV files from the onboard SD card.

    In the tutorial Part_3_03_TFT_Display the sound suffers from distortion. The TFT shows "Peak Meter" and the Serial interface shows all the peak measurements (ranges 0.11-0.99), but the values and the jumping rectangles are not being shown on the TFT.

    For the connection between the Teensy and TFT screen I used 10" wires. I already tried unhooking the TFT screen, still a distorted sound. I cut off the wires, I will try shorter ones tomorrow. Still a distorted sound.

    Just now I tried the tutorial Part_1_03_Playing_Music and the sound is good. Also Part_3_01_Peak_Detection gives a good sound quality, even with the #defines for the TFT inserted. So it must be the rest of the code, which has not been changed by me. (Later this weekend I will test what happens when I delete the instructions for drawing and writing.)

    Any ideas? Thanks!

    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 3-3: Add a TFT Display
    
    #include <ILI9341_t3.h>
    #include <font_Arial.h> // from ILI9341_t3
    
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioPlaySdWav           playSdWav1;     //xy=227,71
    AudioAnalyzePeak         peak1;          //xy=418,176
    AudioAnalyzePeak         peak2;          //xy=443,238
    AudioOutputI2S           i2s1;           //xy=686,160
    AudioConnection          patchCord1(playSdWav1, 0, peak1, 0);
    AudioConnection          patchCord2(playSdWav1, 0, i2s1, 0);
    AudioConnection          patchCord3(playSdWav1, 1, peak2, 0);
    AudioConnection          patchCord4(playSdWav1, 1, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=664,964
    // GUItool: end automatically generated code
    
    #define TFT_DC      20
    #define TFT_CS      21
    #define TFT_RST    255  // 255 = unused, connect to 3.3V
    #define TFT_MOSI     7
    #define TFT_SCLK    14
    #define TFT_MISO    12
    ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
    
    
    // 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
    
    void setup() {
      Serial.begin(9600);
      delay(500);
      tft.begin();
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_YELLOW);
      tft.setFont(Arial_24);
      //tft.setTextSize(3);
      tft.setCursor(40, 8);
      tft.println("Peak Meter");
      
      AudioMemory(10);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.5);
      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);
        }
      }
      delay(1000);
    }
    
    elapsedMillis msecs;
    
    void loop() {
      if (playSdWav1.isPlaying() == false) {
        Serial.println("Start playing");
        //playSdWav1.play("SDTEST1.WAV");
        //playSdWav1.play("SDTEST2.WAV");
        playSdWav1.play("SDTEST3.WAV");
        //playSdWav1.play("SDTEST4.WAV");
        delay(10); // wait for library to parse WAV info
      }
      
      if (msecs > 15) {
        if (peak1.available() && peak2.available()) {
          msecs = 0;
          float leftNumber = peak1.read();
          float rightNumber = peak2.read();
          Serial.print(leftNumber);
          Serial.print(", ");
          Serial.print(rightNumber);
          Serial.println();
    
          // draw the verticle bars
          int height = leftNumber * 240;
          tft.fillRect(60, 280 - height, 40, height, ILI9341_GREEN);
          tft.fillRect(60, 280 - 240, 40, 240 - height, ILI9341_BLACK);
          height = rightNumber * 240;
          tft.fillRect(140, 280 - height, 40, height, ILI9341_GREEN);
          tft.fillRect(140, 280 - 240, 40, 240 - height, ILI9341_BLACK);
          // a smarter approach would redraw only the changed portion...
    
          // draw numbers underneath each bar
          tft.setFont(Arial_14);
          tft.fillRect(60, 284, 40, 16, ILI9341_BLACK);
          tft.setCursor(60, 284);
          tft.print(leftNumber);
          tft.fillRect(140, 284, 40, 16, ILI9341_BLACK);
          tft.setCursor(140, 284);
          tft.print(rightNumber);
        }
      }
    }

  2. #2
    Also with shorter wires the sound is bad.

    Interesting: after commenting all tft actions in the loop, there is no sound at all, while there are still peak levels in the serial.
    After uncommenting one tft action in the loop, there is the distorted sound again.
    Commenting all tft actions in both loop and setup delivers proper sound.

    I tried putting the TFT to pins 0 and 1 (MOSI1/MISO1) but the program wouldn't run. Probably stuck somewhere in the TFT library.

Posting Permissions

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