Files
wecker/README.md
T

80 lines
3.4 KiB
Markdown
Raw Normal View History

# Arcade Button Alarm Clock
A unique Raspberry Pi-based alarm clock that makes sure you are fully awake before it turns off!
Instead of simply pressing a button to stop the alarm, this clock requires you to solve a short memory and attention puzzle. When the alarm rings, you press the button, and the built-in LED will blink a random number of times (between 1 and 7). You then have to press the button exactly that many times to confirm. Get it right, and the music stops. Get it wrong, and you'll have to try again!
## Hardware Requirements
* **Raspberry Pi 4 Model B** (2018)
* **33mm Illuminated Arcade Button** (e.g., from bastelgarage.ch)
* **External Speakers** (connected via 3.5mm jack or a USB Soundcard for better audio quality)
## Software Requirements
This project uses Python 3. The required dependencies are:
* `RPi.GPIO` (usually pre-installed on Raspberry Pi OS)
* `pygame` (used for optimized audio playback)
You can install the required packages via:
```bash
sudo apt-get install python3-pygame python3-rpi.gpio
```
## Wiring
Please refer to the [arcade-button-wiring.md](arcade-button-wiring.md) file for detailed instructions on how to connect the arcade button and its LED to the Raspberry Pi's GPIO pins.
## Usage
1. Make sure your audio file (`Laid Back - Sunshine Reggae.mp3` or any other MP3 you prefer) is in the project directory.
2. Run the alarm clock script manually:
```bash
python3 wecker.py
```
## Automating with Cron
To have the alarm start automatically at a specific time (e.g., 6:45 AM on weekdays), you can set up a cronjob.
1. Open your crontab configuration:
```bash
crontab -e
```
2. Add the following line at the end of the file (adjust the paths if your setup differs):
```bash
45 6 * * 1-5 cd /home/pi/workspace/wecker && /usr/bin/python3 wecker.py > /home/pi/workspace/wecker/cron.log 2>&1
```
* `45 6`: Runs at 6:45 AM.
* `* * 1-5`: Runs from Monday (1) to Friday (5). Skips the weekend.
* It ensures the script runs in the correct directory so it can find the audio file.
## How the Puzzle Works
1. **Ringing:** The music plays in an endless loop.
2. **Start:** Press the arcade button once to start the puzzle. Wait 3 seconds.
3. **Observe:** The arcade button's LED will blink between 1 and 7 times.
4. **Input:** Press the button the exact number of times the LED blinked. Every press is confirmed by the LED lighting up.
5. **Wait:** Stop pressing for 3 seconds to lock in your answer.
6. **Evaluation:**
* *Correct:* The music stops and the script exits.
* *Incorrect:* The alarm waits a few seconds and generates a completely new sequence for you to solve.
## Author
Markus Graf (info@marksugraf.ch)
## Troubleshooting
**Audio issues when running via Cron (ALSA: Couldn't open audio device: Unknown error 524):**
If the script runs perfectly from the terminal but crashes when triggered by cron, it might be trying to use an invalid audio output (like a disconnected HDMI port) because background jobs don't have the same environment variables as interactive sessions.
To force the system to use the 3.5mm headphone jack (Audio Jack), you can create a `~/.asoundrc` file for the `pi` user with the following content:
```
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "hw:2,0"
}
}
ctl.!default {
type hw
card 2
}
```
*(Note: Change `hw:2,0` and `card 2` to match your actual headphone jack card index, which you can find by running `aplay -l`).*