count += piecesTemp[row][4];
piecesTemp[row][5] = !digitalRead(7);
count += piecesTemp[row][5];
piecesTemp[row][6] = !digitalRead(8);
count += piecesTemp[row][6];
piecesTemp[row][7] = !digitalRead(12);
// Oddball because we skipped 9, 10
count += piecesTemp[row][7];
// for serial RX, TX, Serial2 on Teensy 3.1
return count;
// return number of pieces found in this row
}
unused by circuitry external to the microcontroller. Being
able to use Serial.print() statements in your code to be
read in real time using the embedded serial monitor in the
Arduino GUI is a great aid in debugging code. Pins 9 and
10 were also left unconnected and brought out to pads
on the PCB. This pair of pins implements RX2 and TX2 on
the Teensy 3.1 and can be used to connect the
chessboard to other external circuits or a PC.
// Read all 8 lines of the Hall Effect Sensors
int readHall(byte piecesTemp[][8])
{
// The function calls readLine() 8 times to read all
// 8 rows of Hall Effect sensors
// When finished piecesTemp[8][8] has positions of
// pieces on board
// Before each read we set the 3 bit address to the
// 74138
// The total number of pieces on the board is
// returned
int count = 0;
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
digitalWrite(A2, LOW); // 000
delay(1); // let 3144 settle
count += readLine(0, piecesTemp);
digitalWrite(A0, HIGH); // 001
delay(1);
count += readLine(1, piecesTemp);
digitalWrite(A0, LOW); // 010
digitalWrite(A1, HIGH);
delay(1);
count += readLine(2, piecesTemp);
digitalWrite(A0, HIGH); // 011
delay(1);
count += readLine(3, piecesTemp);
digitalWrite(A0, LOW); // 100
digitalWrite(A1, LOW);
digitalWrite(A2, HIGH);
delay(1);
count += readLine(4, piecesTemp);
digitalWrite(A0, HIGH); // 101
delay(1);
count += readLine(5, piecesTemp);
digitalWrite(A0, LOW); // 110
digitalWrite(A1, HIGH);
delay(1);
count += readLine(6, piecesTemp);
digitalWrite(A0, HIGH); // 111
delay(1);
count += readLine(7, piecesTemp);
delay(100);
return count;
// return count of all pieces on the board
}
Instead of a D port read, we use eight digitalRead()
statements that are negated to read a single row of
sensors. The Hall effect sensors are open collector, and
when activated they read as a 0. So, for clarity, this is
negated to a 1, representing a chess piece in that location.
The readHall() function calls readLine() eight times,
after setting the three-bit address to the 74HCT138 to
select each row. Here again, a port C output could have
simplified things a little, but that could have interfered
with the A4 (SDA) and A5 (SCL) I2C signals which are
reserved for communicating with an LCD display or RTC.
After the call to readHall(), the pieces Temp array will show
the locations of all the pieces on the chessboard and
return the total number of pieces found on the board.
At this point, all of the functions that interact with the
hardware need to be described.
We will pause here for this month. Next time, there
will be an overview of the main sections of the software
that contain the logic for supervising a chess game
between two players. The loop() section of the program
takes you through the first player's turn and then, on the
next pass through, changes the turn to the second person.
Inside the logic is the ability to detect which piece is lifted
and display all its possible moves. There will also be some
error checking and looking for a king in check or
checkmate. If you just can't wait, you can obtain the entire
Arduino program from the download section. Keep in
mind that this program is intended to run on a Teensy 3.1.
NV
Teensy 3.1 microcontroller
74HCT138 3-to 8 decoder
7414 Dual Schmidt trigger
Allegro 3144 Hall effect sensors ( 64)
PARTS
2N3906 PNP transistors ( 8)
470 ohm Resistors ( 8)
LIST
2700 μF 6. 3 volt Electrolytic capacitor
0.1 μF Disk capacitors ( 2)
Five volt/two amp Power supply, wall wart type
Power jack to match power supply
LCD display, four-line/20 character with I2C two-wire
The functions readLine() and readHall() do the work of
scanning the 64 board positions and creating an 8 x 8
array telling us where pieces are located, and also return
the number of pieces found. The readLine() function scans
a single row. Notice here that it would have been simpler
to do a read of the D port pins 0-7 on the Teensy 3.1. In
one line of code, we would have read all eight Hall effect
sensors in one row. However, that would mean that we
could not use pins 0 and 1 with our serial monitor.
interface
Momentary pushbutton switch
Programmable RGB LED strip, five meters, 60 LEDs per
meter
(You'll need 256 LEDs of the 300 LEDs in the strip.)
Printed circuit board
Insulating varnish like Super Corona Dope™
Analysis Chess Piece set from www.wholesale chess.com
Neodymium disk magnets, 10 mm diameter by 3 mm thick,
grade N50 ( 32)
In most of my projects, I try to leave these two pins
Miscellaneous header pins, four-pin header jumper cable,
solid 22 gauge hookup wire, screws, nuts washers,
spacers, wooden frame, 1/4 inch Plexiglas
26 January 2017