B4R Question rKeypad library not working with b4r and esp32

lenk54

Member
Licensed User
Longtime User
Hi

I have been trying to interface a 4x5 keypad on ESP32 with B4r but I cannot get it working.


keypad_image.jpg


It works fine with Arduino (1.8.13)

I have connected it to PINS:-
Array As Byte(36, 39, 34, 35), Array As Byte(32, 33, 25, 26, 27)
I know pins 36,39,34,35 are input only without internal pull-ups but I have fitted pull up resistors (3v3)

As I need the extra pins.

This configuration works fine on Arduino.

My version of code:
Sub Process_Globals
    Public Serial1 As Serial
    Private pad As Keypad
    Private password As String = "123456" 'the password is *123456
    Private passwordBuffer(6) As Byte
    Private passwordIndex As Int
    Private bc As ByteConverter
End Sub

Private Sub AppStart
    
    Serial1.Initialize(115200)
    Log("AppStart")
    'PINS 36, 39, 34, 35 are input only pins. I have put pull up resistors on all 4 pins
    'After Appstart the first character in the init string is sent to logs e.g. '<'
    'This Only works once when KP key is held down and the esp32 EN button is pressed and released
    pad.Initialize("<741A0852B>963#@~v^*", Array As Byte(36, 39, 34, 35),  Array As Byte(32, 33, 25, 26, 27),"pad_KeyPressed")
End Sub

'-------------------------- This works OK in Arduino  ----------------------------------------------
'const byte ROWS = 4; //four rows                                                       
'const byte COLS = 5; //four columns                                                       
'//define the cymbols on the buttons of the keypads
'char hexaKeys[ROWS][COLS] = {
'  {'<','7','4','1','A'},
'  {'0','8','5','2','B'},
'  {'>','9','6','3','#'},
'  {'@','~','v','^','*'}
'};

'byte rowPins[ROWS] = {36, 39, 34, 35}; //connect To the row pinouts of the keypad
'byte colPins[COLS] = {32,33, 25, 26, 27}; //connect To the column pinouts of the keypad
'---------------------------------------------------------------------------------------------------


Sub Pad_KeyPressed (Key As String)
    Log(Key)
    If Key = "*" Then
        passwordIndex = 0
        'this is not really required, but it makes the logs nicer.
        bc.ArrayCopy("000000", passwordBuffer)
    Else if passwordIndex < passwordBuffer.Length Then
        'put the key in the buffer.
        passwordBuffer(passwordIndex) = Asc(Key)
        passwordIndex = passwordIndex + 1
        If passwordIndex = passwordBuffer.Length Then
            If passwordBuffer = password Then
                Log("Well done!!!")
            End If
        End If
    End If
    Log(passwordBuffer)
End Sub

The code runs and after the 'AppStart' log, the first character in the string array is logged e.g. '<'
Every character can be logged by holding down the keypad key and pressing EN on ESP32 , it then returns the correct character after the reboot.

Any help would be greatly appreciated.
 

lenk54

Member
Licensed User
Longtime User
Start by detecting input on all 8 input pins. (8 input pins is max 4x4 keypad)
Hi

4x5 keyboard needs 9x pins and the same setup works fine on Arduino with Esp32.
I understand the library is based on the Arduino Keypad!
If I hold a keypad key down and cycle the ESP EN button it logs the correct character.
 
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
Hi

I have been trying to interface a 4x5 keypad on ESP32 with B4r but I cannot get it working.


View attachment 110638

It works fine with Arduino (1.8.13)

I have connected it to PINS:-
Array As Byte(36, 39, 34, 35), Array As Byte(32, 33, 25, 26, 27)
I know pins 36,39,34,35 are input only without internal pull-ups but I have fitted pull up resistors (3v3)

As I need the extra pins.

This configuration works fine on Arduino.

My version of code:
Sub Process_Globals
    Public Serial1 As Serial
    Private pad As Keypad
    Private password As String = "123456" 'the password is *123456
    Private passwordBuffer(6) As Byte
    Private passwordIndex As Int
    Private bc As ByteConverter
End Sub

Private Sub AppStart
   
    Serial1.Initialize(115200)
    Log("AppStart")
    'PINS 36, 39, 34, 35 are input only pins. I have put pull up resistors on all 4 pins
    'After Appstart the first character in the init string is sent to logs e.g. '<'
    'This Only works once when KP key is held down and the esp32 EN button is pressed and released
    pad.Initialize("<741A0852B>963#@~v^*", Array As Byte(36, 39, 34, 35),  Array As Byte(32, 33, 25, 26, 27),"pad_KeyPressed")
End Sub

'-------------------------- This works OK in Arduino  ----------------------------------------------
'const byte ROWS = 4; //four rows                                                      
'const byte COLS = 5; //four columns                                                      
'//define the cymbols on the buttons of the keypads
'char hexaKeys[ROWS][COLS] = {
'  {'<','7','4','1','A'},
'  {'0','8','5','2','B'},
'  {'>','9','6','3','#'},
'  {'@','~','v','^','*'}
'};

'byte rowPins[ROWS] = {36, 39, 34, 35}; //connect To the row pinouts of the keypad
'byte colPins[COLS] = {32,33, 25, 26, 27}; //connect To the column pinouts of the keypad
'---------------------------------------------------------------------------------------------------


Sub Pad_KeyPressed (Key As String)
    Log(Key)
    If Key = "*" Then
        passwordIndex = 0
        'this is not really required, but it makes the logs nicer.
        bc.ArrayCopy("000000", passwordBuffer)
    Else if passwordIndex < passwordBuffer.Length Then
        'put the key in the buffer.
        passwordBuffer(passwordIndex) = Asc(Key)
        passwordIndex = passwordIndex + 1
        If passwordIndex = passwordBuffer.Length Then
            If passwordBuffer = password Then
                Log("Well done!!!")
            End If
        End If
    End If
    Log(passwordBuffer)
End Sub

The code runs and after the 'AppStart' log, the first character in the string array is logged e.g. '<'
Every character can be logged by holding down the keypad key and pressing EN on ESP32 , it then returns the correct character after the reboot.

Any help would be greatly appreciated.
can you try this example with inline c code, for me on esp8266 (wemos d1 mini) works well.

 
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
can you try this example with inline c code, for me on esp8266 (wemos d1 mini) works well.

just found one esp32 (esp32 wroom 30 pin) works well with c inline
 
Upvote 0
Top