ESP32 with a tons of switch

Yosuke
Posts: 8
Joined: Sat Oct 06, 2018 6:59 am

Re: ESP32 with a tons of switch

Postby Yosuke » Thu Oct 11, 2018 12:17 am

Hi, Tom.

I will try 74HC148 as well.
Thanks for helping me and showing me the datasheet.
I really appreciate it.

Yosuke

Yosuke
Posts: 8
Joined: Sat Oct 06, 2018 6:59 am

Re: ESP32 with a tons of switch

Postby Yosuke » Thu Oct 11, 2018 1:39 am

Hello, ESP_Sprite.

I appreciate you giving me the advice.
ESP_Sprite wrote:Yosuke: I'm not quite sure why you get the results you do... the only thing that springs to mind immediately is that your breadboard setup has a fairly big parasitic capacitance, and the pull-up in GPIO16 may not be enough to overpower it. You can try adding an external resistor (anywhere between 1K and 10K should work) from that pin to 3.3V. If that doesn't work: if you have an oscilloscope or logic analyzer, it may be helpful to visualize the signals and see what's happening.
Following your advice, I've tried to add an external resistor(12K) from that pin to 3.3V.
Unfortunately, the result was the same.
I'm trying to use universal board right now because I don't have an oscilloscope and logic analyzer.
IMG_20181011_094426.jpg
IMG_20181011_094426.jpg (2.38 MiB) Viewed 7967 times
Sometimes, I will rent these measuring machines.
ESP_Sprite wrote:(Yosuke: you may still want to modify your schematic a little bit. If you press two buttons at the same time, you're essentially shorting your selected low output with an unselected, high output at times. This is Not Good in general. You could work around this by e.g. connecting 1K resistors between the buttons and the '138; that's enough to limit the current, but will still easily over-power the internal pull-up, which is 50K or so. Even better: use diodes instead of resistors so current can only run from the buttons into the '138; that way your setup can actually detect all the buttons pressed as well.)
When I built the key matrix circuit by Arduino UNO 3 two years ago,
I used diodes(one diode per one button) to avoid Phantom key and be able to press multiple buttons at the same time.
Here is the circuit with 48 buttons(6 rows × 8 columns).
IMG_20181011_094538.jpg
IMG_20181011_094538.jpg (2.85 MiB) Viewed 7967 times
And here is a piece of schematic.
WS000000.JPG
WS000000.JPG (119.05 KiB) Viewed 7967 times
this circuit worked in the expected way.
I could build key matrix circuit by Arduino UNO 3,
so I assumed that If I divert that circuit and use the similar codes, it would be easier to build the key matrix circuit by ESP32.
What I thought was wrong. haha

Thanks, Yosuke.

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: ESP32 with a tons of switch

Postby tommeyers » Thu Oct 11, 2018 4:24 pm

Yosuke,

In the diagram above it appears that the 138 is being used for 2 output purposes: 1) to send a polling signal to each of the 8 columns (of 2 switches) and combined with led0/1 to light 1 of the 16 leds (8 columns 2 rows).

The switch values are presented to the long connector which chooses what row of switches and what column and through the 138 which led row and column. The 138 is used as output only and is being used correctly

The process is polling which returns column switch values to the long connector no to the 138.

For your purpose a 148 is the correct part and is easily chained or matrixed to read more switches.

Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic

tommeyers
Posts: 184
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: ESP32 with a tons of switch

Postby tommeyers » Thu Oct 11, 2018 4:52 pm

Don't give-up.

1) use 148 to read 7 switches
2) See below for reading more

Reading More:
Take a look here: https://www.embeddedrelated.com/showarticle/519.php

For more than 8 buttons you can use a matrix and easily get to 64 buttons.

HC138 for polling rows (0..8) while reading from am HC148 columns.

for 148 value =0; < 8; ++
Read 138 value (it gives 0..7 or none)

pretty easy, Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic

Yosuke
Posts: 8
Joined: Sat Oct 06, 2018 6:59 am

Re: ESP32 with a tons of switch

Postby Yosuke » Sat Oct 13, 2018 6:56 am

To Tom Meyers,

Thank you for your advice.
I do appreciate it.

I ordered 74HC148 yesterday and I will receive it tomorrow.
So, I'll try to verify that 74HC148 with ESP32 works correctly.
Maybe, as is the case with 74HC138, 74HC148 used with ESP32 doesn't work correctly.

To all,

I used universal board because breadboard might cause that defect.
And I used my code(Version 1), but the result was the same.
When I pressed #0 switch, I got 4. ←wrong
When I pressed #1 switch, I got 1. ←right
When I pressed #2 switch, I got 2. ←right
When I pressed #3 switch, I got 1 or 3. ←wrong
When I pressed #4 switch, I got 6. ←wrong
When I pressed #5 switch, I got 5. ←right
When I pressed #6 switch, I got 0. ←wrong
When I pressed #7 switch, I got 7. ←right
IMG_20181011_094426.jpg
IMG_20181011_094426.jpg (2.38 MiB) Viewed 7922 times
This defect happens under any circumstances.
On the other hand, if I change the wirings appropriately, it is no longer a problem except #3 switch.

