Hi all, I'm in the very beginning stages of a project (guitar replica synth) and I have a question about how to connect the buttons to an SX1509 breakout. As a precursor to this question, I've never done anything like this before so I'm more than a little lost. I've been following diagrams found elsewhere online so I think maybe I'm on the right track (or maybe not).
In the attached image, you'll see that I only have 2 rows and 2 columns, but that will be expanded to 8 rows and 4 columns. The MP3 module isn't pictured because I'll get there when I get there.
I want two buttons per row, which will be attached by a thin metal rod to emulate a string (each fret will have its own rod). That way, a note will be played whenever anywhere along the rod is pressed. Two buttons will be used per row for physical stability of the rod.
My question is if I have this set up correctly when using diodes to prevent ghost presses (as I've read elsewhere) and if two buttons can be wired together in such a fashion. A second question is what will happen if both buttons are pressed? Would that cause any issues? Any guidance will be helpful, thank you!
Honestly I'm not sure. I've perused the datasheet on SparkFun's site, but don't really understand what I'm looking at and don't see anything that jumps out at me as an example. It seems like the datasheet only refers to a single button being used per row-column "coordinate" as opposed to two. I'm hoping I'm not over my head here.
Yes, I've been using that as one of my references. The question is if I can use two buttons instead of just one for each coordinate (see the image in my first post).
I think you need only one diode per pair of buttons. Wire the two buttons in parallel with each other and the diode in series with the button pair.
Either button or both pressed at the same time will register as a press. (As pointed out above, you won't know which button in a pair was pressed, but it sounds like that's not important here.)
The diodes should all have the same orientation, meaning all anodes connected to rows and all cathodes to columns of the matrix or vice-versa. From what I remembered seeing in the SX1509 datasheet, the chip can be configured to scan row-by-row or column-by-column. But test a small prototype before building the whole matrix.
For the first part of your response, like this image? For the second part about anodes and cathodes, I'm not sure I understand. Is that not what I've done? They all have the same orientation, but are you saying I need more or some diodes in the opposite direction?
Yes, understood (that's what the link in my last post explains).
This applies if you want to detect more than one key pressed in parallel. Did you check if the SparkFun library supports that or are you going to write this function yourself?
I don't need to detect more than one key pressed in parallel, I just need both buttons to execute the same command. That is to say, just one or the other of the buttons need to be pressed for it to work.
I notice your image shows 4-pin buttons, but only 2 connections to each button, and those connections don't touch the pins! I cannot say that this is right or wrong. But if you use 4-pin buttons, it is possible to connect them incorrectly, if you do not know for sure which pins are permanently connected. When you don't know for sure, just use 2 diagonally opposite pins and leave the other 2 unconnected.
Yes, you have correctly oriented all the diodes the same way. We cannot say if that is the correct way without seeing the code, which I guess you do not have yet. But I understand that whichever orientation you choose for the diodes, it should be possible to write the code to work correctly with that diode orientation. The way in which matrixes are scanned is normally to connect either the columns, or the rows, one at a time, to ground. If a button is pressed, it connects one of the columns and rows together to so that a very small current can flow through the button to ground. The diode must have the correct orientation to allow the current to flow that way.
I think you confused @ec2021 by saying that, which is why they said you do not need the diodes. Perhaps you should explain again. I think you do need diodes, but only one diode per pair of buttons which are connected by the metal rods as you described in the first post.
I actually downloaded a Fritzing part for a 2-pin switch, which is what I have at my disposal. The pins are indeed connected, but the part looks identical to a 4-pin switch besides the different pin placement.
Thank you for the clarification about the diodes, that's helpful. This is certainly a learning process for me.
@PaulRB@ec2021 Yes, the two buttons per "coordinate" are physically connected by their own metal rod. I'll explain again as requested. I want the two buttons per coordinate to act as a single button, but only one of them needs to be activated to trigger the command for that particular coordinate (depending on the stiffness of the rod, they might both be activated simultaneously, however). The project will have 8 rows and 4 columns, thus 32 coordinates, and thus 64 buttons. Does that help?
Are you only pressing one or both of the same coloured pair at a time or do you expect that one or both buttons of several pairs are pressed at a given time in parallel?
Or in pictures:
Is this a possible use case (red marked buttons are pressed at the same time):
@ec2021 It will be like case B. Only one button will be pressed at a time (the black button in your last image), however it is possible that both buttons in the coordinate (the blue ones in your second image) will be pressed simultaneously.
@PaulRB Why 15 pins and not 12 if it's 8 rows and 4 columns?