This section describes how to read the 64 Reed switches directly in Python using Symbus. In my original build I used a centipede board, which is just 4 MCP23017’s stuck together.
I’ve built the full 64 grid board as described here and it works!
Each MCP23017 can control 16 inputs or outputs. For our chess computer we are only interested in inputs (the Reed switches). So there’s 4.
The basic approach is described in this excellent tutorial. It describes the basics of wiring an MCP23017. An important point to note is that we are using four, so each must have its own address that is set as part of the physical wiring. You can have up to eight MCP23017s. We just want four and I have chosen the addresses 0x21,0x22,0x23, 0x24 (see the Python Code)as 0x20 is used by another component.
Python Program to read MCP23017s
This approach uses SYMBUS to read the MCP23017, so you need to install that first. (I tried using WiringPi, but there seem to be version problems and I couldn’t get it to work)
My code for this routine is in this Zip file:
You should be able to figure out whats going on by comparing my code with its comments to the tutorial. The differences are that I set up internal pull ups, which simplifies wiring
Its all done by comparing binary values in registers (1 for open, 0 for closed), which makes it lighting fast and very efficient.
The program reads the board and prints out the x,y coordinates of a square and how it changes (open or Close).
Wiring for the four MCP23017
is shown below, but again it is just an extension of the tutorial.
This is how you wire up one MCP23017:
For the whole board you just wire up four of these, but change the wiring of A0, A1 & A2 which changes the I2C address
The complete board: (slight error on number 3 but you get the idea)