One wire keypad error with ESP32 WROOM

It shouldn’t be the same. I updated it to handle 3.3v and 12-bit ADC for the ESP32 board.

which one ??

Is this one

OnewireKeypad_Final

??

It is showing this one

// Creator: Andrew Mascolo
//
//#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <OnewireKeypad.h>

char KEYS[] = {
  '1', '2', '3', 'A',
  '4', '5', '6', 'B',
  '7', '8', '9', 'C',
  '*', '0', '#', 'D'
};

//LiquidCrystal_I2C Lcd(0x20,20,4);
//OnewireKeypad <LiquidCrystal_I2C, 12> KP( Lcd, KEYS, 4, 3, A0, 4700, 1000 );

OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000 );

void setup () {
  Serial.begin(115200);

  //  Lcd.init();
  //  Lcd.backlight();

  // This method is set in the constructor with a default value of 5.0
  // You only need to include this method if your Arduino is not supplying 5v to
  // the keypad. ie. ~4.7v or even with 3.3v Arduino boards too.
  //KP.SetKeypadVoltage(5.0);
  KP2.SetKeypadVoltage(5.0);
}

void loop() {
  //  if( KP.Getkey() )
  //  {
  //    Lcd.clear();
  //    Lcd.home();
  //    Lcd.print( F( "KP: " ) );
  //    Lcd.setCursor(4,0);
  //    KP.LatchKey();
  //  }

  if ( char key = KP2.Getkey() ) {
    Serial << "Key: " << key << " State: ";
    switch (KP2.Key_State()) {
      case PRESSED:
        Serial.println("PRESSED");
        break;

      case RELEASED:
        Serial.println("RELEASED");
        break;

      case HELD:
        Serial.println("HOLDING");
        break;
    }
  }
}

I updated the library in general. Also that example sketch is now calculating the keypad with 5 volts instead of 3.3 volts that you should be using.

Remove the SetKeypadVoltage(5.0); line

The library should now detect that you are using an ESP32 board and set the analog range to 4095 and voltage to 3.3 automatically.

After updating the library, I have made changes in the code as per the error asked requirements and it is below

// Creator: Andrew Mascolo
//
//#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <OnewireKeypad.h>

char KEYS[] = {
  '1', '2', '3', 'A',
  '4', '5', '6', 'B',
  '7', '8', '9', 'C',
  '*', '0', '#', 'D'
};

//LiquidCrystal_I2C Lcd(0x20,20,4);
//OnewireKeypad <LiquidCrystal_I2C, 12> KP( Lcd, KEYS, 4, 3, A0, 4700, 1000 );

OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000 );

void setup () {
  Serial.begin(9600);

  //  Lcd.init();
  //  Lcd.backlight();

  // This method is set in the constructor with a default value of 5.0
  // You only need to include this method if your Arduino is not supplying 5v to
  // the keypad. ie. ~4.7v or even with 3.3v Arduino boards too.
  //KP.SetKeypadVoltage(5.0);
  KP2.setKeypadVoltage(5.0);
}

void loop() {
  //  if( KP.Getkey() )
  //  {
  //    Lcd.clear();
  //    Lcd.home();
  //    Lcd.print( F( "KP: " ) );
  //    Lcd.setCursor(4,0);
  //    KP.LatchKey();
  //  }

  if ( char key = KP2.getkey() ) {
    Serial << "Key: " << key << " State: ";
    switch (KP2.keyState()) {
      case PRESSED:
        Serial.println("PRESSED");
        break;

      case RELEASED:
        Serial.println("RELEASED");
        break;

      case HELD:
        Serial.println("HOLDING");
        break;
    }
  }
}



Now after getting read of alphabetical errors in scripting, the final error is here :-

errorMSG("Error. The Voltage must not be less than or equal to 0 or greater than " + SUPPLY_VOLTAGE);
^

exit status 1

Compilation error: exit status 1

I see the error you are talking about. The weird thing is I wasn't seeing it last night when I compiled it. I must not have saved changes when I compiled the example sketch.

fixing it now.

Oh OK :blush:

Actually I already tried removing the setkeypadvoltage line but getting same error there !!!

It has nothing to do whether the line is added or not

Well, let me know after all the updation process !!
Thanks

its fixed now.

OK le me go through that . .

With Your Newly updated Library this code below works with UNO and MEGA

// Creator: Andrew Mascolo
//
//#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <OnewireKeypad.h>

char KEYS[] = {
  '1', '2', '3', 'A',
  '4', '5', '6', 'B',
  '7', '8', '9', 'C',
  '*', '0', '#', 'D'
};

//LiquidCrystal_I2C Lcd(0x20,20,4);
//OnewireKeypad <LiquidCrystal_I2C, 12> KP( Lcd, KEYS, 4, 3, A0, 4700, 1000 );

OnewireKeypad <Print, 16 > KP2(Serial, KEYS, 4, 4, A0, 4700, 1000 );

