Programming Ideas

We have a 8x8 matrix, on which we will have to perform continuous sampling to detect the changes:

Because of the chosen configuration and the orientation of diodes (which prevent the "ghost key" effect), one way to do it would be:

  • Connect the rows to 8 pins of the microcontroller, setting them as OUTPUT, and initializing them all to '1' (High).

  • Connect the columns to 8 pins of the microcontroller, setting them all as INPUT with pull-up resistor enabled.

  • Set to '0' (Low) one row and read the value of all columns. Do the same with the other seven rows, one by one.

  • In every full sampling of the board (of the 8 rows), we obtain a matrix of 8 x 8 bits.

  • Detecting changes that occur in the matrix at every sampling, we can know what piece was moved.

It would be something like this...

For example:

When scanning row 3 (setting it to '0'), a read of the columns gives us:

R3: 11111011

While in a complete sampling of the chessboard we obtain:

R8: 00000000

R7: 00001000

R6: 11111111

R5: 11110111

R4: 11110111

R3: 11111011

R2: 00001000

R1: 00000010

This is the way I have chosen, because my intention is just to detect changes in the squares that the microcontroller will translate into commands like 'g1f3', leaving the rest of the job to the host device.

Of course we have to consider all those "special" situations that will occur during the game:

  • Captures (and En passant)

  • Castling

  • Promotion

These situations can be controlled by the microcontroller program, or in the host device: this depends on what you expect of your project, where you plan to connect the electronic chessboard, etc.

ARDUINO

Although I have used a Teensy development board (programming in C language), a good choice would make the same project but using an Arduino, taking advantage of example programs and the great tutorials available.

For example:

You could use these boards: Arduino Nano, Arduino Micro, ...