Go Down

Topic: Reading chess board with reed switches (Read 3860 times) previous topic - next topic

Gatis

I have this chess board and pieces with magnets on the bottom. My idea is to place a reed switch below each tile so that Arduino can detect movements by comparing boards before and after one movement.

How do I wire these reed switches to use as less IO pins as possible without using too much code (I need room for the chess logic)?

Far-seeker


I have this chess board and pieces with magnets on the bottom. My idea is to place a reed switch below each tile so that Arduino can detect movements by comparing boards before and after one movement.

How do I wire these reed switches to use as less IO pins as possible without using too much code (I need room for the chess logic)?


A basic switch matrix (similar to what's used in the Keypad library) will give you a major reduction in I/O necessary.  You'll still need 16 total wires to the chessboard, but provided you don't need a lot of additional I/O for other things it's do able.  You could theoretically get it down to a single pin by using a form of serial encoding, but you'd need a non-trivial amount of logic circuitry between the chess board and the Arduino to achieve that.

Tom Carpenter

A switch matrix like a Keypad wouldn't work as there would be more than piece at any given time.

Your could try using 8x 74HC165 8bit parallel to serial shift registers.
http://www.nxp.com/documents/data_sheet/74HC_HCT165.pdf

That would allow you to read in all 64 through just 3 pins (Clock, Data, Latch). The 165's can be daisy chained such that they all share the same clock and latch(PL) pins, and the serial out from one goes into the serial in of the next and so on until the 8th whose serial out goes into the arduino.

You would basically just have to pulse the latch pin, and then call shiftIn() 8 times to get all 64 pins.
~Tom~

Far-seeker


A switch matrix like a Keypad wouldn't work as there would be more than piece at any given time.


I wrote "similar", not "exactly like" a keypad.  Read the other link I included, especially the last section titled "Scanning Method".  This method polls only one row at a time in quick succession, instead of all rows all the time.  This allows the presence or absence of a piece to be accurately detected because the pin attachted to each column can only register the switch for the single row being polled.

Although admittedly your method works as well.

Tom Carpenter

#4
Aug 09, 2012, 07:48 pm Last Edit: Aug 09, 2012, 07:49 pm by Tom Carpenter Reason: 1
Even that polling method wouldn't account for certain combinations of presses:
Code: [Select]

r0----x---o---o
     |   |   |
     x---x---o
     |   |   |
     o---o---o
     |   |   |
     c0  c1  c2

In that diagram, an x means switch pressed (connected), o means unconnected. If you turn the row0 on (indicated by -----), then you will read 110 on the columns even though only the first switch on row0

Edit: Ahh, I see the diodes there, that would solve the problem.
~Tom~

florinc

Quote
I need room for the chess logic

On Arduino?

JoeN


Quote
I need room for the chess logic

On Arduino?


I think we're gonna need a bigger Arduino.

Arduino Mega R3 to the rescue!

http://www.amazon.com/Arduino-MEGA-2560-Board-R3/dp/B006UTBDGA

It's pretty easy to "make" more pins on an Arduino but impossible to make more program memory.  That's where Megas are nice.
I have only come here seeking knowledge. Things they would not teach me of in college.

Gatis

A switch matrix plus two 165 will let me read whole board with 7 pins (3 for each 165 and 1 return pin).

I believe i can use two arduinos, 1 for reading board and controling an arm, and the other one for chess logic. We'll see.:-)

Chagrin

When you capture a piece your detection of movement is going to get a little goofy. It's no longer a simple problem of "piece removed from spot X, placed at spot Y". You would have to track whose turn it is or guarantee that the capture piece is always picked up first/second before the capturing piece is laid in its place.

Would be nice to be able to detect the black pieces from the white pieces. I had been looking for a hall sensor that could detect either of N, S, or none but could only find one in a 5sot-553 package (which is puny).

Gatis

Oops, i actually meant a 595 for rows and a 165 for cols.

Do i need resistors or can i just attach rows and columns directly? How do i wire this thing?

Tom Carpenter

If you are going down that route, you would need a diode for each reed switch - You don't need a resistor though.


Wire it so that you have:

Row ----|>|------o-o----Col

where --|>|-- is a diode, and o-o is a reed switch.
~Tom~

Gatis

Do see a simpler solution?

I could use the 595 only and read 8 cols with 8 pins. That would simplify things a bit.

Tom Carpenter

The issue is not the chips you are using. To do a simple matrix like that which requires more than one switch to be pressed (at most 32 are required for chess), you have to use diodes.

The alternative to using diodes for each switch is to use 8 47HC165s as suggested already.
~Tom~

Gatis

Got it. So, if I go with 8 74HC165's, will I need resistors? Sorry, I've got ask since I know little about interfacing.

Tom Carpenter

#14
Aug 10, 2012, 02:43 pm Last Edit: Aug 10, 2012, 02:48 pm by Tom Carpenter Reason: 1
You may need pull up resistors on each of the 74HC165 inputs to ensure a known state when the reed switches are open (unless they are SPDT). But as resistors are 0.1pence a shot, cost isn't much of an issue, and space shouldn't be too bad.
Having said that you would still need a pullup resistor on each input of the 74HC165 for the other method as well for the same reason.

~Tom~

Go Up