Skip to content

ESP32 garbage values  #21

@dharmik768

Description

@dharmik768

I am using ESP32 with this library to read my PS2 keyboard. I am using a bi-directional logic level shifter based on MOSFET to convert 3.3v to 5v logic shift.
The GPIO pin that I was using for the clock is 23 and for data 22.
I uploaded the example code Simple_test. And when I type something with the keyboard it detects like when I press key 'a' then it prints 'a' on the serial monitor but many times when I do this little quickly by pressing different keys on the keyboard now ESP prints random garbage values on the serial monitor. For example, pressing 'g' on a keyboard and will show '2' on the serial monitor, and pressing the same key a second time shows 'g' properly.

Initially, I thought the logic converter I build had some issues so I tried the same code with Arduino UNO connected to it and it worked perfectly as expected so it's not a hardware issue.

Then I looked in the library code and get to know that it is using an interrupt on the clock pin and as I have been in a similar situation with ESP32 before while using interrupt I finally got to know why this thing is happening.

In Arduino ESP32 support there is some bug for an ESP32 interrupt routine.
When we declare interrupt on falling edge in ESP32 with Arduino IDE with our ISR function. Then ideally the ISR function should get only triggered on the falling edge but when I checked with my logic analyzer it sometimes gets triggers on the rising edge also don't know the reason for that and also after such updates this thing is still not resolved.
Have a look at this issue

So the simple solution for this problem can be implemented by adding one more if condition inside our ISR function like this.

void ps2interrupt(void)
 {
  if(digitalRead(irq_num_pin) == LOW)
  {

This will verify that the pin is in the LOW state or not by just adding this condition in .cpp file the ESP32 garbage problem was fixed and now I am getting perfect readings with my ESP32.

I defined a new variable as irq_num_pin which is equal to the clock pin called in begin function.

So I suggest updating this little logic so that it works better with an ESP32. Also, I have not tested it with Arduino UNO after making this change but I am sure it will not make any difference for other boards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions