Thanks, CrossRoads, this certainly points me in the right direction!
I used my pin pairs table to show which buttons share a common pin.
I expected it too look normal, like a grid, but it turns out to be some weird shapes with some buttons at the end that look like an afterthought.
10k resistors will not do because it looks like the pull-up resistors on the lines you have been able to measure are 4.7k.
It is probable that you can actually pull the pins fully to ground, but the problem is that you have not been able to fully confirm exactly how it works, hence I was being cautious. What resistors have you got? You may be able to use resistors in series to get to around 1k.
There is absolutely no reason that the physical layout of the pins should correspond neatly to the matrix. Interestingly, it appears to be a 6x7 matrix, although a 5x7 would have been sufficient for 33 keys.
I only have have "standard" resistors that I use with the Arduino (like 220Ω for LEDs and 10KΩ for pull-up) because I don't really make external circuits. Would two pairs of 5 220Ω resistors in series (to give two 1.1KΩ resistors) work?
The single button (colored in dark blue) is the "ON" button, which I guess is more important (it only powers on the device, it does nothing else during operation).
Yes, you can make close to 1K with 220R resistors. If you are experimenting and building little circuits, you'll have to get used to the idea of having a small stock of components. For example, you'll also need decoupling capacitors for those CD4051s.
I didn't notice before, but the ON button is indeed a special case. Pressing it directly grounds pin 13 so it is not incorporated in a matrix. This makes it more likely that you can safely directly ground one pin from the rows and one pin from the columns to simulate the pressing of a button, as already suggested. A resistor to limit the damage if anything goes wrong is not a bad idea. Even a 220R resistor in a 5Volt system helps, in that it limits the current while experimenting, even in the case of a connection between the power rails, to 10mA.
Start with the ON button and , using one of the 220R resistors, short pin 13 to ground and see if that simulates the pressing of that button.
Both with a single 220 resistor and with my "1.1K" resistor, when shorting pin 13 to gnd simulates the press of the ON button.
OK. Progress on to the experiment in post #15
Alright, I have just done it and the results are... hmm... I'll let you decide.
The device in question is a cash register machine.
When powered on, it checks if there is receipt paper. If there is, it boots. If there isn't, it doesn't boot and displays "PF" on the screen. If you press the PF key, it spins the paper feed motor and if paper is loaded, it detects it and says "C" on the screen, prompting you to press the C key to boot.
While it has no paper and says "PF" on the screen the only operational key is PF and when it says "C", you can press PF to advance the paper or press C to boot.
key | pins
|
PF | 2 & 8
C | 2 & 9
While in this "paperless" state, if I connect pins 2 to 8 or 8 to gnd or 2 to gnd and 8 to gnd (any of these combinations) with my 1.1K resistor, the PF key is activated. Similarly, if I connect 2 to 9 or 9 to gnd or 2 to gnd and 9 to gnd (any of these combinations) with my 1.1K resistor, the C key is activated.
Once the device has actually booted, i can't "press" any key with the resistor(s). The only way for it to detect a press is to short the corresponding pins with a wire, like it happens when you actually press a button.
I really do not understand.
You need two resistors. If you are going to start in the "paperless" state then, to simulate the PF key, you have to make the following connections:
Resistor 1 : between Pin 2 and ground
Resistor 2 : between Pin 8 and ground
It may be that if you don't do this simultaneously, you'll get an invalid result.
I guess you could try 220R resistors if you don't want to make up a second 1K resistor.
Did you get any positive results with direct shorting instead of using the resistors ? That is not clear from your description.
Sorry for not being clear.
I have 10 220R resistors, from which I made a pair of 1.1K resistors, so I have two 1.1K resistors.
While in the paperless state, the PF button gets activated if:
a. I connect only pin 8 to GND with a wire
OR
b. I connect only pin 8 to GND with a 1.1K resistor
OR
c. I connect pin 2 to GND and pin 8 to GND with two wires
OR
d. I connect pin 2 to GND and pin 8 to GND with two 1.1K resistors
OR
e. I connect pin 2 and pin 8 together with a wire, like a button press would
OR
f. I connect pin 2 and pin 8 together with a 1.1K resitor, like a button press would
If I load paper and press PF, so "C" is displayed on the screen, I can do everything above to press PF if I want to advance the paper, or do the same (one pin changed) if I want to press C in order to boot:
a. I connect only pin 9 to GND with a wire
OR
b. I connect only pin 9 to GND with a 1.1K resistor
OR
c. I connect pin 2 to GND and pin 9 to GND with two wires
OR
d. I connect pin 2 to GND and pin 9 to GND with two 1.1K resistors
OR
e. I connect pin 2 and pin 9 together with a wire, like a button press would
OR
f. I connect pin 2 and pin 9 together with a 1.1K resitor, like a button press would
After it has booted (after pressing C) I can't "press" any button except by using methods e and f (which is not useful, as it is like physically pressing the button).
(also, I found out that the last vertical set of three buttons on the far bottom-right (B31, B32, B33) are all on different rows/columns is because if you hold all of them at once, no matter what menu the device is in, it will instantly shut off)
OK. So the keyboard scanning works in a way other than I was expecting, i.e. the rows/columns of interest to be brought low. However, that does not matter in this case. The CD4051 acts as a switch so it can also simulate the activity which you have described as E and F in your last post.
The model that @Crossroads has shown will do that. However the 'ON' switch will require special treatment. You will also have to put ground on one of the CD4051 I/O pins, the opposite CD4051 which pin13 is connected to.
The INH (inhibit) pins of the two CD4051s can be connected together and pulled high with a 10K resistor and connected to a single arduino pin.
You now have to make a table of the pin distribution between the arduino/14pin connector/CD4051 (two of), maybe like this which I have started for you :
CD4051(#1) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 1 N/A
I/O 1 2 N/A
I/O 2 3 N/A
. . .
COMMON N/A N/A COMMON of other CD4051
INH N/A A0 Pulled High connected to other CD4051
A N/A D3
B N/A D4
C N/A D5
, , ,
CD4051(#2) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 8 N/A
I/O 1 9 N/A
. . .
I have read the datasheets, but I still don't understand much. I have a few questions about your table:
COMMON N/A N/A COMMON of other CD4051
INH N/A A0 Pulled High connected to other CD4051
So I connect the pins labeled "COM" (pin 3) of both 4051s together?
So I connect the pins labeled "INH" (pin 6) of both 4051s together, I pull it up to 5V (with a wire or a resistor?) and also connect it to A0?
Sorry, I didn't read carefully enough!
What do I do exactly with the ON button?
And what about the "decoupling capacitor" mentioned before by you?
In the meantime, would this table do?
CD4051(#1) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 1 N/A N/A
I/O 1 2 N/A N/A
I/O 2 3 N/A N/A
I/O 3 4 N/A N/A
I/O 4 5 N/A N/A
I/O 5 6 N/A N/A
I/O 6 7 N/A N/A
I/O 7 14 GND GND
COMMON N/A N/A COMMON of other CD4051
INH N/A D2 Pulled High connected to other CD4051
A N/A D3 N/A
B N/A D4 N/A
C N/A D5 N/A
CD4051(#2) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 8 N/A N/A
I/O 1 9 N/A N/A
I/O 2 10 N/A N/A
I/O 3 11 N/A N/A
I/O 4 12 N/A N/A
I/O 5 13 N/A ON Button, should be connected to pin 14 (GND)
A N/A D6 N/A
B N/A D7 N/A
C N/A D8 N/A
I have a question about this: I/O 7 14 GND GND.
So the ON button has to be connected to GND. Pin 13 is on the second CD4051, so I put pin 14 on the first CD4051, as I had an extra pin on that IC. Is this how I should do it? Also, I will connect this pin (14) to Arduino GND, so this will be my common ground, is this ok?
The 'ON' button looks OK. The decoupling capacitor is a 100nF capacitor connected to, and located close to, the 5v Pin ( Vdd - pin16) of each CD4051.
I've made some small additions to your table:
CD4051(#1) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 1 N/A N/A
I/O 1 2 N/A N/A
I/O 2 3 N/A N/A
I/O 3 4 N/A N/A
I/O 4 5 N/A N/A
I/O 5 6 N/A N/A
I/O 6 7 N/A N/A
I/O 7 14 GND GND
COMMON N/A N/A COMMON of other CD4051
INH N/A D2 Pulled High connected to other CD4051
A N/A D3 N/A
B N/A D4 N/A
C N/A D5 N/A
Vee GND
Vss GND
Vdd 5V 5V with 100nF ceramic decoupling cap to ground
CD4051(#2) 14Pin Header Arduino Notes
------------ ------------ -------- ------
I/O 0 8 N/A N/A
I/O 1 9 N/A N/A
I/O 2 10 N/A N/A
I/O 3 11 N/A N/A
I/O 4 12 N/A N/A
I/O 5 13 N/A ON Button, should be connected to pin 14 (GND)
COMMON N/A N/A COMMON of other CD4051
INH N/A D2 Pulled High connected to other CD4051
A N/A D6 N/A
B N/A D7 N/A
C N/A D8 N/A
Vee GND
Vss GND
Vdd 5V 5V with 100nF ceramic decoupling cap to ground
Now, the next table to prepare is :
Arduino Pins
Key Number Key Function D3 D4 D5 D6 D7 D8
---------- ------------ -- -- -- -- -- --
B1 PF 1 0 0 0 0 0
B2 %- 0 1 0 0 0 0
.. ..
You may need to refer to the table in chapter 8.4 (truth table) of this document to completer the table: http://www.ti.com/lit/ds/symlink
/cd4051b.pdf (see section under CD4051B)
Phew. This part was by far my least favorite
Arduino Pins
Key Number Key Function D5 D4 D3 | D8 D7 D6
---------- ------------ -- -- -- -- -- --
B1 PF 0 0 1 0 0 0
B2 %- 0 1 0 0 0 0
B3 VD 0 1 1 0 0 0
B4 PLU 1 0 0 0 0 0
B5 OFF 1 0 1 0 0 0
B6 %+ 1 1 0 0 0 0
B7 C 0 0 1 0 0 1
B8 PLC 0 1 0 0 0 1
B9 PRC 0 1 1 0 0 1
B10 STL 1 0 0 0 0 1
B11 PY 1 0 1 0 0 1
B12 X 1 1 0 0 0 1
B13 7 0 0 1 0 1 0
B14 4 0 1 0 0 1 0
B15 1 0 1 1 0 1 0
B16 00 1 0 0 0 1 0
B17 8 1 0 1 0 1 0
B18 5 1 1 0 0 1 0
B19 2 0 0 1 0 1 1
B20 0 0 1 0 0 1 1
B21 9 0 1 1 0 1 1
B22 6 1 0 0 0 1 1
B23 3 1 0 1 0 1 1
B24 . 1 1 0 0 1 1
B25 ON 1 1 1 1 0 1
B26 DP1 0 1 0 1 0 0
B27 DP2 0 1 1 1 0 0
B28 DP4 1 0 0 1 0 0
B29 TL 1 0 1 1 0 0
B30 DP3 1 1 0 1 0 0
B31 DP5 0 0 0 1 0 0
B32 DP6 0 0 0 0 1 1
B33 DP7 0 0 0 0 1 0
If you don't want to check if it is correct, I don't blame you. I hope I got it right. I reordered the Arduino Pins columns because the truth table was ordered "C B A" instead of "A B C" and I didn't want to mess it up.
Even though I don't really have many components, I found a scrap circuit board with two 104 ceramic capacitors (100 nF), so I also have those.
I'm sure you've got the idea. Anyway, if there is a problem it will show up in the testing and you can correct it in the program.
How important is the 3 simultaneous key sequence to force a shut down? That may not be so easy without additional components.
The 3 key shutdown is not important at all. I will start coding tomorrow.
Thanks for your help so far!
Ok, I have made the circuit on a breadboard (took me way too long, because I cut wires to specific lengths to make it look neater).
How should I program it?
If the INH pin is pulled high that will activate no pins. If I want to send a key press, I have to set it to low, right?
I still don't really get how this "selecting" works. Are all pins low and if I select a channel on the CD4051, does the corresponding I/O get set to high or the other way around?
Thanks!
If the INH pin is pulled high that will activate no pins. If I want to send a key press, I have to set it to low, right?
Correct
I still don't really get how this "selecting" works. Are all pins low and if I select a channel on the CD4051, does the corresponding I/O get set to high or the other way around?
Each CD4051s can be viewed as an selector switch. Their commons are connected together so if, for example, you are connecting pin 2 to pin 8, one CD4051 is connected to pin 8, the other to pin 2 and the Common to Common connection between the chips actually completes the bridge between the two pins. This is just the equivalent of you putting a wire between pins 2 and 8 in this case.
To make a simple test is easy: something like this. Note that the INH pin is never set to HIGH in the code. When it set to an input pin, the external pullup resistor holds it high. When it it set to Output it can be explicitly pulled low.
pinMode( 2, INPUT ) ; // sets inhibit pin to high impedance
// declare A B C select pins on both chips as output here :
. . .
// PF Key
// CD4051 #1
digitalWrite( D5 , LOW ) ;
digitalWrite( D4 , LOW ) ;
digitalWrite( D3 , HIGH ) ;
// CD4051 #2
digitalWrite( D8 , LOW ) ;
digitalWrite( D7 , LOW ) ;
digitalWrite( D6 , LOW ) ;
pinMode( 2, OUTPUT ) ; // inhibit
digitalWrite( 2 , LOW ) ; // enable
delay(100) ; // simulate a keypress for 100mS
pinMode( 2, INPUT ) ; // sets inhibit to high impedance
Once you get that working, then you define an array and a function to set the keys.
The array will look something like this where the first two bits are always 0 and the remaining 6 are as in your table:
byte selectKey[34] = {
0b00001000 /* PF / ,
0b00010000 / %- */ ,
. . .
. . .
}
and the function will take an argument, that is the number of the key, interpret the array and set D3 to D8 as required as in the test code.
It's alive! I mean, "alive" as in "it suffered a heart attack in 2018 and is still recovering".
The buttons can indeed be "pressed" (I tested a few buttons).
My device has a kind of menu system. The "main menu" is when it is powered on and is says "OFF" on the screen. From here you can press the number pad to go to different menus. When you are in a menu, you press the OFF key to go back to the main menu (sometimes you have to press it a few times).
From the main menu, if you want to shut it off, you press the number 0 on the number pad and it normally should shut off.
Well, with the Arduino, after it "presses" 0, the device is "softlocked" as in it displays something on the screen, but you can't do anything to it. If I disconnect the CD4051s' power supply from the Arduino, the device curiously restarts instead of shutting off, which I haven't seen before. So I guess the device will stay on all of the time and if it is accidentally tried to be shut off, it needs manual assistance to pull the Arduino's power supply out or unplug the device from the mains socket. I have also discovered that after plugging it back in, it automatically starts without having to hold the ON button.
Oh and I should mention that you can't manually press any button on the keyboard while the Arduino is connected. when the 14 pin header is connected to the breadboard.
This is some weird behavior.