Trouble getting a UNO to work with 1306 OLED LCD display & SD Card Module

Hi,

I am trying to use a UNO with an 1306 OLED LCD display in conjunction with an SD card module.

Both work fine separately with test code but when I merge the code together the display wont work. Are these not compatible?

Any help appreciated…

https://www.ebay.com.au/itm/0-96-I2C-IIC-Serial-128X64-128-64-Blue-OLED-LCD-LED-Display-Module-Hot/202698047598?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

Code is below

// --------------------------------------------------------
//  Needed for Display
//
#include <SPI.h>              
#include <Wire.h>            
#include <Adafruit_GFX.h>    
#include <Adafruit_SSD1306.h> 
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

long lastTime = 0;
long minutes = 0;
long hours = 0;
long trig_minutes = 2;
long trig_hours = 0;

#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH  16 

#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
//
// ---------------------------------------------------------
//
//
// SD Card Parameters
//
#include <ThreeWire.h>  
#include "SD.h" //SD Card Library
#include "TMRpcm.h" //Audio Library
#include "SPI.h" //SD SPI library
#define SD_ChipSelectPin 4 //Chip select is pin number 4
#define countof(a) (sizeof(a) / sizeof(a[0]))
TMRpcm play_audio; 
ThreeWire myWire(8,2,10); // IO, SCLK, CE
//
// ---------------------------------------------------------
//
//
//
// 
//
void setup(){

    //
    // Needed to wake up Audio with Test Ding...
    //
    play_audio.speakerPin = 9;  // Audio Out on pin 9
    play_audio.play("ring5.wav");
    Serial.println("DING on Power Up");
    delay (50);
    play_audio.stopPlayback(); 
  
    //
    // SD Card Initialization
    //
    Serial.begin(9600);         //Serial COM for debugging
    if (!SD.begin(SD_ChipSelectPin)) 
      {
      Serial.println("SD fail");
      return;
      }

    //
    // Display Initialization
    //
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
    display.clearDisplay();

    //
    // Define IO Lines
    //
    pinMode(3, INPUT_PULLUP);   // Handset Onhook/Offhook Detection
    pinMode(7, INPUT_PULLUP);   // Manual Trigger Button
    pinMode(6, INPUT);          // Button to Increment Minutes
    pinMode(5, INPUT);          // Button to Increment Hours
    
    //
    // Initial Text on Serial Terminal
    //
    Serial.println("    ---  TEST ---");
    delay (1000);

}





void loop () 
{
        
 
    //
    // Start Timer
    //
    if(millis()-lastTime > 60000)
    {
      minutes++;
      lastTime = millis();
    }
    
    if(minutes > 59)
      {
      hours++;
      minutes = 0;
      }
   
    display.display();
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println("PHONE SIMULATOR");
    display.setCursor(0,12);
    display.println("ELAPSED:");
    display.setCursor(52,12);
    display.println(hours);
    display.setCursor(68,12);
    display.println(minutes);
    Serial.println(minutes);
    display.setCursor(0,22);
    display.println("TRIGGER:");
    display.setCursor(52,22);
    display.println(trig_hours);
    display.setCursor(68,22);
    display.println(trig_minutes);

    //
    // Check if timer = preset hour & minute settings
    //
    if ((minutes == trig_minutes) and (hours == trig_hours))
      {
        display.clearDisplay();
        display.setCursor(20,12);
        display.println("RINGING");
        Serial.println("Bingo !  Time Triggered");
        Audio_Ringer();
      }


}




void Audio_Ringer()

//
// **********************************
// *                                *
// *       Play Audio Routine       *
// *                                *
// **********************************
//

{
      digitalWrite(6, LOW);
      
a:    play_audio.play("ring5.wav");       // Play Ring File
      Serial.println("RING RING");        // Update Serial Display
      display.clearDisplay();             // 
      display.setCursor(20,12);           // Update I2C Display
      display.println("RINGING");         //
 
a1:   Serial.println("RING LOOP");
      if (digitalRead(3)==LOW)              // Handset has been Lifted
        {
        play_audio.stopPlayback();    
        play_audio.play("x-files.wav");     // Play Msg 
        
a2:     Serial.println("PLAYING MSG");      // Update Serial Display
        display.clearDisplay();             // 
        display.setCursor(20,12);           // Update I2C Display
        display.println("PLAYING MSG");     //
        
        if (digitalRead(3)==HIGH)
          {
          Serial.println("STOP PLAYING MSG");
          display.clearDisplay();             

          play_audio.stopPlayback();  
          delay (7000);
          goto a;
          }
        goto a2;
                 
      }
      if (digitalRead(7)==LOW) 
        {
        goto a;
        }
      goto a1;
  }

Hi,

I am trying to use a UNO with an 1306 OLED LCD display in conjunction with an SD card module.

Both work seperately with test code but when I merge the code display wont work.  Ar ethese not compatible?



https://www.ebay.com.au/itm/0-96-I2C-IIC-Serial-128X64-128-64-Blue-OLED-LCD-LED-Display-Module-Hot/202698047598?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

https://www.ebay.com.au/itm/For-Arduino-New-Micro-SD-Storage-Board-Mciro-SD-TF-Card-Memory-Shield-Module-SPI/391599342659?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649

Code is below
#define OLED_RESET 4
#define SD_ChipSelectPin 4 //Chip select is pin number 4

I don't think that you can use pin 4 for both.

groundFungus:

#define OLED_RESET 4

#define SD_ChipSelectPin 4 //Chip select is pin number 4




I don't think that you can use pin 4 for both.

OK.
Sorry I am not really sure what these two lines of code even do, can I just use another pin?
I don't even have anything connected to pin 4?

Pin 4 is a usual pin for the SD chip select. Leave that as it is and change the OLED_RESET to a different pin.

I don't even have anything connected to pin 4?

Is that a question? How do I know what you have connected?

Can you make those links clickable? Makes life simpler on mobiles.

If either or both of those are plug on shields, pin 4 may well be in use by either or both. Pin 4 is certainly the chip select pin of choice for SD modules.

groundFungus:
Pin 4 is a usual pin for the SD chip select. Leave that as it is and change the OLED_RESET to a different pin.

OK, thanks, will try that but whats confusing me is the OLED display doesnt have a CS pin, there is no connection.

groundFungus:
Is that a question? How do I know what you have connected?

It was a statement as I was confused because I didnt even have a connection on pin 4, but in double checking I see my wire had just fallen off.

But still really confused about the #define OLED_RESET 4 line, this is an I2C display, there is no reset pin...

I tried moving CS for the SD card to pin 3 which has got me past the SD card error i was getting but now no loop code will run, the program just freezes...

By working backwards commenting out bits of code I have found the line (#include "TMRpcm.h" //Audio Library) is whats stopping everything, if I comment this out my timer displays on the display.

Any ideas where I go from here?

Thanks