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

Thread: SPI Problem? - Sharing SD Card and TFT Display

  1. #1

    SPI Problem? - Sharing SD Card and TFT Display

    Edit: Think I've been looking at this wrong. Think I need to somehow merge the Adafruit library and Teensy Audio library so they are not competing for the SPI bus. I'll amend my problem/question: Should I try to use the TFT in 8-bit mode instead? Or should I work on getting the SD card and TFT to both work on SPI? Whichever is easier.

    Hello all,

    Need some assistance. Am I misunderstanding how SPI works?

    Background:
    I have a Teensy 3.6, which worked with a 3.5" TFT (Adafruit) when connected (mini-grabbers for temporary tests) alone. I disconnected the TFT, have since soldered the Audio Shield to the Teensy, and got it working with wav files on the SD card. I am now having problems trying to re-connect the TFT and get it to play nice with the SD card.

    Here's the main issue: TFT functions (fillscreen, printIn, etc) all work in the Setup() of my code UP UNTIL the lines that activate the SD Card, and then nothing works.
    Code:
      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);
        }
      }
    I was under the impression that MOSI, MISO and SCK could be shared between multiple devices. Is this not the case? Do I need to define separate MOSI, MISO and SCK lines for my TFT? Relevant lines of code below:
    Code:
    //These are 'flexible' lines that can be changed
    #define TFT_CS 21 //ALTERNATE (Default 10)
    #define TFT_DC 20 //ALTERNATE (Default 9)
    #define TFT_RST -1 // RST can be set to -1 if you tie it to Arduino's reset
    
    // Use these with the Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    
    Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, 7, 14, TFT_RST, 12);
    Thanks for any advice.
    Last edited by ragemachine; 05-02-2018 at 03:57 AM.

  2. #2
    Junior Member
    Join Date
    Oct 2016
    Posts
    17
    Look at:
    https://forum.pjrc.com/threads/29356...k-rates-n-such

    The devices on the SPI bus share MOSI MISO but not chip select lines and sometimes have different comms speeds/formats. I am having issues with a Wiznet and a TFT display and am hoping the above thread will assist me...

    Good Luck

    Simon

  3. #3
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,599
    Some SPI chips donít release the MISO line and thats where the problem is. most of the time if you run one code with one device it works, switch to other code and other device same port, works, its that. youll need a tristate buffer to fix that kind of problem.

    fortunately teensy 3.6 has 3 SPI ports, so you can put them on a different bus as well.

  4. #4
    Quote Originally Posted by tonton81 View Post
    Some SPI chips don’t release the MISO line and thats where the problem is. most of the time if you run one code with one device it works, switch to other code and other device same port, works, its that. youll need a tristate buffer to fix that kind of problem.

    fortunately teensy 3.6 has 3 SPI ports, so you can put them on a different bus as well.
    Since I have no idea how I would implement a tri-state buffer, I think I'll try your other suggestion first and use a separate port.

  5. #5
    Quote Originally Posted by SimonWakley View Post
    Look at:
    https://forum.pjrc.com/threads/29356...k-rates-n-such

    The devices on the SPI bus share MOSI MISO but not chip select lines and sometimes have different comms speeds/formats. I am having issues with a Wiznet and a TFT display and am hoping the above thread will assist me...

    Good Luck

    Simon
    Question on this... If I use separate SPI buses, as suggested below, would I just need to define each bus one time (probably in the setup)? That thread seems to state that if you use one bus, you need to constantly reconfigure the SPI port as you switch between which device you want to communicate with.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,445
    Alternate SPI bus setup is to unique hardware and settings. Making an instance and setup of each should be independent in function where each would be used normally without interference.

    Even on the same bus with transaction interface it seems that would be handled for each device as it is accessed once setup and configuration are done.

    Easy to confirm - set up each in turn and have them working - then merge to usage of both devices.

  7. #7
    So I moved the TFT to the SPI2 port. Changed the HX8357 code to reflect the new pins:
    Code:
    Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, 44, 46, TFT_RST, 45);
    I'm at the point again where the wav player and TFT each work... but only if one is defined in the code at a time. I don't quite understand how to define the separate SPI buses, particularly since I am using various pre-packaged libraries that presumably are trying to do that for me.

    Anyone able to point me in the right direction? Full code dump below:
    Code:
    #include <SPI.h>
    #include "Adafruit_GFX.h" // Core graphics library
    #include "Adafruit_HX8357.h"
    #include "Adafruit_SPITFT.h" // Hardware-specific library
    #include <Fonts/FreeSansBold12pt7b.h>
    #include <Bounce.h>
    #include <Audio.h>
    #include <Wire.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    Bounce button1 = Bounce(24, 15); //Pin number, debounce time.
    Bounce button2 = Bounce(25, 15); //15 = 15 ms debounce time
    Bounce button3 = Bounce(27, 15);
    Bounce button4 = Bounce(28, 15);
    Bounce button5 = Bounce(29, 15);
    Bounce button6 = Bounce(30, 15);
    Bounce button7 = Bounce(31, 15);
    Bounce button8 = Bounce(32, 15);
    
    // GUItool: begin automatically generated code
    AudioPlaySdWav           playSdWav1;     //xy=138,160
    AudioPlaySdWav           playSdWav2;     //xy=146,263
    AudioInputI2S            i2s2;           //xy=148,353
    AudioMixer4              mixer1;         //xy=366,207
    AudioMixer4              mixer2;         //xy=366,296
    AudioOutputI2S           i2s1;           //xy=563,257
    AudioConnection          patchCord1(playSdWav1, 0, mixer1, 0);
    AudioConnection          patchCord2(playSdWav1, 1, mixer2, 0);
    AudioConnection          patchCord3(playSdWav2, 0, mixer1, 1);
    AudioConnection          patchCord4(playSdWav2, 1, mixer2, 1);
    AudioConnection          patchCord5(i2s2, 0, mixer1, 2);
    AudioConnection          patchCord6(i2s2, 1, mixer2, 2);
    AudioConnection          patchCord7(mixer1, 0, i2s1, 0);
    AudioConnection          patchCord8(mixer2, 0, i2s1, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=362,444
    // GUItool: end automatically generated code
       
    //46, 45, 44 SCK, MISO, MOSI
    //These are 'flexible' lines that can be changed
    #define TFT_CS 43 //ALTERNATE (Default 10)
    #define TFT_DC 54 //ALTERNATE (Default 9)
    #define TFT_RST -1 // RST can be set to -1 if you tie it to Arduino's reset (Was set to 8)
    #define WHITE    0xFFFF
    #define BLACK    0x0000
    
    // Use these with the Teensy Audio Shield
    #define SDCARD_CS_PIN    10
    #define SDCARD_MOSI_PIN  7
    #define SDCARD_SCK_PIN   14
    // 0x4B is the default i2c address
    #define MAX9744_I2CADDR 0x4B
    
    int thevol = 31;
    int mgain = 18;
    int brtness = 25;
    
    int YGridPos = 2;
    int XGridPos = 2;
    int YGridPosPrev = 2;
    int XGridPosPrev = 2;
    int stringnum = 1;
    
    int TextHeight = 23;
    int CatHeight = 25;
    int Row1Height = 98;
    int Row2Height = 97;
    
    const char* cellstrings[]={
      "-", //Null Row 1, 0
      "-", //Null Row 1, 1
      "-", //Null Row 1, 2
      "-", //Null Row 1, 3
      "-", //Null Row 1, 4
      "-", //Null Row 2, 5
      "Cell1", //File 1 - Row 2, Col 2, #6
      "Cell2", //File 2 - Row 2, Col 3, #7
      "Cell3", //File 3 - Row 2, Col 4, #8
      "-", //Null Row 2
      "-", //Null Row 3
      "Cell4", //File 4 - Row 3, Col 2, #11
      "Cell5", //File 5 - Row 3, Col 3, #12
      "Cell6", //File 6 - Row 3, Col 4, #13
      "-", //Null Row 3
      "-", //Null Row 4
      "Cell7", //File 17 - Row 4, Col 2, #16
      "Cell8", //File 18 - Row 4, Col 3, #17
      "Cell9", //File 19 - Row 4, Col 4, #18
      "-", //Null Row 4
      "-", //Null Row 5
      "-", //Null Row 5
      "-", //Null Row 5
      "-", //Null Row 5
      "-", //Null Row 5
    };
    
    const char* CatStrings[]={
      "-",
      "Cat1",
      "Cat2",
      "Cat3",
      "-",
    };
    
    // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
    //Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
    
    // SoftSPI - note that on some processors this might be *faster* than hardware SPI!
    //Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
    Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, 44, 46, TFT_RST, 45);
    //SPISettings TFTSPI(1000000, MSBFIRST, SPI_MODE0);   // 1Mhz? Mode 0, 1, 2 or 3?
    
    void setup() {
      Serial.begin(9600);
      Serial.println("Begin");
      
      Wire.begin();
      
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.8);
      sgtl5000_1.inputSelect(AUDIO_INPUT_MIC); //Select mic source for audio shield
      sgtl5000_1.micGain(mgain); //Set initial gain. Range 0-63dB.
      
      //Turn off ADC high pass filter to reduce noise level
      sgtl5000_1.adcHighPassFilterDisable();
      
      pinMode(35, OUTPUT); //PWM Output
      
      pinMode(24, INPUT_PULLUP); //PUSH-TO-TALK Button
      pinMode(25, INPUT_PULLUP); //STOP
      pinMode(27, INPUT_PULLUP); //PLAY
      
      pinMode(28, INPUT_PULLUP); //PRESS 5-Way Switch - Settings Screen
      pinMode(29, INPUT_PULLUP); //RIGHT Nav Screen
      pinMode(30, INPUT_PULLUP); //LEFT Nav Screen
      pinMode(31, INPUT_PULLUP); //DOWN Nav Screen
      pinMode(32, INPUT_PULLUP); //UP Nav Screen
    
      // TFT Screen Setup
      tft.begin(HX8357D);
      tft.setRotation(3);
      tft.setFont(&FreeSansBold12pt7b);
      tft.setTextColor(WHITE);  
      tft.setTextSize(1);
      tft.fillScreen(BLACK);
      tft.drawFastVLine(159, 0, 319, WHITE);
      tft.drawFastVLine(320, 0, 319, WHITE);
      tft.drawFastHLine(0, (CatHeight), 479, WHITE);
      tft.drawFastHLine(0, (CatHeight+Row1Height+1), 479, WHITE);
      tft.drawFastHLine(0, (CatHeight+Row1Height+Row2Height+2), 479, WHITE);
      
      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);
        }
      }
    
     //Manually define TFT SPI settings?
     //SPI2.setMOSI(44);
     //SPI2.setMISO(45);
     //SPI2.setSCK(46);
     //SPI2.begin(); 
     //delayMicroseconds(100000);
    
      tft.setCursor(0, (TextHeight));
      tft.println("PLACEHOLDER");
    }
    
    void loop() {
    
    button1.update(); //Read bounced buttons
    button2.update();
    button3.update();
    button4.update();
    button5.update();
    button6.update();
    button7.update();
    button8.update();
    
      if (button8.fallingEdge()) { //UP
        Serial.println("UP");
        if ((YGridPos = 1)) {} //Do nothing if YPos is already min (1)
          else {
            YGridPos = YGridPos - 1;
          }
        }
    
      if (button7.fallingEdge()) { //DOWN
        Serial.println("DOWN");
        if ((YGridPos = 3)) {} //Do nothing if YPos is already max (3)
          else {
            YGridPos = YGridPos + 1;
          }
        }
    
      if (button6.fallingEdge()) { //LEFT
        Serial.println("LEFT");
        if ((XGridPos = 1)) {} //Do nothing if XPos is already min (1)
          else {
            XGridPos = XGridPos - 1;
          }
        }
    
      if (button5.fallingEdge()) { //RIGHT
        Serial.println("RIGHT");
        if ((XGridPos = 3)) {} //Do nothing if XPos is already max (3)
          else {
            XGridPos = XGridPos + 1;
          }
        }
    
      if (button4.fallingEdge()) { //PRESS
        Serial.println("PRESS");
          settingsMenu();
          YGridPosPrev = 0; //Fake change to force screen re-draw
          XGridPosPrev = 0;
      }
    
      if (button3.fallingEdge()) {
        Serial.println("PLAY");
        if (playSdWav1.isPlaying() == 1) {
          if (playSdWav2.isPlaying() == 1) {}
          else {
          playFile1("TEST1.WAV");  // filenames are always uppercase 8.3 format
          Serial.println("TEST1.WAV");
          } 
        } 
        else {
          playFile2("TEST2.WAV");
          Serial.println("TEST2.WAV");
        }
      }
    
      if (button2.fallingEdge()) {
        Serial.println("STOP");
        if (playSdWav2.isPlaying() == 1) { //If Wav2 is playing...
          playSdWav2.stop();
          Serial.println("STOP2");
        }
        else if (playSdWav1.isPlaying() == 1) {
          playSdWav1.stop();
          Serial.println("STOP1");
        }
      }
    
      //if (digitalRead(26) == LOW) {
      //  Serial.println("MIC ACTIVATE");
      //  MicPTT();
      //  mixer1.gain(0, 0.5);
      //  mixer1.gain(1, 0.5);
      //  mixer1.gain(2, 0);
      //  mixer2.gain(0, 0.5);
      //  mixer2.gain(1, 0.5);
      //  mixer2.gain(2, 0);
      //}
      
      if ((YGridPos == YGridPosPrev) & (XGridPos == XGridPosPrev)){
      Serial.println("No change X or Y");
      }
      //Increment "no change" counter? Display YoRHa bitmap? bmpDraw(bmpfilename, x, y); (24-bit BMP)
      else {
        Serial.println("Refresh screen");
        //tft.fillScreen(BLACK);
        tft.fillRect(0, 0, 480, 320, BLACK);
        tft.drawFastVLine(159, 0, 319, WHITE);
        tft.drawFastVLine(320, 0, 319, WHITE);
        Serial.println("CatHeight");
        Serial.println(CatHeight);
        Serial.println("RowHeight1");
        Serial.println(Row1Height);
        Serial.println("RowHeight2");
        Serial.println(Row2Height);
        tft.drawFastHLine(0, (CatHeight), 479, WHITE);
        tft.drawFastHLine(0, (CatHeight+Row1Height+1), 479, WHITE);
        tft.drawFastHLine(0, (CatHeight+Row1Height+Row2Height+2), 479, WHITE);
      
        if ((XGridPos == XGridPosPrev)){}
        else {
          //tft.fillRect(0, 0, 158, (CatHeight-1), BLACK);
          //tft.fillRect(160, 0, 319, (CatHeight-1), BLACK);
          //tft.fillRect(321, 0, 479, (CatHeight-1), BLACK);
          tft.setCursor(0, (TextHeight));
          tft.println(CatStrings[(XGridPos-1)]);
          Serial.println("CatStrings X-1: ");
          Serial.println(CatStrings[(XGridPos-1)]);
          tft.setCursor(160, (TextHeight));
          tft.println(CatStrings[(XGridPos)]);
          tft.setCursor(321, (TextHeight));
          tft.println(CatStrings[(XGridPos+1)]);
        }
      
        stringnum = ((YGridPos * 5) + XGridPos);
        //tft.fillRect(0,(CatHeight+1), 158,(CatHeight+Row1Height), BLACK);
        //tft.fillRect(0,(CatHeight+Row1Height+2), 158,(CatHeight+Row1Height+Row2Height+1), BLACK);
        //tft.fillRect(0,(CatHeight+Row1Height+Row2Height+3), 158, 319, BLACK);
        //tft.fillRect(160, (CatHeight+1), 319, (CatHeight+Row1Height), BLACK);
        //tft.fillRect(160, (CatHeight+Row1Height+2), 319, (CatHeight+Row1Height+Row2Height+1), BLACK);
        //tft.fillRect(160, (CatHeight+Row1Height+Row2Height+3), 319, 319, BLACK);
        //tft.fillRect(321, (CatHeight+1), 479, (CatHeight+Row1Height), BLACK);
        //tft.fillRect(321, (CatHeight+Row1Height+2), 479, (CatHeight+Row1Height+Row2Height+1), BLACK);
        //tft.fillRect(321, (CatHeight+Row1Height+Row2Height+3), 479, 319, BLACK);
        
        tft.setCursor(0, (CatHeight+TextHeight+1));
        tft.println(cellstrings[(stringnum - 6)]);
        tft.setCursor(160, (CatHeight+TextHeight+1));
        tft.println(cellstrings[(stringnum - 5)]);
        tft.setCursor(321, (CatHeight+TextHeight+1));
        tft.println(cellstrings[(stringnum - 4)]);
        
        tft.setCursor(0, (CatHeight+Row1Height+TextHeight+2));
        tft.println(cellstrings[(stringnum - 1)]);
        tft.setCursor(160, (CatHeight+Row1Height+TextHeight+2));
        tft.println(cellstrings[(stringnum)]);
        tft.setCursor(321, (CatHeight+Row1Height+TextHeight+2));
        tft.println(cellstrings[(stringnum + 1)]);
        
        tft.setCursor(0, (CatHeight+Row1Height+Row2Height+TextHeight+3));
        tft.println(cellstrings[(stringnum + 4)]);
        tft.setCursor(160, (CatHeight+Row1Height+Row2Height+TextHeight+3));
        tft.println(cellstrings[(stringnum + 5)]);
        tft.setCursor(321, (CatHeight+Row1Height+Row2Height+TextHeight+3));
        tft.println(cellstrings[(stringnum + 6)]);
      
      }
      //Serial.println("X, Y, Prevs");
      //Serial.println(XGridPos);
      //Serial.println(YGridPos);
      //Serial.println(XGridPosPrev);
      //Serial.println(YGridPosPrev);
      YGridPosPrev = YGridPos;
      XGridPosPrev = XGridPos;
      //Serial.println("X, Y, Prevs");
      //Serial.println(XGridPos);
      //Serial.println(YGridPos);
      //Serial.println(XGridPosPrev);
      //Serial.println(YGridPosPrev);
      delay(500);
    }
    
    void settingsMenu() {
      Serial.println("SettingsMenu");
      tft.fillScreen(BLACK);
    
      //Set Text Size?
      //Print Settings Labels
      tft.setCursor(45, 154);
      tft.println("VOL 0-63");
      tft.setCursor(183, 154);
      tft.println("BRT 25-255");
      tft.setCursor(345, 154);
      tft.println("MIC 0-63");
    
      //Print current settings values
      tft.setCursor(77, 194);
      tft.println(thevol);
      tft.setCursor(227, 194);
      tft.println(brtness);
      tft.setCursor(377, 194);
      tft.println(mgain);
      
      //Draw Triangle vol up/down indicators. x0,y0 = left, x1,y1 = top/bottom point, x2,y2 = right corner.
      //void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
      //void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
      tft.fillTriangle(29, 99, 89, 19, 149, 99, WHITE); //Up and down arrows (6 total, white with black fill)
      tft.fillTriangle(179, 99, 239, 19, 299, 99, WHITE);
      tft.fillTriangle(329, 99, 389, 19, 449, 99, WHITE);
      tft.fillTriangle(29, 219, 89, 299, 149, 219, WHITE);
      tft.fillTriangle(179, 219, 239, 299, 299, 219, WHITE);
      tft.fillTriangle(329, 219, 389, 299, 449, 219, WHITE);
    
      tft.fillTriangle(32, 97, 89, 22, 146, 97, BLACK); //Black fill in white triangles
      tft.fillTriangle(182, 97, 239, 22, 296, 97, BLACK);
      tft.fillTriangle(332, 97, 389, 22, 446, 97, BLACK);
      tft.fillTriangle(32, 221, 89, 296, 146, 221, BLACK);
      tft.fillTriangle(182, 221, 239, 296, 296, 221, BLACK);
      tft.fillTriangle(332, 221, 389, 296, 446, 221, BLACK);
      
      int settingsSelect = 2;
      //Draw initial box around middle option
      tft.drawRect(179, 119, 120, 80, WHITE);
      
    while (digitalRead(28) == HIGH) {
      Serial.println("WHILE LOOP");
      delay(500);
     
      button4.update();
      button5.update();
      button6.update();
      button7.update();
      button8.update();
      
      if (settingsSelect > 3) { //Keep value in bounds in case of craziness
        settingsSelect = 3;
      }
      if (settingsSelect < 1) {
        settingsSelect = 1;
      }
    
      if (button8.fallingEdge()) { //UP
        Serial.println("UP");
        if (settingsSelect == 1) {
          if (thevol == 63) {}
          else {
            thevol = thevol + 1;
            setvolume(thevol);
            tft.fillRect(75, 159, 50, 37, BLACK);
            tft.setCursor(77, 194);
            tft.println(thevol);
          }
        }
        else if (settingsSelect == 2) {
          if (brtness == 255) {} //0-255 PWM
          else {
            brtness = brtness + 5;
            analogWrite(35, brtness);
            tft.fillRect(225, 159, 50, 37, BLACK);
            tft.setCursor(227, 194);
            tft.println(brtness);
    
          }
        }
        else if (settingsSelect == 3) {
          if (mgain == 63) {}
          else {
            mgain = mgain + 1;
            sgtl5000_1.micGain(mgain);
            tft.fillRect(375, 159, 50, 37, BLACK);
            tft.setCursor(377, 194);
            tft.println(mgain);
      
          }
        }
      }
    
      if (button7.fallingEdge()) { //DOWN
        Serial.println("DOWN");
        if (settingsSelect == 1) {
          if (thevol == 0) {}
          else {
            thevol = thevol - 1;
            setvolume(thevol);
            tft.fillRect(75, 159, 50, 37, BLACK);
            tft.setCursor(77, 194);
            tft.println(thevol);
          }
        }
        else if (settingsSelect == 2) {
          if (brtness == 25) {} //25 is about ~10% brightness (0-255)
          else {
            brtness = brtness - 5;
            analogWrite(35, brtness);
            tft.fillRect(225, 159, 50, 37, BLACK);
            tft.setCursor(227, 194);
            tft.println(brtness);
          }
        }
        else if (settingsSelect == 3) {
          if (mgain == 0) {}
          else {
            mgain = mgain - 1;
            sgtl5000_1.micGain(mgain);
            tft.fillRect(375, 159, 50, 37, BLACK);
            tft.setCursor(377, 194);
            tft.println(mgain);
          }
        }
      }
    
      if (button6.fallingEdge()) { //LEFT
        Serial.println("LEFT");
        if (settingsSelect == 1) {} //Do nothing if farthest left (Vol)
          else {
           Serial.println("CLEAR/REDRAW RECT");
             
           if (settingsSelect == 2) {
             tft.fillRect(179, 119, 120, 80, BLACK);
             tft.setCursor(183, 154);
             tft.println("BRT 25-255");
             tft.setCursor(227, 194);
             tft.println(brtness);
             tft.drawRect(29, 119, 120, 80, WHITE);
             settingsSelect = settingsSelect - 1;
           }
           else {
             tft.fillRect(329, 119, 120, 80, BLACK);
             tft.setCursor(345, 154);
             tft.println("MIC 0-63");
             tft.setCursor(377, 194);
             tft.println(mgain);
             tft.drawRect(179, 119, 120, 80, WHITE);
             settingsSelect = settingsSelect - 1;
           }
           //tft.drawRect((29 + (150 * settingsSelect)), 119, 120, 80, BLACK); //Black-out current box
           //settingsSelect = settingsSelect - 1;
           //tft.drawRect((29 + (150 * settingsSelect)), 119, 120, 80, WHITE); //Draw new box
          }
        }
    
      if (button5.fallingEdge()) { //RIGHT
        Serial.println("RIGHT");
    
      
      
        if (settingsSelect == 3) {} //Do nothing if farthest right (Mic Gain)
          else {
           Serial.println("CLEAR/REDRAW RECT");
           if (settingsSelect == 1) {
             tft.fillRect(29, 119, 120, 80, BLACK);
             tft.setCursor(45, 154);
             tft.println("VOL 0-63");
             tft.setCursor(77, 194);
             tft.println(thevol);
             tft.drawRect(179, 119, 120, 80, WHITE);
             settingsSelect = settingsSelect + 1;
           }
           else {
             tft.fillRect(179, 119, 120, 80, BLACK);
             tft.setCursor(183, 154);
             tft.println("BRT 25-255");
             tft.setCursor(227, 194);
             tft.println(brtness);
             tft.drawRect(329, 119, 120, 80, WHITE);
             settingsSelect = settingsSelect + 1;
           }
           //tft.drawRect((29 + (150 * settingsSelect)), 119, 120, 80, BLACK); //Black-out current box
           //settingsSelect = settingsSelect + 1;
           //tft.drawRect((29 + (150 * settingsSelect)), 119, 120, 80, WHITE); //Draw new box
          }
        }
        
      }
      //Reset Text Size?
    }
    
    boolean setvolume(int v) {
      // cant be higher than 63 or lower than 0
      if (v > 63) v = 63;
      if (v < 0) v = 0;
      
      Serial.print("Setting volume to ");
      Serial.println(v);
      Wire.beginTransmission(MAX9744_I2CADDR);
      Wire.write(v);
      if (Wire.endTransmission() == 0) 
        return true;
      else
        return false;
    }
    
    void playFile1(const char *filename)
    {
      Serial.print("Playing file: ");
      Serial.println(filename);
    
      // Start playing the file.  This sketch continues to
      // run while the file plays.
      playSdWav1.play(filename);
    
      delay(5);
    
    }
    
    void playFile2(const char *filename)
    {
      Serial.print("Playing file: ");
      Serial.println(filename);
    
      playSdWav2.play(filename);
    
      delay(5);
    
    }
    
    void MicPTT() {
      while (digitalRead(24) == LOW) {
        mixer1.gain(0, 0.33);
        mixer1.gain(1, 0.33);
        mixer1.gain(2, 0.33);
        mixer2.gain(0, 0.33);
        mixer2.gain(1, 0.33);
        mixer2.gain(2, 0.33);
        Serial.println("MIC ON");
        delay(500);
      }
    }
    Last edited by ragemachine; 05-03-2018 at 04:38 PM.

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    8,464
    Are you using the sd card on t3.6? If so it is on its own buss and typically you don’t use spi

  9. #9
    Quote Originally Posted by KurtE View Post
    Are you using the sd card on t3.6? If so it is on its own buss and typically you don’t use spi
    DOUBLE EDIT: I am dumb. I somehow deleted the AudioMemory(8); line of code from my main sketch.

    It is now working using the SD Card slot on the Teensy 3.6. I'll have to come back to this some day and battle with SPI some more, but I am very pleased to have this all working now. Thanks for help and suggestions for a noob, everyone.

    Edit: Hm. Using the Teensy 3.6 SD card slot and running the WavFilePlayer example with this defined works:
    Code:
    // 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
    But if I move those definitions to my code, it does not play.

    I think I have some other problem here... not sure why my sound files would not be playing.
    Last edited by ragemachine; 05-03-2018 at 05:57 PM.

  10. #10
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    183
    Suppose I do have a bad actor on the SPI. Would it be possible to re-wire its' bad MISO line to the alternate MISO line on the Teensy to avoid the bus contention, without having to wire in an extra tri-state buffer? Would I have to re-start the SPI (repeatedly) to make use of the changing status of the main and alternate pins? Agree it is slight insanity to keep changing the bus settings, but it seems like it would help me get beyond the contention problem while prototyping.

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,599
    you can dynamically change the MISO pin to the ALT pin or back anytime you want using setMISO(pin)

    Tony

Posting Permissions

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