Library conflicts

I am trying to use 1.5 inch OLED display and a keypad together, I am getting a conflict between keypad and one or more library's used for the display. They are SPI.h, Adafruit_GFX.h or Adafruit_SSD1351.h When I use earther separately they work fine but together the keypad will not work at all.

Please post your full sketch that doesn’t work.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click the “Reply” button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link that will allow you to make the attachment.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

//==========================================//Wire
#include <Wire.h>												//Include library for Wire communication of the clock

//==========================================//Globlel Variables

int ticks;														//
int currentTemp;												//Current Temperature Variable
int setTemp;													//Set Temperature Variable
int currentHum;													//Current Humidity Variable
int select = 0;													//Users Selection Variable

//==========================================//Slide Switch
#define S_SWITCH1 A7
#define S_SWITCH2 A6

//==========================================//Clock 1307RTC
#include <RTC.h>												//Includes library for real time clock
static DS1307 rtc;
#define DS1307 0x68

//==========================================//SSD1351 Display
#include "SPI.h"												//Includes library for SPI communication of  the display
#include "Adafruit_GFX.h"										//Includes core graphics library
#include "Adafruit_SSD1351.h"									//Includes hardware specific library


											//screen dimensions
#define SCREEN_WIDTH 128										//pixel width
#define SCREEN_HEIGHT 128										//pixel height

											//pin definitions
#define SCLK_PIN 13	//YELLOW									//defines serial clock pin
#define DC_PIN    5	//GREEN										//defines master-in slave-out pin
#define MOSI_PIN 11	//BLUE										//defines master-out slave-in SDA pin   
//#define RST_PIN  -1	//No Wire								//defines reset pin uses arduino reset       
#define CS_PIN    4	//ORANGE									//defines chip select pin  

											// Colour definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF
#define GREY            0x8410
#define ORANGE          0xE880
											//Display Object
Adafruit_SSD1351 ssd = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, -1);

//==========================================//DHT11 Temperature Sensor
#include <DHT_U.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>

																//Uncomment the type of sensor in use
#define DHT_TYPE DHT11											//DHT11
//#define DHT_TYPE DHT22										//DHT22 (AM2302)
//#define DHT_TYPE DHT21										//DHT21 (AM2301)
#define DHT_PIN	A0												//Digital pin 4 connected to the DHT sensor

DHT dht(DHT_TYPE, DHT_PIN);										//DHT Sensor object

//==========================================//Relay
#define RELAY A1													//Relay connected to digital pin 5

//==========================================//Control buttons
#include <Keypad.h>
#include <Key.h>

const byte Row = 5;												//1 buttons in 5 rows
const byte Col = 1;												//5 buttons in 1 columns																	
char PushButton[Row][Col] =										//Dfine the symbols on buttons
{
	{'1'},														//Arrow up button
	{'2'},														//Arrow down button
	{'A'},														//Set button
	{'B'},														//Hold button
	{'C'}														//Run button
};
byte RowPins[Row] = { 10,9,8,7,6 };							//Each buton is connected to it's own row pin
byte ColPins[Col] = { 12};										//All buttons connected to the column pin
Keypad Buttons = Keypad(makeKeymap(PushButton), RowPins, ColPins, Row, Col);								//Initialize an instance of class

//==========================================//Setup
void setup()
{
	Serial.begin(9600); delay(50);
	Wire.begin(); delay(50);
	
	ssd.begin();
	ssd.fillScreen(YELLOW);

	ssd.setCursor(0, 0);
	ssd.setTextColor(GREEN);
	ssd.setTextSize(2);
	ssd.print("Doug Cindy");
}

//==========================================//Loop
void loop()
{
	char button = Buttons.getKey();
	if (button)
	{
		Serial.println(button);
	}
}

Which Arduino board are you using?

The Nano

OK, so the problem is that you're using pin 12 for the keypad, but this is also one of the SPI pins.