void setup () {
  Serial.begin(9600);

  //  Lcd.init();
  //  Lcd.backlight();

  // This method is set in the constructor with a default value of 5.0
  // You only need to include this method if your Arduino is not supplying 5v to
  // the keypad. ie. ~4.7v or even with 3.3v Arduino boards too.
  //KP.SetKeypadVoltage(5.0);
  // KP2.setKeypadVoltage(5.0);
}

void loop() {
  //  if( KP.Getkey() )
  //  {
  //    Lcd.clear();
  //    Lcd.home();
  //    Lcd.print( F( "KP: " ) );
  //    Lcd.setCursor(4,0);
  //    KP.LatchKey();
  //  }

  if ( char key = KP2.getkey() ) {
    // Serial << "Key: " << key << " State: ";
    switch (KP2.keyState()) {
      case PRESSED:
        // Serial.println("PRESSED");
        Serial << key ;
        break;

      // case RELEASED:
      //   Serial.println("RELEASED");
      //   break;

      // case HELD:
      //   Serial.println("HOLDING");
      //   break;
    }
  }
}

But it is not working with ESPs where it is showing square boxes for some keys and too displaying other values for some keys and some keys are even not working any of the way

With OLDER Library (fortunately found the old zip file in document folder)
this code below works very well with UNO and MEGA

// Armuino --- Reading Membrane Keypad to Arduino with a Single Analog Wire  ---
// Video - https://www.youtube.com/watch?v=N39EXI_F8uA

#include "OnewireKeypad.h" // OneWireKeypad Library

char KEYS[] =   // Define keys' values of Keypad
{
	'1', '2', '3', 'A',
	'4', '5', '6', 'B',
	'7', '8', '9', 'C',
	'*', '0', '#', 'D'
};

/* Define Library :
OnewireKeypad <Print, #of buttons>
Keypad(Serial, Char values, #Rows, #Cols, Arduino Pin, Row_resistor, Columns_resistor) */
OnewireKeypad <Print, 16 > Keypad(Serial, KEYS, 4, 4, A0, 4700, 1000);

void setup ()
{
	Serial.begin(9600);
}

void loop()
{
	Keypad.SetHoldTime(100);  // Key held time in ms
	Keypad.SetDebounceTime(50); // Key Debounce time in ms
  
	if ((Keypad.Key_State() == 3))    // not pressed = 0, pressed = 1, released = 2,  held = 3
	{
		char keypress = Keypad.Getkey();  // put value of key pressed in variable 'keypress'
		// Serial.print("Keypad Key: ");
		Serial.print(keypress);  // Display value on Serial Monitor
    // Serial.print((char)keypress);
		while ((Keypad.Key_State())) {} // Stay here while Key is held down
	}
}

But same thing in happening in case of ESPs like square boxes , wrong key displaying etc etc etc . . . .

Now what's next ?

You need to follow the instruction to get the analog value for each key first.
Each keypad, each wiring, each MCU creates the different analog value for each key. Therefore, you need to do calibration at first.
Here is a tutorial for one-wire Keypad that contains calibration instruction

Now I need to remake my keypad and test it on my end.

What pin are you using on the ESP32? I tested it with D4 (or just 4) and it works. It doesn't work great but I can see all the Keys even with my thrown together keypad.

I also made a change that takes the resistor tolerance band into consideration when determining which key was pressed, so by default its set to 0.05 because gold = 5% and silver = 10%.

Another change I made is, I cleaned up the OneWireKeypad_Final sketch and remove the commented out code. It was just for an LCD anyway.

Does OP power the resistor string from 5volt when using an Uno/Mega,
and from 3.3volt when using an ESP8266 or ESP32.
Leo..

Based on the wiring diagram he provided for the UNO, he isn't powering it from a fixed external source (like 5v). And as long as he is using the 5v or 3.3v power rails on each board, it should be fine.

The library will determine the voltage it should be using based on if its an ESP32 board or not and calculate the values of the resistors from that.

He can choose to override the voltage in the library but that is on him. Though I wouldn't suggest plugging 5v into a 3.3v pin.

I could probably take 15-20 to go through all the possible boards and configure the library to handle the voltage and ADC values for each board. I'll get around to that eventually...

Btw, I have that keypad (or a version of that keypad) from your first post and the pins are not as straightforward as your diagram makes it look. The pins for the rows and columns are not 4 and 4 beside each other, they are kinda every other pin if I remember correctly. But you said it works fine on the UNO/MEGA so it seems your wiring is correct.

Ya my side started working with all the keys .
Just the thing is the mismatch of result with keys

rest everything OK

Don't know with both version of libraries how the Arduino models are working smoothly while ESP series is not supporting !!

I tried with both voltage levels and libraries !! Same result no change !!

Ya basically I have this 4x4 general purpose membrane keypad with red and blue keys commonly used for Arduino experiment

I didn't find any proper diagram regarding that so I posted it from internet only

A kind request is there . .
Would you please upload the old library with some other name or details and new one separately ????

No, I just applies ADC1 or pin 36
So should I move to D4 ??

How to define that in program ??
I mean like A0 what I need to define