0
\$\begingroup\$

This question already has an answer here:

I've been a programmer, for a while, but I am new to the hardware aspect of things so I apologize for my lack of knowledge.

Just for a fun project to try to get better with hardware, I've decided to make an electronic chess board that records your moves.

I'm using reed switches for this project (they activate when they are near magnets) and I have a question.

In chess, there are 64 tiles which means I need 64 reed switches. I realized that connecting each reed switch to its own GPIO pin is inefficient and annoying considering that I'll need to get more pins (I'm using a RPi B+, so I have 27 pins to work with currently). I decided to check if anybody else has done what I'm trying to do using reed switches to see if they had any workarounds to this. Nobody has gone into too much detail about how they did it, but it appears that some people have gotten away with using 16 pins (one for each row/column).

All I really need to know is how many reed switches are activated on each row and column. I'm assuming there is a way of connecting everything in such a way where every activated switch adds to the voltage, and then I can read the voltage for each input. However, my RPi only allows me to see if there is a high or low voltage supplied to the input.

Any tips? Thanks!

\$\endgroup\$

marked as duplicate by brhans, Elliot Alderson, Edgar Brown, Warren Hill, Finbarr Feb 7 at 12:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ You might want to look for questions on here about driving LED matrices, because what you're asking works in a very similar manner. \$\endgroup\$ – Hearth Feb 2 at 2:36
  • \$\begingroup\$ think about how chess moves are recorded .... for instance is there a square named 49? \$\endgroup\$ – jsotola Feb 2 at 2:43
  • \$\begingroup\$ Thanks for the feedback, I was planning on using a multiplexer, but the matrix seems like a good idea. I'll look into it! \$\endgroup\$ – Andrew Feb 2 at 3:46
  • 1
    \$\begingroup\$ Please note, though, that you'll need a diode for each square. \$\endgroup\$ – WhatRoughBeast Feb 2 at 3:52
  • \$\begingroup\$ I understand, my only question is that if the matrix is designed for a keyboard (where there are keypresses and only one pair of rows and columns are active at the same time) will it still work when everything is active at the same time? \$\endgroup\$ – Andrew Feb 2 at 3:56
1
\$\begingroup\$

As mentioned by others, it can be done using an 8x8 matrix. If you look at the internet you will find plenty of picture where they are used for keypads.

However those standard schematics are assuming you press only one key at a time. Some combination of two switches are also possible. But in your case need to be able to detect any combination if pressed switches.

I worked on that problem a while ago and found you can do it with an 8x8 matrix, but, as also mentioned by WhatRoughBeast, it requires a diode in series with each switch.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Thank you, I understand the general idea. I'm just wondering, for this to work you would need to receive 3 bits of information, correct? As I stated in the question, I can only receive high or low for the input given my current setup. What should I do about this? \$\endgroup\$ – Andrew Feb 2 at 4:08
  • \$\begingroup\$ The additional information you have is that you activate one row at a time. (it is called 'scanning') So you know which row is active and the column tells you which switches in that row are pressed. Without diodes it fails if you press buttons on more then one row. \$\endgroup\$ – Oldfart Feb 2 at 4:12
  • \$\begingroup\$ you could use an 8bit demultiplexer to provide the output and an 8bit multiplexer to read the input ...... that way you would only need 7 pins .... 6 for addressing and 1 for data \$\endgroup\$ – jsotola Feb 2 at 20:26
  • \$\begingroup\$ mux and demux part numbers ..... 74HC151, 74ls138 \$\endgroup\$ – jsotola Feb 3 at 4:59
0
\$\begingroup\$

It's called scanning. You have 8 pins set as inputs, one connected to each column. You have 8 pins set as outputs, one connected to each row.

You begin by looking at column 1 and putting a high level on each row output sequentially (1-8). If there is a switch or switches closed in column 1 you will see a 'high' when the row scan hits that switch (or switches). So then you continue, looking at each column in sequence, and scanning through the 8 rows.

This will tell you which switches among the 64 are closed.

\$\endgroup\$
  • \$\begingroup\$ It wouldn't be able to detect how many switches are closed though, would it? For example: image that every square has a piece on it except for one. If you place a piece on that last empty square, will it be able to detect the change even though everything will still be activated as it was before? \$\endgroup\$ – Andrew Feb 2 at 3:58
  • \$\begingroup\$ As you activate each row you see on the column lines which switches of that row are active. \$\endgroup\$ – Jasen Feb 2 at 6:50
0
\$\begingroup\$

The correct answer is 16 ports to maps to 8X out by 8Y in ports scanned in >2x rapid sequence to detect events >1/x duration per frame. Pull up or down input resistors define the open state opposite to drive level.

You must estimate the shortest close reed event you want to ignore and then choose the board scan rate >8X and use small caps or software filtering to eliminate glitches if desired.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.