I noticed another interesting thing.
I tried ESP32-DevKitC(made by Espressif Systems) in the same circuit and same code(version 1).
IMG_20181011_220340.jpg
IMG_20181011_220340.jpg (2.68 MiB) Viewed 7922 times
The result is following.
When I pressed #0 switch, I got 4. ←wrong
When I pressed #1 switch, I got 1. ←right
When I pressed #2 switch, I got 2. ←right
When I pressed #3 switch, I got 3. ←right
When I pressed #4 switch, I got 0. ←wrong
When I pressed #5 switch, I got 5. ←right
When I pressed #6 switch, I got 6. ←right
When I pressed #7 switch, I got 7. ←right

#0 switch and #4 switch have replaced each other.
This defect depends on developer kit!
Here is a comparison of developer kit.
ESPr® Developer 32(made by SWITCH SCIENCE)................ESP32-DevKitC(made by Espressif Systems)
When I pressed #0 switch, I got 4. ←wrong.............When I pressed #0 switch, I got 4. ←wrong
When I pressed #1 switch, I got 1. ←right.......................When I pressed #1 switch, I got 1. ←right
When I pressed #2 switch, I got 2. ←right.......................When I pressed #2 switch, I got 2. ←right
When I pressed #3 switch, I got 1 or 3. ←wrong.......When I pressed #3 switch, I got 3. ←right
When I pressed #4 switch, I got 6. ←wrong.............When I pressed #4 switch, I got 0. ←wrong
When I pressed #5 switch, I got 5. ←right.......................When I pressed #5 switch, I got 5. ←right
When I pressed #6 switch, I got 0. ←wrong.............When I pressed #6 switch, I got 6. ←right
When I pressed #7 switch, I got 7. ←right.......................When I pressed #7 switch, I got 7. ←right

I changed the wirings appropriately(#0 switch → PIN 4 of HC138 and #4 switch → PIN 0 of HC138).

When I pressed #0 switch, I got 0. ←right
When I pressed #1 switch, I got 1. ←right
When I pressed #2 switch, I got 2. ←right
When I pressed #3 switch, I got 3. ←right
When I pressed #4 switch, I got 4. ←right
When I pressed #5 switch, I got 5. ←right
When I pressed #6 switch, I got 6. ←right
When I pressed #7 switch, I got 7. ←right

All right! Yeah :D

Yosuke
Posts: 8
Joined: Sat Oct 06, 2018 6:59 am

Re: ESP32 with a tons of switch

Postby Yosuke » Sun Oct 14, 2018 5:26 am

I added diodes(one diode per one button) to my circuit, but I can't press multiple buttons at the same time.
hmm... :|
IMG_20181014_114538.JPG
IMG_20181014_114538.JPG (48.1 KiB) Viewed 7901 times

Yosuke
Posts: 8
Joined: Sat Oct 06, 2018 6:59 am

Re: ESP32 with a tons of switch

Postby Yosuke » Mon Oct 15, 2018 1:35 am

I recieved 74HC148 and I tried to verify it with ESP32, 7 switches, and 7 resisters(12K).
The result was not what was expected.
IMG_20181015_074512.jpg
IMG_20181015_074512.jpg (2.73 MiB) Viewed 7880 times
Here is my codes.

Code: Select all

void setup() {
  
  pinMode(12, INPUT);
  pinMode(13, INPUT);
  pinMode(14, INPUT);
  
  Serial.begin(115200);

}

void loop() {
  
  byte res1 = (GPIO.in >> 12) & 0x1;
  byte res2 = (GPIO.in >> 13) & 0x1;
  byte res3 = (GPIO.in >> 14) & 0x1;
  
  if(res1&&res2&&res3){return;}
  else if(!res1&&res2&&res3) {Serial.println("Pressed button1");delay(100);}
  else if(res1&&!res2&&res3) {Serial.println("Pressed button2");delay(100);}
  else if(!res1&&!res2&&res3) {Serial.println("Pressed button3");delay(100);}
  else if(res1&&res2&&!res3) {Serial.println("Pressed button4");delay(100);}
  else if(!res1&&res2&&!res3) {Serial.println("Pressed button5");delay(100);}
  else if(res1&&!res2&&!res3) {Serial.println("Pressed button6");delay(100);}
  else if(!res1&&!res2&&!res3) {Serial.println("Pressed button7");delay(100);}//*/

}
The result was;
When I pressed #1 switch, I got 1. ←right
When I pressed #2 switch, I got 2. ←right
When I pressed #3 switch, I got 2 or 3. ←wrong
When I pressed #4 switch, I got 4. ←right
When I pressed #5 switch, I got 4 or 5. ←wrong
When I pressed #6 switch, I got 4 or 6. ←wrong
When I pressed #7 switch, I got 4 or 6 or 7. ←wrong

Who is online

Users browsing this forum: No registered users and 130 guests