Skip to content

Conversation

@Ay1tsMe
Copy link

@Ay1tsMe Ay1tsMe commented Oct 17, 2025

This script runs through the board and gets the average threshold reading for each photoresistor when a piece is on the square. This is useful when finding the correct threshold for the particular lighting and not relying on trial and error.

The process is as follows:

  1. Empty chessboard to get unoccupied readings
  2. Place 8 pieces on each rank, starting with A1 to A8
  3. Collect occupied reading for rank
  4. Repeat steps 2 and 3 until done

It has both a global and individual mode that outputs a threshold value the user can paste into there .ino file.
Example:

// Individual
unsigned short THRESHOLD[64] = {
  // A1-A8
  436,  411,  458,  523,  405,  396,  539,  341,
  // B1-B8
  475,  471,  454,  470,  565,  485,  398,  468,
  // C1-C8
  322,  299,  327,  272,  340,  299,  304,  339,
  // D1-D8
  312,  355,  313,  333,  331,  344,  293,  467,
  // E1-E8
  692,  718,  719,  726,  725,  681,  722,  736,
  // F1-F8
  726,  711,  698,  690,  733,  727,  723,  682,
  // G1-G8
  576,  580,  604,  667,  652,  596,  657,  659,
  // H1-H8
  525,  488,  479,  647,  644,  660,  559,  656,
};
// Global
const unsigned short THRESHOLD = 496;

You can toggle between which mode you want to use by editing this variable before uploading firmware:

// !!! choose mode: 1 = global single value, 0 = per-square array !!!
#define USE_GLOBAL_THRESHOLD 1

The script also has an optional -s, --squares flag which the user can skip the calibration by rank and instead do it by square. This is useful if one or two sensors need adjusting without having to recalibrate the whole board.
Example:

// Calibrates squares A3 and D5
python calibrate_thresholds.py -s a3,d5

@Ay1tsMe
Copy link
Author

Ay1tsMe commented Oct 17, 2025

NOTE: This code should only be merged if LiBoard/Arduino#4 is also merged

@Ay1tsMe Ay1tsMe changed the title calibration_thresholds.py script calibrate_thresholds.py script Oct 19, 2025
Ay1tsMe and others added 5 commits October 19, 2025 11:52
    Instead of manually specifying global or individual threshold type,
    the script automatically detects threshold type with '!' command.
    Also fixes single square calibration
feat: detect Liboard type and fix single square calibration
feat: Enter quiet mode to avoid bitboard output hanging calibration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant