A full-featured Rubik's cube timer made to run on a Raspberry Pi running Raspberry Pi OS. Inspiration taken from the stackmat timer for the hardware and from csTimer for the software.
Timer.Demo.mp4
This timer is made to integrate with a 3d printed case I designed. The case integrates a 3.5 inch touch screen, a 10000mah battery, and two buttons to start and stop the timer stackmat style. The buttons connect to GPIO19 and GPIO26 (physical pins 35 and 37).
View the design on Printables to learn more
This is an experimental method that assumes the Pi you're using is a throwaway device meant to act solely as the timer. The device used to make this script is a 4GB Pi 4 with SSH + WiFi pre-configured before install but with no LCD drivers.
- Make sure when you enable
ssh
, that the username ispi
and not the name it suggests- The timer code assumes this username and will not work otherwise
- The screen will stay white and you will have to
ssh
into it using the credentials you specify when burning the device: the LCD drivers being installed is included in the script
- If you plan on doing this process multiple times, it is recommended that you download the
img
/xz
and have it on you in case it tries to re-download it another time - If the
curl
command doesn't work, try towget
it and then runbash install.sh
To start, ssh
into your Pi and run:
bash <(curl -sSL https://github.com/mrusse/PiMatTimer/raw/main/install.sh)
Make sure your username on the Raspberry Pi is pi
and that you clone this repo in the $HOME
directory (e.g., /home/pi
). The script assumes these paths. Run cd ~
if you are unsure if you're in the home directory.
When cloning this repo to your pi make sure to also clone the submodules (access denied (publickey) error?):
cd ~
git clone [email protected]:mrusse/PiMatTimer --recurse-submodules
Then install the requirments
python -m pip install -r requirements.txt
The program also requires nodejs so install that on the pi if you don't have it already
sudo apt-get install nodejs
You could now run the program by doing python3 timer.py
however you should setup the program to run at startup if you are using the pi as a dedicated timer. If the timer does not start, check out the troubleshooting below.
You can use autostart to do this on the pi
mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/timer.desktop
Then put this in the timer.desktop
file.
[Desktop Entry]
Type=Application
Name=Timer
Exec=/usr/bin/python3 /home/pi/PiMatTimer/timer.py
Save and exit with ctrl + x
, followed by y
when prompted to save, and then enter
. Reboot with:
sudo reboot
The program should now launch on start up
The timer can provide scrambles for 2x2 - 7x7 and also has a scramble image tool for 3x3. The main screen will also display your current average of 5 and 12 similar to csTimer
Every scramble the timer uses is generated using the pyTwistyScrambler module which can generate WCA random state scrambles. However to reduce lag there is a buffer file of scrambles that is used. Each time you complete a solve it pulls a new scramble from the buffer file, deletes that scramble from the file, then in a new thread adds a new scramble generated by pyTwistyScrambler to the end of the file. It is done this way since there is a delay in generating these random state scrambles on the pi (about 3 seconds). So using this file buffer method the experience is seamless.
You can select a time and click Delete Selected Time
to remove that solve. Each session (2x2 - 7x7) will store their times seperatly.
In the settings you can change your puzzle type and turn on or off WCA inspection. You also have access to some system controls here such as the option to shutdown the pi or exit the program.
If the pi has a wifi connection it will also show the link to a local webserver where you can export your solves or download a current screenshot of the program. (View image below)
If you don't have a GitHub account or SSH credentials set up, you will get an access denied (publickey) error because of GitHub's security concerns.
Aside from creating a GitHub account and setting that up, you can also make Git clone from HTTPS instead of SSH:
# Use HTTPS instead of SSH by default
git config --global url."https://github.com/".insteadOf [email protected]:
# Clone the repo and its submodules
git clone [email protected]:mrusse/PiMatTimer --recurse-submodules
# Undo the HTTPS setting
git config --global --unset url."https://github.com/".insteadOf
Even though it is possible to git clone https://github.com/mrusse/PiMatTimer
, Git will still default to SSH, which will still throw the error during the cloning of the submodules.
Got this issue on a Raspberry Pi 4 Model B Rev1.1; solution was to export DISPLAY=:0.0
, but to make this setting persist on reboot you'll need to add it to your .*rc
file (e.g., append it to the bottom of ~/.bashrc
or ~/.zshrc
, whichever file exists).