Hardware

Arduino, Rasperry PI, Reed Switches, LEDs & more

The Hardware consists of the board plus the various bits of electronics, buttons etc. You can see a video of the hardware components here.

The Board

I needed a board that was thin enough to allow the magnets to activate the reed switch.

My experiments showed me that an 8mm board worked well with 1cm diameter magnets. However all the good quality chess boards I found were at least 15mm thick. so I decided to build my own using 50mm strips of veneer on 8mm MDF board see Building the Chess Board. This worked well.

The Pieces.

I used a standard set of Staunton pieces and simply glued 10mm x 1mm Neodymium magnets to the base:

DSCF0458

 

The Electronics:

The parts list was:

  • Arduino Uno to control the board. I chose the Uno because it is easily available in the UK. The Teensy 2++ would have been a better choise as it has more pins and more memory
  • Raspberry Pi
  • 64 5mm green leds
  • MAX7219CNG LED display driver. A brilliant little device that makes controling the LEDS very easy.
  • 64 Reed switchs
  • Centipede Shield  add-on PCB for Arduino . It uses the Wire I2C interface on analog pins 4 and 5 to provide 64 general purpose I/O pins which I used to directly address each reed switch.
  • LCD Display: basic 20 character by 4 line display. Utilizes the extremely common HD44780 parallel interface chipset
  • Four buttons for chosing options etc
  • Piezo buzzer
  • 64 10mm x 1mm Neodymium magnets

Chess-Hardware

Click here for a higher quality image

