Ili9341_t3n and Audio library break each other

Status
Not open for further replies.

NaokiS

Member
Hi all,

Running into an issue with my program. I've traced it down to the ili9341_t3n and Audio library. Essentially using the updateScreenAsync when using a frame buffer will no long work when using the Audio library. Without calling any functions, having

Code:
// GUItool: begin automatically generated code
//AudioPlaySdWav           playSdWav1;     //xy=242,364
AudioPlayMemory          playMem1;       //xy=251,332
AudioMixer4              mixer1;         //xy=425,353
AudioOutputAnalogStereo  dacs1;          //xy=615,351
//AudioConnection          patchCord1(playSdWav1, 0, mixer1, 1);
//AudioConnection          patchCord2(playSdWav1, 1, mixer1, 2);
AudioConnection          patchCord3(playMem1, 0, mixer1, 0);
AudioConnection          patchCord4(mixer1, 0, dacs1, 0);
AudioConnection          patchCord5(mixer1, 0, dacs1, 1);
// GUItool: end automatically generated code

Will stop updates to the screen. Not sure if it's because Audio uses DMA too so it will cause issues. Or if it's even a problem I can solve. I checked the RAM and though the screen uses a good chunk of RAM, I still have a fair amount of ram (20%) left over.

Not sure if either Paul or KurtE know about this?

Thanks!
 
I will but the whole program is huge and a lot of functions that are not relevant here (not for audio nor screen). Will do so in a short time
 
I will but the whole program is huge and a lot of functions that are not relevant here (not for audio nor screen). Will do so in a short time

Can't you strip it down to the important parts? But it should work, so we that we can copy&paste it and try ..
 
This shows that updateScreen() works, but updateScreenAsync() no longer works. Removing all Audio.h stuff will let it work

Code:
// LCD Pins
#define TFT_DC      20
#define TFT_CS      21
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI    11
#define TFT_SCLK    14
#define TFT_MISO    12
// LCD LED
#define TFT_LED     22
#define TFT_DEFAULT_BRIGHTNESS 255

// Arduino/PlatformIO
#include "src/ILI9341_t3n.h"
#include <SPI.h>

uint16_t frame_buffer[320 * 240+32];
ILI9341_t3n tft(TFT_CS, TFT_DC);

#define USE_SDIO 1
#include <SD.h>

bool useSD = false;
File globalFile;

#include <Audio.h>
#include <SerialFlash.h>


// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=242,364
AudioPlayMemory          playMem1;       //xy=251,332
AudioMixer4              mixer1;         //xy=425,353
AudioOutputAnalogStereo  dacs1;          //xy=615,351
AudioConnection          patchCord1(playSdWav1, 0, mixer1, 1);
AudioConnection          patchCord2(playSdWav1, 1, mixer1, 2);
AudioConnection          patchCord3(playMem1, 0, mixer1, 0);
AudioConnection          patchCord4(mixer1, 0, dacs1, 0);
AudioConnection          patchCord5(mixer1, 0, dacs1, 1);
// GUItool: end automatically generated code

static void printOK() {
  tft.setTextColor(ILI9341_GREEN);
  tft.println("OK");
  tft.setTextColor(ILI9341_WHITE);
}

void printBad() {
  tft.setTextColor(ILI9341_RED);
  tft.println("BAD");
  tft.setTextColor(ILI9341_WHITE);
}

void setup() {
  bool fatal = false;

  // Serial debug
  Serial.begin(115200);
  
  // Setup LCD
  analogWriteResolution(8);
  analogWrite(TFT_LED, TFT_DEFAULT_BRIGHTNESS);
  tft.begin();
  tft.setRotation(4);
  tft.fillScreen(ILI9341_BLUE);
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLUE);
  tft.setTextSize(1);
  tft.setFrameBuffer(frame_buffer);
  tft.useFrameBuffer(true);

  // Lower the internal volume of the chimes
  mixer1.gain(0, 0.7);
  mixer1.gain(1, 0.7);
  mixer1.gain(2, 0.7);
  AudioMemory(4);

  int x = tft.getCursorX();
  int y = tft.getCursorY(); 

  /*
  serIntro();
  tft.println();
  tft.println(moduleType);
  tft.print("SW: "); tft.println(programVer);
  tft.print("HW: "); tft.println(moduleVer);
  tft.updateScreen();
  */
  
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
  tft.print("CAN: ");
  if (true) { // ACAN reports setup failures
    printBad();
    fatal = true;
  }
  else printOK();
  tft.updateScreen();

  // RTC
  tft.print("RTC: ");
    printOK();

  tft.print("SD:  ");
  if (!SD.begin(BUILTIN_SDCARD)) {  //sdcardCARD_CS_PIN
    printBad();
    fatal = true;
    useSD = false;
  } else {
    printOK();
    useSD = true;
    tft.print("JSON...");
    globalFile = SD.open("test.txt");
    if (globalFile) {
      printOK();
      // close the file:
      globalFile.close();
    } else {
      // if the file didn't open, print an error:
      printBad();
    }
  }
  tft.updateScreen();

  tft.println(F("Setup done."));
  tft.updateScreen();
  x = tft.getCursorX();
  y = tft.getCursorY();
  tft.fillRect(x, y, 255, 355, ILI9341_BLACK);
  tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
  if (fatal) {
    tft.setTextColor(ILI9341_RED);
    tft.println(F("Error occured during setup."));
    tft.setTextColor(ILI9341_WHITE);
  } else tft.println(F("Main loop() now."));
  tft.println(F("Start clock"));
  tft.println(F("End setup"));
  tft.updateScreenAsync();
  
}

void loop() {
  // put your main code here, to run repeatedly:
  tft.print("Test text after setup");
  tft.updateScreenAsync();
  delay(2000);
}
 
Which Teensy are you using?

Teensy 3.x with Audio Board Rev A to C uses pin 22 for Audio you use it for the LED.
Teensy 4.x with Audio Board Rev D uses pin 20, and 21 for Audio.. which are DC and CS in your program.

You can't use a pin for two things :)

The used pins are here:
https://www.pjrc.com/store/teensy3_audio.html

It's a Teensy 3.5
A21 and A22 are DAC 0 and DAC 1 respectively.
Pins 21 and 22 are A7 and A8, respectively.

Plus, to add to confusion... It could "sometimes" work, that is to say play the sample file whilst updating the screen. But maybe once or twice before the loop locked up.

EDIT: Waaaiiiit a minute. 21 and 22 is for the audio board right? I'm not using that, only the DACs. Or are they always used no matter what?
 
Changed the pins to the following, same result for me.

Code:
// LCD Pins
#define TFT_DC      10
#define TFT_CS      9
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI    11
#define TFT_SCLK    14
#define TFT_MISO    12
// LCD LED
#define TFT_LED     8
#define TFT_DEFAULT_BRIGHTNESS 255

EDIT:

And ones that do not touch any pins of the audio shield, stops working.
Code:
// LCD Pins
#define TFT_DC      21
#define TFT_CS      15
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI    11
#define TFT_SCLK    14
#define TFT_MISO    12
// LCD LED
#define TFT_LED     8
#define TFT_DEFAULT_BRIGHTNESS 255
 
Status
Not open for further replies.
Back
Top