LCD Keypad Shield on Wemos D1 R2

I’ve got an Arduino UNO R3 equipped and a LCD Keypad Shield.
Since I work mostly on WiFi enabled project I just tried to run this
LCD Shield on Wemos D1 R2 and faced some issues which I could solve.

To reduce the IO number, the LCD Keypad shield use a voltage divider for all keys to determine which key is pressed and one analog output for all keys.

The shield is supplied by 5V Input, so I checked the voltage of the divider.
Each Key has a different pull-down resistor which would result in a different voltage and the highest would be if no key is pressed. I could measure 5V on A0 pin. This would be differently too much for the Wemos. ESP8266 ADC input is limited to 1V, so the Wemos is also equipped witch a voltage divider, but Wemos expects the max input of 3.3V. Here we have to make sure that we apply a voltage which is not higher than 3.3V. A 3K3 resistor between A0 and GND would be the best solution and provide a maximum output of ~3V which is ok for the Wemos.

The other part is just to make sure the IO configuration for the Wemos fits and you may include the “Wire” library if you get some compiler errors, see the code below.

#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <ESP8266WiFi.h>
// Wemos IO mapping
#define D0    3
#define D1    1
#define D2    16
#define D3    5
#define D4    4
#define D5    0
#define D6    2
#define D7    14
#define D8    12
#define D9    13
#define D10   15

// Create LDC instance
LiquidCrystal lcd(D8, D9, D4, D5, D6, D7);

// key defines 
#define KEY_RIGHT         	0
#define KEY_UP            	1
#define KEY_DOWN          	2
#define KEY_LEFT          	3
#define KEY_SELECT        	4
#define KEY_NOT_PRESSED   	5
#define KEY_ANALOG_TRESHOLD 50

byte PressedKey = KEY_NOT_PRESSED;

void setup()
{
  lcd.begin(16, 2); 
  lcd.setCursor(0,0); 
  lcd.print("Engsta.com");
}

int GetKeyValue()
{
  int ADCVal = 0;
  ADCVal = analogRead(A0); 

  if (ADCVal > 900 + KEY_ANALOG_TRESHOLD)   return KEY_NOT_PRESSED;
  if (ADCVal < 10  + KEY_ANALOG_TRESHOLD)   return KEY_RIGHT;
  if (ADCVal < 200 + KEY_ANALOG_TRESHOLD)   return KEY_UP;
  if (ADCVal < 400 + KEY_ANALOG_TRESHOLD)   return KEY_DOWN;
  if (ADCVal < 550 + KEY_ANALOG_TRESHOLD)   return KEY_LEFT;
  if (ADCVal < 750 + KEY_ANALOG_TRESHOLD)   return KEY_SELECT;
 
  return KEY_NOT_PRESSED; 
}

void loop()
{

	lcd.setCursor(0,1); 
	PressedKey = GetKeyValue();
	
	  switch (PressedKey) 
	  {
		  case KEY_RIGHT: {	 
			  lcd.print("RIGHT          "); 
			  break;
		  }
		  case KEY_LEFT:  {
			  lcd.print("LEFT           "); 
			  break;
		  }
		  case KEY_UP: {
			  lcd.print("UP             ");
			  break;
		  }
		  case KEY_DOWN: {
			  lcd.print("DOWN           ");
			  break;
		  }
		  case KEY_SELECT:{
			  lcd.print("SELECT         ");
			  break;
		  }
		  case KEY_NOT_PRESSED:{
			  break;
		  }

		  default:
		  break;
		} 
		delay(50);
}

 

Click to rate this post!
[Total: 1 Average: 5]

One thought on “LCD Keypad Shield on Wemos D1 R2”

  1. Thanks so much!

    This post, help me alot to understand some configurations that was not working before I read.

    Congratulations by the knowledge shared.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.