This Python script provides a versatile clock application for a Raspberry Pi, utilizing an LCD display, LED matrix, and GPIO buttons for interaction. The script offers multiple menu levels, each providing distinct functionalities and information displays.
- Utilizes an LCD display for menu and information display.
- Utilizes an LED matrix for visual notifications.
- Utilizes GPIO buttons (UP, DOWN, LEFT, RIGHT, SELECT, RESET) for user interaction.
- Displays various menu levels on the LCD screen.
- Navigates through menu options using UP and DOWN buttons.
- Executes selected actions using the SELECT button.
- Resets the menu or timer using the RESET button.
- Provides options such as displaying the IP address, weather information, countdown, timer, and more.
- Defines multiple menu levels (
level1
tolevel7
) with associated actions. - Provides functions for each menu level to display relevant information.
- Maps button presses (UP, DOWN, SELECT, etc.) to corresponding callback functions.
- Callbacks handle navigation, selection, and resetting actions.
- Enters a continuous main loop that updates the LCD display based on the current menu level.
- Responds to button presses and triggers appropriate actions.
- Requires customization of specific variables (e.g.,
lang
,city
,key
) to match your use case. - Can be adapted to different hardware setups or requirements.
Note: This script serves as a foundational Raspberry Pi clock application and may need further development and customization to align with your project goals. It demonstrates how to create a menu-driven interface with diverse features using an LCD display, LED matrix, and GPIO buttons.
Before using this script, ensure you understand the interactions between components and tailor variables and functionalities to your project's needs. Adaptation and customization are essential for successful implementation.
- Displays system hostname, IP address.
- Presents the current date with day, month, and year.
- Fetches real-time weather information from OpenWeather using the configured city and API key.
- Displays the current weather conditions, including temperature, humidity, and weather description.
- Provides weather forecasts for the next 24 hours, with temperature and weather condition changes.
- Allows users to set a countdown timer for a specific duration using LEFT and RIGHT buttons.
- Displays the remaining time on the LCD screen in a user-friendly format (HH:MM:SS).
- Displays the current time in hours, minutes, and seconds.
- Offers continuous updates to keep users informed of the accurate time.
- Provides a running stopwatch that counts elapsed time in hours, minutes, and seconds.
- Offers a START/STOP functionality using the SELECT button for precise time tracking.
- Enables users to measure elapsed time for various purposes.
- Raspberry Pi Model B Plus Rev 1.2 (x1)
- HW-109 lcd MAX7219 (x3)
- Five Direction button module (x1)
- 1602 A LCD 5v (x1)
- Raspberry Pi OS lite v10 (buster)
- python 3
- OpenWeather account
- pyowm
- python3-smbus
- python3-dev
- i2c-tools
- build-essential
- python3-pip
- libfreetype6-dev
- libjpeg-dev
- libopenjp2-7
- libtiff5
- RPi.GPIO
MAX7219 | Raspberry pi |
---|---|
VCC | 5V |
GND | GND |
DIN | #10 MOSI |
CS | #8 CE0 |
CLK | #11 SCLK |
Five Direction | Raspberry pi |
---|---|
COM | GND |
UP | #17 |
DWN | #27 |
LFT | #22 |
RHT | #18 |
MID | #23 |
SET | X |
RST | #24 |
1602 A LCD | Raspberry pi |
---|---|
GND | GND |
VCC | 5V |
SDA | #2 SDA |
SCL | #3 SCL |
Consult the Schema for reference.
Follow these steps to set up the necessary software components for PiClockMatrix:
- Update and upgrade the package list:
sudo apt update && sudo apt upgrade -y
- Install required packages:
sudo apt install git python3 python3-smbus python3-dev i2c-tools build-essential python3-pip libfreetype6-dev libjpeg-dev libopenjp2-7 libtiff5
- Configure
config.txt
: Edit the configuration file using the nano text editor:
sudo nano /boot/config.txt
Add the following lines at the bottom of the file:
dtparam=i2c_arm=on
dtparam=spi=on
Save and exit by pressing CTRL-X, then Y, then RETURN.
- Configure
modules
:
sudo nano /etc/modules
Add the following lines at the end of the file:
i2c-bcm2708
i2c-dev
Save and exit by pressing CTRL-X, then Y, then RETURN.
- Reboot the Raspberry Pi:
sudo reboot
- Install required Python libraries:
sudo pip3 install luma.led_matrix pyowm RPi.GPIO
- Clone the PiClockMatrix repository:
git clone https://github.com/Superjulien/piclockmatrix.git
- Edit
piclockmatrix.py
: Navigate to thepiclockmatrix
directory and edit thepiclockmatrix.py
file to customize the weather settings:
cd piclockmatrix
nano piclockmatrix.py
Change the following lines to match your preferences:
# Setting weather:
lang = 'EN'
city = 'City,EN'
key = 'api-key'
Save the changes and exit the editor.
Run the PiClockMatrix script with the following command:
sudo python3 piclockmatrix.py
The script includes exception handling to ensure a graceful exit when the user interrupts the program (Ctrl+C).
The PiClockMatrix script utilizes GPIO buttons (UP, DOWN, LEFT, RIGHT, SELECT, RESET) to interact with application. Here's how to use these buttons to navigate through menus and perform actions:
-
Navigation Buttons (UP and DOWN):
- The "UP" button is used to navigate to the previous menu or move the selection upward.
- The "DOWN" button is used to navigate to the next menu or move the selection downward.
-
Selection Button (SELECT):
- The "SELECT" button is used to execute the action associated with the selected option in the menu.
-
Reset Button (RESET):
- The "RESET" button is used to reset the menu or timer, depending on the context.
-
Scroll Buttons (LEFT and RIGHT):
- In certain menus, the "LEFT" and "RIGHT" buttons can be used to move the selection horizontally, for example, to adjust the countdown.
-
Center Button (MID):
- The "MID" button can be used to perform specific actions in different menus, for example this action could involve displaying specific information, triggering a timer, showing weather data ...
-
Upon starting the application, you'll see a main screen with menu options.
-
Use the "UP" and "DOWN" buttons to select the desired menu.
-
Press the "SELECT" button to confirm your selection and access the submenu or execute the associated action.
-
In certain menus, use the "LEFT" and "RIGHT" buttons to adjust settings, such as timer adjustment.
-
Press the "MID" button to perform special actions, such as starting or stopping a timer.
-
To reset the menu or timer, press the "RESET" button.
-
Activating the Countdown: When you access the level 4 menu, you have the option to select a time for the countdown. The "Left" and "Right" buttons adjust the countdown value.
-
Starting the Countdown: Once you've selected the desired time, press the "Select" button to start the countdown. The script will then enter a loop that displays the remaining time on the LCD screen.
-
Updating the Countdown: The script updates the countdown display every second. The remaining time is displayed in minutes and seconds. When the time reaches zero, the countdown stops.
-
End of Countdown: Once the countdown is complete, you can press any button to return to the main menu.
-
Countdown Interruption: At any point during the countdown, if you press the "Reset" button, the countdown will be interrupted, and you will be taken back to the main menu.
-
Activating the Stopwatch: When you access the level 7 menu, you have the option to start the stopwatch. Press the "Select" button to begin timing.
-
Measuring Time: The script starts measuring time once you've started the stopwatch. The display will continuously update to show the elapsed time in hours, minutes, and seconds.
-
Pause and Resume: You can pause the stopwatch at any point by pressing the "Select" button again. Press "Select" again to resume timing.
To convert temperature from Celsius to Fahrenheit in the script, make the following modifications:
In the select_level2 function, change the line
temp_dict_celsius = weather.temperature('celsius')
to
temp_dict_fahrenheit = weather.temperature('fahrenheit')
change the line
temp_dict_celsius2 = weather.temperature('celsius')
to
temp_dict_fahrenheit2 = weather.temperature('fahrenheit')
change the line
meteo = str(str(temp_dict_celsius['temp'])+"C "+str(status).replace('é','e').replace('è','e')+" "+str(temp_dict_celsius['feels_like'])+"C +"+str(temp_dict_celsius['temp_max'])+"C -"+str(temp_dict_celsius['temp_min'])+"C Hum:"+ str(hum)+"% Wind:"+str(wind_dict_in_meters_per_sec['speed']) +"m/s "+"Sun:"+str(sunrise_date.strftime('%H:%M:%S'))+" - "+str(sunrset_date.strftime('%H:%M:%S'))+" || Tomorrow at "+str(h)+"h : "+str(temp_dict_celsius2['temp'])+"C "+str(status2).replace('é','e').replace('è','e')+" "+str(temp_dict_celsius2['feels_like'])+"C")
to
meteo = str(str(temp_dict_fahrenheit['temp']) + "F " + str(status).replace('é', 'e').replace('è', 'e') + " " + str(temp_dict_fahrenheit['feels_like']) + "F +" + str(temp_dict_fahrenheit['temp_max']) + "F -" + str(temp_dict_fahrenheit['temp_min']) + "F Hum:" + str(hum) + "% Wind:" + str(wind_dict_in_meters_per_sec['speed']) + "m/s " + "Sun:" + str(sunrise_date.strftime('%H:%M:%S')) + " - " + str(sunrset_date.strftime('%H:%M:%S')) + " || Tomorrow at " + str(h) + "h : " + str(temp_dict_fahrenheit2['temp']) + "F " + str(status2).replace('é', 'e').replace('è', 'e') + " " + str(temp_dict_fahrenheit2['feels_like']) + "F")
PiClockMatrix provides several customizable functions that allow you to tailor the behavior and features of the clock application to your specific needs. Here are some of the key customizable functions:
-
Weather Data Retrieval:
- You can customize the city and language settings to get weather information for your desired location and language.
-
Displaying Weather Information:
- You can modify the formatting, layout, and additional details displayed about the weather.
-
Countdown Timer:
- You can customize the display and behavior of the countdown.
-
Custom Menus and Actions:
- You can modify these functions to create new menu options or change the behavior of existing menus.
-
Button Callbacks:
- You can customize these functions to define different actions or behaviors when specific buttons are pressed.
-
Additional Customization:
- PiClockMatrix uses various variables to control settings and behavior.
- You can adjust these variables to customize aspects such as language, date/time formats, and display configurations.
-
Interaction with External APIs:
- PiClockMatrix interacts with the OpenWeather API using the PyOWM library to fetch weather data.
- You can explore the PyOWM documentation to customize weather data retrieval or incorporate other APIs.
-
LCD Display and LED Matrix:
- The luma.led_matrix library controls the LCD display and LED matrix.
- You can modify settings and configurations to adjust the appearance and behavior of the display.
Remember that customization involves understanding the script's structure, function interactions, and external library usage. Be cautious when making changes, and consider testing each modification to ensure the desired functionality is achieved.
Feel free to explore, experiment, and customize PiClockMatrix to create a unique clock application tailored to your needs.
- The use of hardware components requires a proper understanding of GPIO pins and hardware interactions.
- Make sure to correctly connect the hardware components according to the provided diagram and manufacturer's instructions.
- This script may require modifications and adjustments to fit different hardware configurations or address specific needs.
- Ensure you understand the code and script functionalities before running it on your Raspberry Pi.
- Customizing the script requires basic knowledge of Python programming.
- Sensitive variables such as the weather API key must be handled with caution and should not be shared publicly.
- This script is provided "as is" and may require updates or further adjustments based on changes in libraries, APIs, and your project's requirements.
- Implementation of the
def level4():
. - Enhanced stability and performance.
- Bug fixes.
- HW-109 lcd MAX7219
- Five Direction button
- 1602 A LCD 5v
- Python3
- luma.led_matrix
- RPi_I2C_driver
- OpenWeather
- PyOWM
This software is provided to you free of charge, with the hope that if you find it valuable, you'll consider making a donation to a charitable organization of your choice :
-
SPA (Society for the Protection of Animals): The SPA is one of the oldest and most recognized organizations in France for the protection of domestic animals. It provides shelters, veterinary care, and works towards responsible adoption.
-
French Popular Aid: This organization aims to fight against poverty and exclusion by providing food aid, clothing, and organizing recreational activities for disadvantaged individuals.
-
Doctors Without Borders (MSF): MSF provides emergency medical assistance to populations in danger around the world, particularly in conflict zones and humanitarian crises.
-
Restaurants of the Heart : Restaurants of the Heart provides meals, emergency accommodation, and social services to the underprivileged.
-
French Red Cross: The Red Cross offers humanitarian aid, emergency relief, first aid training, as well as social and medical activities for vulnerable individuals.
Every small gesture matters and contributes to making a real difference.
For support email :
PiClockMatrix is open-source software released under the MIT License. You are free to use, modify, and distribute the software as per the terms of the license.