Shop OBEX P1 Docs P2 Docs Learn Events
Chess Board Interface I/O Quandry — Parallax Forums

Chess Board Interface I/O Quandry

VeramacorVeramacor Posts: 6
edited 2007-10-17 06:40 in BASIC Stamp
Hello all,

I'm about to embark on creating a tournament size chess board interface. I have sourced some Reed Switches which will be magnetically switched on and off by the chess pieces themselves.

I would like to use a basic stamp and use just digital logic to sense the pieces.

That would mean I would need 64 I/O pins (one for each square).

I tried to think of using some fancy switch logic but the circuit design is a bit beyond me at the moment.

I thought of using I/O expanders, but I would need at least 8 extra chips if I use just the basic stamp (not a bs240)

I thought about analog, but I would like the interface to be as fast as possible.

Any ideas for my I/O hungry application?

Thanks!

Comments

  • Computer Geek 101Computer Geek 101 Posts: 179
    edited 2007-10-16 12:18
    maybe matrix encode the reed switches and use a matrix decoder.
  • VeramacorVeramacor Posts: 6
    edited 2007-10-16 13:40
    Looking a little more I hear people using a method called CharliePlexing - would this apply to reading the 8x8 matrix, not just driving it?
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2007-10-16 14:47
    Charlieplexing is pretty complex and I would steer away from that.

    You could simply use all 16 I/O lines on the BS2 (8 for the rows and 8 for the columns) and connect the reed switches into an 8x8 switch matrix. However, this would leave no I/O for anything else - but you may need at least 1 more I/O line for a serial display or something - so this approach is probably out then.

    I would think about using (8) 74HC165 parrallel to serial to chips to allow for 8 sets of 8 reed switches. This would be the easiest approach. If you look in the StampWorks on the Parallax site it shows you how to cascade the chips together and has BS2 code for this. I would go with this approach.


    Post Edited (T&E Engineer) : 10/16/2007 2:57:41 PM GMT
    2560 x 1024 - 196K
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-10-16 15:00
    Vermacor -

    You might do well to think about this quite a bit further. Please don't think I'm pouring water on your project, nothing could be further from the truth. On the other hand, one must look at both the advantages as well as the disadvantages of any given project direction long before one line of program is coded, or one bit of hardware is purchased.

    It appears from what you're proposing that you hope to learn/know that a chess piece is on a given square on a chess board, just as one might know which key was pressed on a keypad. Sorry to say, but mere position is not going to be nearly good enough. You will need to know at least the following, if you are planning to use the chess board as an "input device", which is what I'm presuming in my answer here, based on your posting:

    1. That some piece is on a given square, and what that square is of the 64 possible squares.

    2. What kind of chess piece is on that particular square (rook, bishop, pawn, etc.).

    3. Specifically you will also need to know which specific piece is on that given square (king's bishop, queen's rook, king's knight, etc.).

    With only 32 bytes of readily available variable RAM on the BS-2 Stamps, you will probably find yourself short of variable space, long before you find yourself short of I/O ability (I/O pin ports), as you will see.

    Now I suppose you could encode something up for 16 x 2 individual chess pieces (32 total), and perhaps use less than a BYTE (8 BITS), but more than a NIB (4 BITS) per piece, merely based on 2^5 = 32 or 2^6 = 64, depending on where your thinking takes you. Based on your particular encoding method and scheme, you may or may not have location in those 5 or 6 bits. However, even if you did, a 5 or 6 bit variable would be VERY difficult to use in PBASIC, unless you're the patient and careful type. This is not to say that it couldn't be done.

    Where to get more user RAM is now the first question of importance, I would think. Well, if one uses one of the more advanced Stamp models (BS-2p and above) one could also take advantage of the SPRAM (128 BYTES of Scratch Pad RAM) for additional variable space. Again, this makes programming a bit more complex than just using the standard 32 bytes of ordinary RAM as provided on all BS-2 Stamps. So too, if one specifically opted for a BS-2P40, then·32 I/O ports are supported.

    Hopefully this information may help you to avoid or plan around one potential pitfall, and give you more to consider.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 10/16/2007 3:06:19 PM GMT
  • VeramacorVeramacor Posts: 6
    edited 2007-10-16 15:00
    Thanks so much,

    I was thinking this would be the route to go, the 8 chips is what keeps me looking for a better solution

    thanks for the info!
  • VeramacorVeramacor Posts: 6
    edited 2007-10-16 15:17
    Bruce,

    The inteface board will be connected to a Visual Basic app connected to a chess server. Positions on the board are maintained at the vb/chess server.

    All I need to do is derive what the difference between the server position is and what my switches tell me

    the types of pieces are irrelevant, I'm looking for the discrepency in positions to derive a move

    ie,

    a pawn moved two spaces forward in front of the Queen in chess notation is simply:

    d2-d4

    the coordinates are :

    a - h (x direction)
    1 to 8 (y direction)

    So I dont have to carry any information about what type of pieces are on what square.

    There is a problem when capturing pieces, so when I am checking for the current positions in my loop, I will have to know :

    1) What the coordinate of the piece that was taken off the board
    2) The starting position of the capturing piece

    I can send the board position, along with 1) and 2) over the serial line to VB, VB makes the comparision and then sends the derived move to the chess server.


    I could look for 1) and 2) only then send over the serial, but there can be a lot of 'what if movement' before the final position is reached -

    I plan on having a "Clock" switch, when I'm done with my move I hit the "Clock" and that will send the position over to VB to be derived...

    Post Edited (Veramacor) : 10/16/2007 4:06:17 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-10-16 15:41
    Vermacor -

    I still see numerous problems, but I may not understand your planned process. Is the actual move (d2-d4? - your example) manually entered into the chess server (or whatever software program there might be) ?

    Will castling, en passant pawns and queening be recognized properly? It just seems to me there is a good deal more to this, but again I'm not sure of the exact purpose of the board and its proposed switches.

    If it's merely a case of determining "is there a chess piece on this square or not" and/or "has this previously empty square just been covered by a chess piece", an optical solution (infrared) might be quite useful, with reflective tape on the bottom of each of the chess pieces. Whether it's cost effective or not would have to be calculated.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • VeramacorVeramacor Posts: 6
    edited 2007-10-16 15:56
    The chess server (FICS) takes care of the rules, en passant, castling, ect and will notify of illegall moves

    I have already created a basic VB to FICS interface via a winsock connection.

    I can find a game (black or white)

    get position info from FICS

    and make a move

    eg:

    sending just an e1-g1 to FICS will allow me to castle FICS checks ALL chess conditions

    ie, if I am attempting to castle into check, FICS will send back over the winsock line...

    'Illegal Move!"

    The hard part thus is done for me. The tedious part of internet chess is the 2 dimensional interface and using the mouse to make moves is not the same experience as making moves with real pieces.

    There are interface boards available but they are fancy wood boards, costing $300+!!! Most of them are not tournament size and most importantly, most chess games are played on vynl rollup boards with green and white squares, not smaller wood boards costing mega bucks.


    Sooooo,

    The plan is to be able to slap on any old standard vynl board with elective choice of green and white, brown and white, blue and white, etc squares over an interface

    All I need to take care of is what the Reed switches are telling me are currently set


    As far as the method of sensing, I'm pretty much commited to trying the reed switch approach. I scored 70 (count SEVENTY) reed switches for $12 on ebay , and what better to use 64 of them playing chess [noparse]:)[/noparse]

    Post Edited (Veramacor) : 10/16/2007 4:02:41 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-10-16 17:54
    Hmm.

    A chess board is 8x8. So, if you make it one bit for each square, that's 8 bytes to 'capture' the whole board. Then, you'll want to 'compare' one board-map to the next board-map. So you need 8 bytes for 'old' board, and 8 bytes for 'new' board.

    It should be possible to wire the relays as a 'matrix'. So the left-most column of cells would be wired to I/O bit zero. You'd have a pull-down (10K ohm resistor) to Vss on that column. The next to the right would go to I/O bit one, etcetera.

    So then, you put down your pieces. This would 'fully populate' rows zero, one, six and seven. Now, your row zero would have the OTHER end of its relays tied to I/O bit 8. So, to 'scan' that row, you pull I/O bit eight high, then 'read' bits zero through 7 into a byte. Every open relay would give you a zero, and every closed relay would give you a one.

    Then, you put I/O bit 8 low, and put I/O bit 9 high. Now when you read bits zero through 7, you're reading the relays on row #1, that have their "other" ends tied to I/O bit 9. Again, open relays read as zero, closed relays read as one.

    One brute-force approach would be to simply send all 8 bytes to the PC everytime a bit changed. Then the PC could convert that into something meaningful in terms of piece movement.

    Edit:· Well, that was an interesting problem.· Here's a complete BS2 side program to implement it.
    Edit2: I'm attaching a 'txt' version.· The only thing I'm not certain of is the exact syntax to 'scan'
    ······· through the 'row' pin -- I'm sure there's a simple syntax for it, though.


    Post Edited (allanlane5) : 10/16/2007 6:11:45 PM GMT
  • bubbleheadbubblehead Posts: 36
    edited 2007-10-17 06:40
    Configure the switches in each row (or column) of the chess board·to·drive the input·of an R-2R digital-to-analog converter.· The output voltage will be a function of which switches are closed.· Read the output with an ADC or use the RCTIME function to read the voltage.

    see http://www.ikalogic.com/dac08.php·or ·http://en.wikipedia.org/wiki/Resistor_Ladder
Sign In or Register to comment.