This project is for my class at Rice University: ENGI 301, Introduction to Practical Electrical Engineering.
MotivationMy motivation for project stems from a universal challenge we all face: the struggle of getting out of bed in the mornings. Personally, I love being awake in the mornings and given my early wake-up routine for work, I wanted to create a solution that would facilitate a smoother transition into the day. The result is this alarm clock, designed to enhance my mornings by gradually brightening with customizable sunrise colors and playing my preferred music through a buzzer. Beyond its functional benefits, I wanted it as a means to stop using my phone at night and in the mornings. By returning to the simplicity of digital alarm clocks, I can detach from my phone before sleep, improving the quality of my rest. Ultimately, this alarm would make waking up a more pleasant experience, providing a natural and calming start to the day.
HardwareI will go through each of the hardware components I implemented in my device and how to set them up.
All components use the PocketBeagle as the microcontroller. For reference, this is the schematic of the PocketBeagle and each of the pins' functions.
The buzzer was the first hardware component I implemented. The positive connection of the buzzer must be wired into one of the PocketBeagle's PWM pins, and the negative connection must be wired to ground.
Using the buzzer_template code, I changed the notes' durations and frequencies such that the buzzer plays the introduction to Coldplay's Viva la Vida in the key of C5 major. This was chosen based on research of what the most scientifically perfect alarm sound should be to waking up easily:
- a melody one can easily sing or hum along to
- a dominant frequency in the key of C5
- not too fast or too slow (100 β 120 beats per minute is ideal)
You can hear the buzzer playing the song in my alarm demo video below.
2. Push ButtonsNext, I set up 5 push buttons. Each of the buttons must have one side connected to ground, and the other side connected through a 1k resistor to 3.3 V in the PocketBeagle. A GPIO pin in the PocketBeagle must also be connected to the side of the resistor to control the button. I used various convenient GPIO pins for my buttons.
I used 5 push buttons in my device, in order to mimic a digital alarm with maximal user friendliness. The green button controls the hour setting of the alarm, the blue button control the minute setting, the black button toggles between the actual time and alarm time, the red button turns off the alarm noise played by the buzzer, and the yellow button turns off the LED sunrise lights.
The next hardware item to set up is the SPI screen. The first step is to solder the following pins as well as solder a bridge between IM1, IM2, and IM3 on the back of the screen.
I connected the SPI pins to the PocketBeagle in the following way:
- GND to GND
- VIN to 3.3V
- CLK to CLK
- MISO to MISO
- MOSI to MOSI
- CS to GPIO31
- D/C to GPIO33
- RST to GPIO35
I used these pins because After connections, the following software installations must be run to display:
- sudo apt-get update
- sudo pip3 install --upgrade Pillow
- sudo pip3 install adafruit-circuitpython-busdevice
- sudo pip3 install adafruit-circuitpython-rgb-display
- sudo apt-get install ttf-dejavu -y
In order for the device to use the actual time, it needs to collect the local time using Wifi. First, the USB must be wired such that when the PocketBeagle is inserted into P1_1, the following connections are wired:
- VCC to P1_7
- D- to P1_9
- D+ to P1_11
- ID to P1_13
- ID to GND of the USB must be connected with a capacitor
Then, the Wifi adapter can be plugged into the USB port. Once the Wifi Adaptor is plugged in, the command "lsusb" can be used to see the device, and then connect to the network of choice.
Once the network is connected, I used it to import the local time on the SPI Screen so that it can now behave as an alarm!
This video shows the device working as an alarm so far in the steps:
5. LED Strip Lights and Level ShifterThe final hardware part of the device to implement is the LED strip lights. First, a level shifter must be wired to produce a 5V voltage for the LED lights. I wired it in the following way:
Once the level shifter is wired, I connected the LED strip lights to it. The red wire should be connected to the 5V power source, the green wire to the VCCA data in, and then white wire to GND. GPIO pin P1_08 must be used, not any other GPIO pin.
After setting up the hardware, the following software executables, python scripts, and other files need to be in place. They are attached in the Github page linked.
- configure_pins.sh - Configure pins script
- run - Example run script
- run-opc-server - Run script for opc-server
- opc-server - Executable to run open-pixel-control
- opc.py - Open Pixel Control Python interface library
- config.json - OPC server configuration file
- pru/bin/ws281x-original-ledscape-pru0.bin - Executable to load into the PRU CPUs that help with execution
- pru/bin/ws281x-original-ledscape-pru1.bin
Additionally, the boot settings need to be modified to use the UIO library. uEnv.txt needs to be edited through sudo nano /boot/uEnv.txt. RPROC firmware needs to be commented out and UIO firmware needs to be uncommented. sudo reboot should be called and UIO availability can be checked through ls /sys/class/uio.
Once everything is installed, the LED lights need to be run on two terminals on PocketBeagle. The first terminal should run the opc-server (sudo./run-opc-server) and the second should run the python LED strip test (./run).
After I got the LED lights working, I modified the RGB codes of the lights after trial and error to display the lighting of a sunrise that I liked!
I also wanted to lights to turn on gradually 5 minutes before the alarm goes off, to be at its maximum brightness when the alarm buzzer goes off. Below is a video displaying the gradual brightening of the sunrise lights over 30 second. This is elongated to 5 minutes in the actual alarm code.
Running the AlarmAll the python files in the Github link attached must be downloaded and installed through the PocketBeagle. To run the alarm, type sudo ./run-opc-server in one terminal tab. In other tab, run the main_alarm.py file. The functions are threaded so that it should ideally all be able to run together. However, when I personally ran this code from my laptop, when the LED lights were triggered, the SPI screen would turn off and glitch, so I was not able to get a proper video of it, with the 5 minute timing.
Challenges and Future WorkI underestimated the challenges posed by the small issues that emerged during the course of this project. Given the inclusion of multiple hardware components, distinguishing between hardware and software issues became complicated when things didn't work as expected. Additionally, this was my first time actually using Python, which had a learning curve that I had to get over. It was also my first time going into the practical use of electrical components, which required a lot of background research. Despite encountering difficulties throughout the project, I learned a great amount and it was very rewarding!
For In the future, I would like to make customizable LED light colors and make the alarm touchscreen, which is possible with this SPI screen. However, for time and simplicity sake, I opted for buttons.
A huge thank you to Erik Welsh, my ENGI 301 professor, for his expertise and hours of help!
Comments