How about optically?
Put a series of 5 light & dark spots on each piece, and 5 optical sensors at each location.
Allows recognizing 32 pieces - or 30, if all light (no piece) and all dark (piece upside down, misoriented) are treated as 'error' states.