I haven't looked at the Keypad library, but you are also restricted in what you can do with pin 10 while using SPI. The best approach would be to use pin 10 as CS_PIN for your SSD1351.

More information here:
https://www.arduino.cc/en/reference/SPI

Thank you I will try that.

I tried what you told me but it didn't work. The pin placement doesn't work with the display either. I
tried the sketch both ways. Thank you very much for your help, I would appreciate any thoughts you may have.

This sketch does not work.

/*
 Name:		Display_1.ino
 Created:	8/22/2020 11:56:27 AM
 Author:	doug_
*/

/* This is a test to display an RGB bitmap from a picture file to
 *  be displayed onto a 1.5" 128x128 pixel OLED SS1351 screen.
 *  Contact tylerovens@me.com if you have any questions
 */

 //included libraries
#include "SPI.h" //Includes library for SPI communication of display
#include "Adafruit_GFX.h" //Includes core graphics library
#include "Adafruit_SSD1351.h" //Includes hardware specific library

extern const uint16_t Smily48[];
extern const uint16_t Fire_48[];

//screen dimensions
#define SCREEN_WIDTH 128 //pixel width
#define SCREEN_HEIGHT 128 //pixel height

//pin definitions
#define SCLK_PIN 13		//YELLOW    //defines s clock pin						  
#define DC_PIN   12		//GREEN		//defines master-in slave-out pin             
#define MOSI_PIN 11		//BLUE		//defines master-out slave-in SDA pin
#define CS_PIN  10		//ORANGE	//defines chip select pin 
//#define RST_PIN   3		//defines reset pin or -1                 WHITE or No White

                    

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF
#define GREY            0x8410
#define ORANGE          0xE880

Adafruit_SSD1351 ssd = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, -1); //-1 insted of pin 3

void setup() {
	ssd.begin();
	ssd.fillScreen(RED);

	ssd.setCursor(0, 0);
	ssd.setTextColor(RED);
	ssd.setTextSize(2);
	ssd.print("Doug");
}

void loop() {
	

}

This Sketch will work. The only difference is the pin placement.

/*
 Name:		Display_1.ino
 Created:	8/22/2020 11:56:27 AM
 Author:	doug_
*/

/* This is a test to display an RGB bitmap from a picture file to
 *  be displayed onto a 1.5" 128x128 pixel OLED SS1351 screen.
 *  Contact tylerovens@me.com if you have any questions
 */

 //included libraries
#include "SPI.h" //Includes library for SPI communication of display
#include "Adafruit_GFX.h" //Includes core graphics library
#include "Adafruit_SSD1351.h" //Includes hardware specific library

extern const uint16_t Smily48[];
extern const uint16_t Fire_48[];

//screen dimensions
#define SCREEN_WIDTH 128 //pixel width
#define SCREEN_HEIGHT 128 //pixel height

#define SCLK_PIN 13		//YELLOW    //defines s clock pin						  
#define DC_PIN    5		//GREEN		//defines master-in slave-out pin             
#define MOSI_PIN 11		//BLUE		//defines master-out slave-in SDA pin
#define CS_PIN    4		//ORANGE	//defines chip select pin 
//#define RST_PIN   3		//defines reset pin or -1                 WHITE or No White

// Color definitions
#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0  
#define WHITE           0xFFFF
#define GREY            0x8410
#define ORANGE          0xE880

Adafruit_SSD1351 ssd = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, -1); //-1 insted of pin 3

void setup() {
	ssd.begin();
	ssd.fillScreen(RED);

	ssd.setCursor(0, 0);
	ssd.setTextColor(RED);
	ssd.setTextSize(2);
	ssd.print("Dougl");
}

void loop() {
	
}

I think this is the problem:

doug_army:

#define DC_PIN   12		//GREEN		//defines master-in slave-out pin

Pin 12 is the SPI MISO pin. You can't use it for DC. Use another free pin for DC and leave pin 12 unused.