Belo Horizonte, MG, BR
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« on: August 09, 2012, 10:57:18 am » |
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)?
|
|
|
|
|
Logged
|
|
|
|
|
USA
Offline
God Member
Karma: 14
Posts: 644
|
 |
« Reply #1 on: August 09, 2012, 11:21:38 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 986
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #2 on: August 09, 2012, 12:10:54 pm » |
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.pdfThat 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.
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
USA
Offline
God Member
Karma: 14
Posts: 644
|
 |
« Reply #3 on: August 09, 2012, 12:32:35 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 986
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #4 on: August 09, 2012, 12:48:04 pm » |
Even that polling method wouldn't account for certain combinations of presses: 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.
|
|
|
|
« Last Edit: August 09, 2012, 12:49:52 pm by Tom Carpenter »
|
Logged
|
~Tom~
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1398
Arduino rocks
|
 |
« Reply #5 on: August 09, 2012, 03:11:19 pm » |
I need room for the chess logic On Arduino?
|
|
|
|
|
Logged
|
|
|
|
|
Samplefinger
Offline
God Member
Karma: 8
Posts: 819
ALWAYS ASK FOR THREE. One to use. One to lose. One to abuse.
|
 |
« Reply #6 on: August 09, 2012, 03:42:11 pm » |
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/B006UTBDGAIt's pretty easy to "make" more pins on an Arduino but impossible to make more program memory. That's where Megas are nice.
|
|
|
|
|
Logged
|
Latest Sampling Scores: ATXMEGA64A3U-MH x3, ATXMEGA256A3U-MH x3, SST38VF6404-90-5C-EKE x3, SST38VF6402-90-5C-EKE x3, PGA870 x3, THS770006 x3
|
|
|
|
Belo Horizonte, MG, BR
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #7 on: August 09, 2012, 09:57:46 pm » |
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.:-)
|
|
|
|
|
Logged
|
|
|
|
|
Dubuque, Iowa, USA
Offline
Edison Member
Karma: 13
Posts: 1541
|
 |
« Reply #8 on: August 10, 2012, 12:31:05 am » |
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).
|
|
|
|
|
Logged
|
|
|
|
|
Belo Horizonte, MG, BR
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #9 on: August 10, 2012, 05:24:55 am » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 986
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #10 on: August 10, 2012, 05:27:43 am » |
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.
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Belo Horizonte, MG, BR
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #11 on: August 10, 2012, 05:49:47 am » |
Do see a simpler solution?
I could use the 595 only and read 8 cols with 8 pins. That would simplify things a bit.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 986
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #12 on: August 10, 2012, 07:24:17 am » |
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.
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
Belo Horizonte, MG, BR
Offline
Newbie
Karma: 0
Posts: 14
Arduino rocks
|
 |
« Reply #13 on: August 10, 2012, 07:35:57 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 986
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #14 on: August 10, 2012, 07:43:10 am » |
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.
|
|
|
|
« Last Edit: August 10, 2012, 07:48:25 am by Tom Carpenter »
|
Logged
|
~Tom~
|
|
|
|
|