57 Responses to Hardware

  1. Berger says:

    Hi,

    Max, I see that you have solved the controll of a LED in each square (64 LEDs).

    In case you wanted to use 2 arrays of 8 LEDs (rows and columns), I built some time ago a simple demultiplexer circuit for Bryan. This circuit was never used because Matt didn’t implement its control (from Teensy) in his project SishFishPi.

    Its operation is very simple:

    1) It works with 5V: perfect to connect to Teensy++ or any other USB device.

    2) 3 pins to select row LED, and other 3 to select column LED. With 3 pins (3 bits) yo have 8 possibilities. For example:

    (0=GND, 1 =5V)

    000 – row 1
    001 – row 2

    110 – row 7
    111 – row 8

    And the same for the columns:

    000 – column A
    001 – column B

    110 – column C
    111 – column D

    2) Enable Pin (E):
    0 = All LEDs off
    1 = The previously selected LEDs will turn on.

    4) The best, I think, is to make the selection “before” you “E”nable the circuit.

  2. maxchess says:

    Berger,

    The circuit you have designed looks interesting, however my knowledge of electronics is limited.
    My alternative was to use the MAX7219, which is quite cheap, £9.41 from proto-pic and which has a set of libraries that run on the Arduino & Teensy.
    Also the chip is driven by just 4 pins.

    The libraries allow you to control up to 8 MAX7219s = 8×64 LEDS daisy chained together!, for the chess board we need only one.
    You can then address any LED directly, so for example to switch on the LED in the first array (0) at position 2, 7 (in an 8×8 array) we just say
    lc.setLed(0,2,7,true);
    to switch it off we say
    lc.setLed(0,2,7,false);

    the library also allows us to switch all LEDS off or on and off course we can make them blink by looping around on, off with a delay.

    You could also drive the MAX7219 directly from a Raspberry PI using the SPI interface or directly (see http://browse.feedreader.com/c/Raspberry_Pi_Blog/283371850) but it requires more effort in code and uses most of the GPIO pins, so I think you are still better off letting and arduino/teensy drive hardware.

  3. Michael says:

    Hi Max,

    would you provide the wiring diagram?

    Thanks and regards, Michael

    • maxim says:

      Michael,
      I am not an engineer, just a hobbyist, so I would have no idea how to draw a wiring diagram, but I have added a better version of the hardware layout picture, so you can see better how everything is connected.

      I hope this helps.

      Max

  4. Hi!

    I will try to duplicate your great achievement. I wonder what kind of “read switches” you use?

    Sincerely
    Pierre 🙂

    • Max says:

      Hi, I just used cheap reed switches I bought from China on EBay. They are quite fragile so order spares, but once in place they are very reliable.

  5. Olivier says:

    Hi Max,

    Congratulations for your great work. It inspired me to try to do the same

    I’ll start by building the usb chessboard using Berger’s sensor Matrix. https://sites.google.com/site/bergersprojects/reedcb/matrix

    Would it be possible to indicate where the soldering should be done to connect the centipede to the reed? should it be at the row level (x) after the diode? (the other side of the reed being connected to the column (y)

    I have also a question regarding the power supply. Do you use only one power on RPI that supplies also the Arduino & the Centipede?

    Thanks
    BR, Olivier

    • Max says:

      Oliver,
      The great advantage of using the Centipede board for connecting Reed switches is that you do not need any diodes, pull up resistors or other components. As it says on the “Building the board” page;

      The Reed switches were first glued in place on the underside of the board and then soldered at one end with a common earth, and the other end directly to the strands of 20 strand ribbon cable (16 connections, 2 common earth and 2 unused) the other end of this cable plugged directly into the Centepede card.

      The LEDs and the reed switches are two completely separate matrices. So just to be clear, for the Reed switch matrix you first run one continuous wire as common earth to every square and solder one end of all the Reed switches to that. (It doesn’t matter which end) then the other end of the Reed switch each has a separate direct connection to the Centipede board. So you the address the Centipede board to test if the connection is open. In testing it means you can check each switch directly so fault finding is easy. This makes the wiring easy, but not very elegant and NO diodes required.
      So you choose the x,y connection to match the LED Matrix. I wrote a test program that lit an LED when the Reed switch was activated to make sure the two matched. At first they didn’t so I had to write a little mapping routine rather than re solder the Reed switches.

      On the power supply I used a standard RPI power supply for the pi and the Arduino is powered off the Pi via the USB connection. I have also found I can power the board with one of those portable powerbanks used to power mobile phones. The Centipede board is just a switch, it doesn’t use any pwer. Only a few LEDs are ever on at one time so the whole systen is not very power hungry.

      Please let me know how you get on, only a few people have built one of these. If you have more questions just ask, Max

  6. Olivier says:

    Hi Max,

    thank you a lot for your answer. In Berger site they wrote about ghost effect (diode being a way to solve the issue). I assume centipede and direct connection solve this problem.
    I created 2 diagrams to represent my understanding for options on the reed Matrix and connection to the Centipede. https://we.tl/sSEjq1sX8Z

    Do you think for Reed Matrix the diagram “Wiring_Diagram_Column” be enough?

    About what you wrote:
    “20 strand ribbon cable (16 connections, 2 common earth and 2 unused) ”
    the continous wiring is then connected to the ribbon too. Right? why 2 strands are necessary for the common earth connection?

    Also for the second ribbon only 16 connections are to be used (no need to connect the 2 common earth). Is that correct?

    For Led, I do not see clearly the relationship between the “8 strand ribbon cable glued” and the matrix where each led is soldered (one leg x and one leg y). I tried to zoom the image but the definition is not high enough to see the details of the wiring.

    Sorry I have very limited knowledge in electronics and would like to start with a good basis.

    Best regards
    Olivier

    • Max says:

      Olivier
      You are right having direct connection means there is no ghosting, so no need for Diodes.
      For wiring the reeds I suggest using one long earth wire that snakes its way backward and forward. You are right that in theory you should only need one strand of ribbon cable for the earth, but because the wire is long I made 4 earth connections, 1 every 2 rows. So I used two connections on each ribbon cable, but all going to the same earth

      For the LEDs there is a diagram and a complete description on how to wire the matrix in the links section. Its LED Matrix
      This also gives detailed instructions on connecting the MAX72XX .

      I hope this helps. Max

  7. Jayant says:

    Hi ,
    Very interesting project. Appreciate the lucid way you have explained.
    Is there any DIY shop where I can get all the components for a quick assembly of the chess board?
    I am not sure if I can get all the components in India.
    Pls suggest.
    Thanks
    Jayant

  8. vitor says:

    on this project, you dont identify each peace by itself right? you only know what peace is played because you detect only with the reed switch right? All reed switch are activated at same time and each one is identified by position?

    • Max says:

      That’s right, I track the pieces rather than “identify” them. So I know the starting position and then update where each piece as the game progresses. I have looked at various technologies to track pieces such as RFID, but that requires 64 sensors. DGT boards cost around $1000 and use a patented passive LC technology to identify actual pieces. Any ideas for a practical low cost method much appreciated.

  9. Brian says:

    See my comment under Raspberry pi only build.
    Although my board with vertically mounted reed switches is finished and works perfectly ( much better than horizontal mounting). I would still like a board with piece recognition, and can’t justify the cost of a DGT board..
    I have the 64 hall sensors and am experimenting with them.
    With the sensors glued to the back of the chessboard, routed so there is 1mm thickness of wood. Then mounting the magnets in the chess pieces between 0 and 10mm deep for the different pieces, I can easily differentiate between them. I am using 10mm diameter magnets at the moment and the value stays constant as long as any part of the magnet is directly over the sensor, but quickly falls away when moved a few mm’s off centre. I am waiting for 25mm diameter magnets to see if this works better for pieces placed off centre on the square.
    I will be using 4 of 16 channel analogue multiplexers to read from the 64 squares.
    http://www.ebay.co.uk/itm/121933332237?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT.

    At the very least this method could replace the reed switches and diodes, and hopefully with some careful programming full piece recognition.

  10. Elliot says:

    Hey Max,
    Great project. My friend and I are attempting to recreate this for a project in our Python class, and we were having some issues figuring out the wiring. We were wondering if we’d be able to get some better pictures of how you have everything connected together. Any help is appreciated, thanks!

  11. Max says:

    The wiring on my first attempt is a bit of a mess, but I have tried to design it in modular form. If you are just starting I would strongly recommend you build the NOX example first.
    The chess board hardware is really just two separate grids. A grid of LEDS and a grid of reed switches. So start your hardware development by understanding how to wire these up these so you can switch on any LED and read any switch, using python. That was the purpose of the NOX examples. Once you can do that the rest of the hardware is just an LCD screen and a few buttons.
    My first build used an Arduino to do this, its what Arduinos are good at but they uses a simple form of C, not Python. In theory it should be straightforward to do this in python all on a Raspberry pi and the Noughts and Crosses (NOX) example gives you the full Python code and wiring diagram. If you can do it on a 3×3 grid its just a matter of scaling up to do 8×8 and introducing the more complex logic for chess.

  12. waasay zia says:

    hi my names Waasay, i am making this project as a school project, i need help understanding where all the connections of ◾MAX7219CNG lead to, like where each pin is connecting

  13. Max says:

    For the LEDs there is a diagram and a complete description on how to wire the matrix in the links section. Its LED Matrix
    This also gives detailed instructions on connecting the MAX72XX .

  14. Waasay Zia says:

    The link u shared is about a different board, how do I use this to make my own code, would it be possible if u can give me head start on the code u used and what is the silver thing next to the lcd display and which raspberry pie did u use for the project

  15. Max says:

    The chess computer consists of two systems:
    The Arduino based USB board
    The RPI based chess engine.

    The link I shared is a Arduino USB chess board. The systems communicate serially using the USB connection.
    More on USB boards at:
    https://sites.google.com/site/bergersprojects/reedcb/matrix

    I used an Arduino UNO but you could use a Nano or better still a Teensy (Arduino derivative)

    As described elsewhere on this site the Arduino board code is simply two matrices, one to read the reed switches and one to control the LEDS, see the Useful Stuff page for details

  16. Waasay says:

    What is the silver thing next to the lcd display

  17. Waasay Zia says:

    Can u send me the diagram or any hints on how to connect the lcd display and the 4 push buttons to arduino please, because all the diagrams online are different

  18. Max says:

    This web site assumes that you are familar with general Arduino techniques and programming. There are also links to some useful sites on the “Useful links” page
    The buttons are just simple Arduino switches. For LCD display see:
    https://www.arduino.cc/en/Tutorial/LiquidCrystalDisplay

  19. Waasay zia says:

    Did u use any other electronic components such as resistors when linking the led controller to the arduino and the lcd to the arduino or do they both run off 5v

  20. Waasay zia says:

    Also can any type of lcd screen be used or does it have to be the exact same as the one u used for example does it have to be the HD44780

  21. Waasay says:

    Also can any type of lcd display screen be used or does it have to be the same type you used for example does it have to be the HD44780

  22. Waasay zia says:

    Is it possible that u can send me another picture of the chessboard from underneath with a clear way of connections on my email, Waasay.zia123@gmail.com

  23. Waasay zia says:

    What do all the buttons do, as in what options do the buttons select and what is displayed on the lcd display

  24. Waasay zia says:

    Do we have to write our own python program as well or can we just build on the one u have made, sorry for asking a lot of questions, it is my final year project for school

    • Max says:

      You can use the python program on the site as a base but yes you have to write your own python program for the pi and if you are using on, your own program to control the arduino. This project assumes you are already a competent programmer and familiar with Arduinos. It is quite possible to teach yourself all this stuff, but the chessboard is not a good first project.

  25. Waasay zia says:

    Is it the Same code as the one used in only the arduino version as in the one that is on github, the picochess one made by bran I think for arduino. Because I can’t really start another project I’ve already made the physical build the only problem I’m having is for the coding, I’ve already spent a lot of money on this, is it possible if u can help me out payment won’t be an issue, I would really appreciate that but it is completely up to u

  26. Brian says:

    Sorry, I haven’t looked here for a while,
    To get my code to work, you need to build your board exactly as in the fritzing circuit diagram on the github site (.fzz). it’s not the same as the board built by Max.
    You then need to program the arduino with the code also on the github site.
    To test the arduino section you can monitor the serial output of the arduino and see that you get the move you made eg A2A4.
    Then get your raspberry Pi working with the rasbian distribution and copy the python script to the pi. connect the ardiono to the pi usb.
    This does create a really excellent chess computer, but it is quite difficult to get it all working together if you are a beginnere with arduino and python programming.

  27. Brian says:

    Actually. It is better to start with the image at https://www.picochess.org/.
    Then replace the picochess directory with mine.

    Saves you the trouble of setting up all the python dependencies.

  28. Waasay zia says:

    In the model I m making, I replaced the Max7219 with a adafruit 1.2 8×8 led backpack, would that do the same function if I replace the max library with the adafruit library, also I’ve got the physical built already made I can’t really change much of it

  29. Brian says:

    There would be no problem doing that as long as you can write code for the arduino.
    It just sends moves in text format(eg d2d4),
    and responds to moves from picochess. use my code as example.

  30. Waasay says:

    Did u use a centipede board as well, if so which side of the connections were supposed to go to the common earth, the two that said gnd or the two that said com

  31. Brian says:

    I didn’t use a centipede board, and I don’t know how to connect it.
    The circuit diagram for my board is on github.

  32. Waasay says:

    Ok so I have already made the physical build of max’s Project, except replaced the max7219 with an adafruit driver instead, i am pretty sure all the connections are correct, is there anyway that you can help me come up with a code that can work on my design, the main trouble o am having is getting the led’s code and the reed switch code

  33. Waasay says:

    Ok actually I can modify mine to make it like urs, is the Raspeberry Pi necessary and if so did it use the same Raspeberry Pi code that is on this website with stockfish

  34. Brian says:

    I think you are on a tight schedule, so you should not try to get my project working. It is too complex. Max’s project is anyway much better documented.
    I recommend you follow the steps outlined by Max in his recent post. but you need at least a basic understanding of electronics and c programming to build either project.
    Otherwise, you could follow all the steps perfectly, but the smallest problem, such as a bad solder joint or a faulty diode would be immpossible to trace.
    Perhaps it would be better to start with Max’s Tic tac toe project first.

  35. Waasay says:

    I can’t really do that anymore, this project has been locked in, I have all of next week, this week and two weeks holidays to get a basic model built, I have already written the portfolio and report for this, in your project, are all the codes given, and if so does it also use a Raspeberry Pi with the same code as in this site, the reason I am unable to do max’s Project is because he hasn’t provided a source code and to make one from scratch is near impossible for me at least in your one the source code has been provided

  36. Brian says:

    On my github is EVERTHING you need to build this project.
    The circuit diagram (Chessboard.fzz, use the free fritzing program to view it)
    The Arduino code (Chessboard_S_v2.ino)
    The modified picochess code for the raspberry pi.
    use this link http://docs.picochess.org/en/latest/installation.html. to create the pi image
    then replace the picochess directry on the pi with my version from github
    If you need some help, give me you email rather than flood this forum with troubleshooting comments

  37. Waasay zia says:

    My email is Waasay.zia123@gmail.com, what’s urs, I just need help figuring out the connections of the buttons, I don’t think the image u provided and the circuit diagram match

  38. Andrew says:

    When I try to run the code, picochess, it comes up with an error saying,

    from uci.engine import UciShell, uciengine
    From utilities import Observable
    From configobj import configobj, configobjerror, duplicate error

    How do I fix this

  39. Andrew says:

    When I try to run the code, picochess, it comes up with an error saying,

    from uci.engine import UciShell, uciengine
    From utilities import Observable
    From configobj import configobj, configobjerror, duplicate error

    How do I fix this

  40. Andrew Lang says:

    Hello

    I need help with the code for the Pinochess, it keeps coming up with errors, may I have ur email, Brian, so u can help me out on that

  41. Brian says:

    ErnisiusDF@Gmail.com.
    Please send me a screenshot of the python error message.

    When you copied the picochess directory, the engine executables attribute will be set by linux to no execution. Don’t ask why, I am not a linux expert, but you need to set all the engines in the engines directory to r,w and x using the attrib command. Don’t know if that is the problem though it was for me.

  42. Cory says:

    Hi everyone,

    I want to make an 11×16 reed switch matrix, so that means I will have 176 individual sensors. Instead of chess I’m are doing Dungeons and Dragons, that’s why I need a larger matrix. Are three centipede shields the best option to connect each of them or are 2-74HC595 and 2-74HC165 shift registers better to make the matrix?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *