Raspberry Pi 24h Clock ========================== For simplified indication of time to children. Files: gpioclock.cpp - The program to drive the clock hand motor. gpioclock.service - Service file for making Raspberry Pi launch the program always when it boots. gpioclock.png - Wiring diagram. gpioclock.amf - The 3D model for the clock hand. May need some filing to fit onto the motor axle - I just opened mine with a 5mm drill-bit. Note: If you're using this file to print the clock-hand, then your opto-fork needs to be exactly 45mm from the motor axle, so the nub under the hand hits the sensor beam. README.txt - This file, that you are now reading. First, about physically building this project, and adapting the program to any changes: Assemble the parts according to the picture gpioclock.png. Motor control output, in order: 27, 22, 23, 24. Opto-fork input: 17. If you have to connect to other pins (e.g. because something else is already connected to these) then change the pin numbers in gpioclock.cpp to match. The pin numbers are listed in the beginning of the file. Motor drive pin numbers should be in the same order as they are connected to the motor driver inputs 1-4, or the motor will not turn. Opto-fork may be substituted for other sensors, like a hall-effect sensor or mechanical switch. Note that the angle of the sensor is not critical. You can change the position of the sensor, as long as you change the sensor position into the constant variable named "CENTERING_POSITION_STEP_VALUE". Also, please check whether your sensor outputs a high or low logical value when triggered, and change "inputTriggerValue" accordingly. If you are using a different gearbox or motor, you should chek that the combination has 2048 steps to one full revolution. If not, change the variable "numPositionsTotal" in the program also to match, because the progra uses the number of steps to determine where the time hand is pointing. If you are unsure about the total number of steps, then put a large value (e.g. 30000) in it, compile, and run the program once with the "-v -t" flags. The program will print the number of steps between running into the sensor again, so after a couple of rounds you can deduce the correct number (which should be a multiple of the number of motor inputs). Packages required: - build-essential - libgpiod-dev This instruction assumes that you un-zipped the folder gpioclock to /home/pi/gpioclock . If not, you'll heave to fix the path in file gpioclock.service to point where you put the compiled program. Compiling the program: g++ gpioclock.cpp -lgpiod -o gpioclock You can try running the program simply with "./gpioclock -v -t", assuming you're in the gpioclock directory. "-v" turns on text output, so you can troubleshoot if shomething is not working as expected. "-t" tells the program to exit after 15 loops, which is approximately 30 seconds if everything is working correctly. Installing the service file and enabling the service: Copy the gpioclock.service file to under /etc/systemd/system/ (This is not the location where user-created service files should really go, but it's the simplest way on a Raspberry Pi that's not doing anythig else important. If someone wants to put better instructions here, feel free to send a message with a good write-up.) Then run "sudo systemctl enable gpioclock". Setting the timezone: Use raspi-config -> Internationalisation -> Change Timezone --OR-- Alternatively, you can use timedatectl, which works on e.g. Debian and Ubuntu, even outside the Raspberry Pi ecosystem. "sudo timedatectl set-timezone Europe/Helsinki" Replace continent and capital city with your own. List of timezones is available with "timedatectl list-timezones".