4X4 Keypad Input Display Through OLED

In this tutorial basically we’re going to learn how to take input from keypad and show it on our desired OLED display. For this i would suggest you see my other tutorials as prerequisite Keypad Tutorial and OLED Display Tutorial

If you miss these tutorial you might not be able to do this.

Step 1: Working With the Oled DIsplay

Working With the Oled DIsplay
lib add.png
libinc.png
keylib2.png
FB5H28CIE7J5E55.MEDIUM.jpg

Including Library:

Both libraries below needs to be installed before you are able to continue with this instructable.
https://github.com/adafruit/Adafruit_SSD1306 (SSD1306 library)

https://github.com/adafruit/Adafruit_SSD1306 (GFX library)

The connections from the display:

VCC to arduino 5v GND to arduino GND SCL to arduino pin A5 SDA to arduino pin A4

Library Correction :

For Adafruit_SSD1306 Library:
Go to: C:\Program Files (x86)\Arduino\libraries\Adafruit_SSD1306 Open Adafruit_SSD1306.h (in a text editor like Notepad++ for example) Find and comment out the line: #define SSD1306_128_32 Uncomment the line: #define SSD1306_128_64 Open the ssd1306_128x64_i2c example in Arduino: Change address from 0x3D to 0x3C in void setup()

Step 2: Connecting the Keypad and Oled With Arduino

Connecting the Keypad and Oled With Arduino
GuWTi.png
keypad.png

Connecting keypad with aruduino digital pins:

keypadv

Keypad Pin Connects to Arduino Pin

1                              D9

2                              D8

3                              D7

4                              D6

5                              D5

6                              D4

7                              D3

8                              D2

Connecting OLED with aruduino Analog pins:

VCC to arduino 5v GND to arduino GND SCL to arduino pin A5 SDA to arduino pin A4.

Step 3: Uploading Code…

Heres the code….

#include <SPI.h>
#include <Wire.h>
#include <Keypad.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16

static const unsigned char PROGMEM logo16_glcd_bmp[] = { B00000000, B11000000, B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011, B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111, B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111, B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000, B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error(“Height incorrect, please fix Adafruit_SSD1306.h!”);
#endif

const byte numRows= 4; //number of rows on the keypad
const byte numCols= 4; //number of columns on the keypad

char keymap[numRows][numCols]=
{
{‘1’, ‘2’, ‘3’, ‘A’},
{‘4’, ‘5’, ‘6’, ‘B’},
{‘7’, ‘8’, ‘9’, ‘C’},
{‘*’, ‘0’, ‘#’, ‘D’}
};

 

byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

 

void setup() {

Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128×64) // init done // Show image buffer on the display hardware.

display.display(); //delay(2000);

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(10, 0);

display.clearDisplay();

display.println(“INPUT YOUR TEXT HERE: “);

// invert the display

display.invertDisplay(true);

display.invertDisplay(false);

display.display();

display.clearDisplay(); }

void loop() {

while (1) {

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(10, 0);

display.clearDisplay();

display.println(“input:”);

printText();

display.display();

}

}

void printText(void) {

String s;

char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
Serial.print(keypressed);
display.println(keypressed);

display.display();

display.println(“\n”);
}
delay(4000);

}

 

0.96 OLED Display With Arduino & Getting Text From Serial Monitor

Now we start to work with 0.96′ OLED Display with arduino and we will try to display

text from the serial monitor input…

 

FTV56SDJ48PTOPH.LARGE

 

In this tutorial i will show you how to connect and test and write some data from serial monitor to a 0.96″ i2c OLED display module to an arduino.

 

Parts:

 

Breadboard and hookup wires Arduino The OLED i2c display

The connections from the display:

VCC to arduino 5v GND to arduino GND SCL to arduino pin A5 SDA to arduino pin A4

Both libraries below needs to be installed before you are able to continue with this instructable.

Step 2: Correction in Library N Code..

For Adafruit_SSD1306 Library:

Go to: C:\Program Files (x86)\Arduino\libraries\Adafruit_SSD1306 Open Adafruit_SSD1306.h (in a text editor like Notepad++ for example)

Find and comment out the line: #define SSD1306_128_32 Uncomment the line: #define SSD1306_128_64

Open the ssd1306_128x64_i2c example in Arduino:

Change address from 0x3D to 0x3C in void setup()

 

 

From examples go to adafruit SSD1306 upload the 3rd sketch.

Step 4: Getting Text From Serial Monitor to OLED Display…

Here is my code :

 

#include <SPI.h>

#include <Wire.h>

 

#include <Adafruit_GFX.h>

 

#include <Adafruit_SSD1306.h>

#define OLED_RESET 4

Adafruit_SSD1306 display(OLED_RESET);

#define NUMFLAKES 10

#define XPOS 0

#define YPOS 1

#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16

#define LOGO16_GLCD_WIDTH 16

static const unsigned char PROGMEM logo16_glcd_bmp[] = { B00000000, B11000000, B00000001, B11000000, B00000001, B11000000, B00000011, B11100000, B11110011, B11100000, B11111110, B11111000, B01111110, B11111111, B00110011, B10011111, B00011111, B11111100, B00001101, B01110000, B00011011, B10100000, B00111111, B11100000, B00111111, B11110000, B01111100, B11110000, B01110000, B01110000, B00000000, B00110000 };

 

#if (SSD1306_LCDHEIGHT != 64)

#error(“Height incorrect, please fix Adafruit_SSD1306.h!”);

#endif

 

void setup() {

Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128×64) // init done // Show image buffer on the display hardware.

display.display(); //delay(2000);

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(10, 0);

display.clearDisplay();

display.println(“INPUT YOUR TEXT HERE: “);

display.invertDisplay(true);

display.invertDisplay(false);

display.display();

display.clearDisplay(); }

 

void loop() {

while (1) {

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(10, 0);

display.clearDisplay();

display.println(“input:”);

printText();

display.display();

}

}

 

void printText(void) {

String s;

if (Serial.available()) {

s = Serial.readString(); //getting string input in variable “s”

display.println(s);

display.display();

display.println(“\n”);

}

delay(4000);

}

 

You will find the arduino .Ino file in the link below…

Instructables

Blog Spot

FB Page