Matrix of APX9141 to detect chess pieces

NachoGoro

Oct 24, 2024
3
Joined
Oct 24, 2024
Messages
3
Hi all,

I have started looking into electronics after over a decade since I last touched it, with the idea of making a chess board which automatically detects the moves made on a chess board. I will be using a Raspberry Pi inside of it as it should be powerful enough for any future features I add, and I have a few laying around.

My idea is to have a magnet under each piece, one polarity per color, and use a matrix of Hall effect sensors (one sensor per square) to detect if I have a piece on a square or not, and its color. I can deduce the move made in that case provided it was a legal move by using the rules of chess (already have written a library for that).

I guess my first question is: is APX9141 the right sensor for the task? I can see it has two outputs, one per polarity, so it looks promising!

If so, I was wondering how I could wire an 8x8 matrix of these sensors to get the state of the board. My current idea is to use 6 GPIO pins (3 to specify the desired column and 3 to specify the desired row) as inputs to the detecting circuit and 2 GPIO pins to read its output (one pin per color).

I was thinking of using a 3:8 decoder to power only the row I am interested in. Then each row passes that power as Vcc only the sensor for the column we are looking (using another 3:8 decoder per row), and I OR the north outputs together and the south outputs together to get 2 bits of output per row (one per color).

I would then OR the white ouptut and the south output of each row to get two output signals, one indicating if there was a white piece in the (r, c) square and the other indicating if there was a black piece in the (r, c) square.

Is this a reasonable approach? I can see it is based on the assumption that a sensor whose Vcc and GND are put to ground will output low and not a random value, not sure how reasonable this assumption is!

I can probably spare a few pins, so I'd be happy to go with other approaches which use more pins if they are easier! I guess I could read a whole row in one go and place the read in a shift register, I am not sure if that would draw too much current from a pin though.

Thanks in advance :)
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
is APX9141 the right sensor for the task?
Imho no.
The two outputs are not independent: DOB is the inverse of DO. Furthermore these outputs are meant to directly drive the coils of brushless DC motors. While the sensor could be used for your purpose, it is way overengineered for this job.
it has two outputs, one per polarity,
See above. But in the light of
I can deduce the move made in that case provided it was a legal move by using the rules of chess
you don't even need different indications for black or white as per the rules teh position of all pieces can be determined from the starting configuration and the moves. Therefore any inexpensive Hall sensor that detects the presence (or absence) of a magnetic field should work.

Is this a reasonable approach?
Using a matrix is definitely reasonable, provided you scan the matrix fast enough to detect the changes in the pieces' position in "real time". Otherwise you would need way to many pins.
 

NachoGoro

Oct 24, 2024
3
Joined
Oct 24, 2024
Messages
3
Ah, you are right! I misunderstood the datasheet and thought there would be no output in the presence of no magnetic field. Thanks for correcting my mistake :)

Back to the drawing board then! Also, if someone wants 70 APX9141 when they arrive in two weeks just let me know

you don't even need different indications for black or white as per the rules teh position of all pieces can be determined from the starting configuration and the moves.

I think I do for realiability. If one of your pieces can take two or more of the oponent's pieces, and you take one of them, if the board can only detect the presence/absence of a piece in a square it won't know which one of the pieces you took. You could scan the board continuously to figure out if you saw any changes in a square in between moves to resolve ambiguity, but that would be unreliable if the user accidentally knocks pieces down for example.

By knowing the color of a piece in a square and the rules of chess, you can resolve that ambiguity provided the user plays legal moves (with the exception of the promotion piece, but I'll deal with that).

Do you know of any sensor which could fulfil my needs to indicate "North pole", "South pole" or "No magnetic field"? I guess I could use an analog sensor and an ADC, but was hoping to keep it digital for simplicity.
 
Last edited:

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
was hoping to keep it digital for simplicity.
It's not entirely impossible, such sensors may exist - I'm simply not aware of them.
The issue with a purely digital sensor is that you have 3 states:
  1. no chess piece above the sensor
  2. white chess piece above the sensor
  3. black chess piece above the sensor
which means you need two lines to encode these states, e.g. as 00, 01 and 10. This doubles your wiring. Whereas an analog sensor could easily respond by e.g. -1 V, 0 V and + 1 V (these numbers are arbitrary, for explanation only) on a single wire.
 

NachoGoro

Oct 24, 2024
3
Joined
Oct 24, 2024
Messages
3
Yes, I am starting to see the appeal in the analog sensor. I was trying to keep it digital because the Raspberry Pi has no analog pins, so I would need to add an ADC and then use SPI to read the value, making the interface dirtier and adding complexity. I just realised I could use an Arduino Nano to do the ADC, since it has analog pins, and use two of its GPIO pins as a digital indicator.

Thank you so much for the help, this is looking more concrete now :)

I can predict soldering 64 sensors will be tough even with only 3 pins per sensor (no previous soldering experience!) and cable management will be challenging. Designing and printing a PCB is out of my skill set atm. I guess this isn't really the post for this, but since we are talking, are you aware of any solderless options I could use to implement this system modularly? E.g. solderless sockets which would allow to split a signal into multiple pins (like a breadboard row), or to allow simple cable connection to a pin in a DIP IC (again, like a breadboard)?
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
14,271
Joined
Nov 17, 2011
Messages
14,271
Any solderless method is "good" for experimental purposes only. In the long term you will be plagued by contact problems and lack of reliability.
I suggest you use perfboard if you can't design a pcb. Here's an article to get you started.
 
Top