This repository provides a utility for logging useful information from a Raspberry Pi onto an I2C LCD screen. The utility utilizes a Python driver for the I2C LCD, simplifying the process of interfacing with the LCD display.
- lcd_driver.py: This file contains the Python class lcd which provides methods for controlling the LCD display via I2C communication.
- log-data.py: An example usage of the lcd class. This script continuously displays the Raspberry Pi's IP address and CPU temperature on the connected LCD screen.
- Python 3.x
- smbus Python library (usually pre-installed on Raspberry Pi OS)
- I2C_LCD_driver.py (for the log_data.py example)
- Ensure your Raspberry Pi has the I2C interface enabled.
- Clone this repository to your Raspberry Pi:
git clone git@github.com:cololaborde/raspberry-I2C-LCD-logger.git
- Connect your I2C LCD to the Raspberry Pi following the previous schema.
- Import the lcd class from lcd_driver.py into your Python script.
- Initialize the lcd object.
- Use the provided methods to control the LCD display.
from time import sleep
from lcd_driver import lcd
mylcd = lcd()
while True:
# Get IP address
# (Replace this with your method of obtaining the IP address)
ip = "192.168.1.100"
# Get CPU temperature
# (Replace this with your method of obtaining the CPU temperature)
temp = "Temp: 45C"
# Display IP address and CPU temperature on LCD
mylcd.lcd_display_string(ip, 1)
mylcd.lcd_display_string(temp, 2)
sleep(5) # Update every 5 seconds
- Create a new systemd service file:
sudo nano /etc/systemd/system/lcd_display.service
- Add the following contents to the file:
[Unit]
Description=LCD Display Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/usr/bin/python3 /path/to/log_data.py
[Install]
WantedBy=multi-user.target
Replace /path/to/log_data.py with the actual path to your log_data.py script.
- Save the file and exit the editor.
- Reload systemd to read the new service file:
sudo systemctl daemon-reload
- Enable the service to start on boot:
sudo systemctl enable lcd_display.service
- Original code for the I2C interface and LCD control was compiled, modified, and made available by Denis Pleic under the GNU General Public License.
- Example usage script (log_data.py) utilizes the lcd class provided in this repository along with some system commands to display IP address and CPU temperature.
This project is licensed under the GNU General Public License. See the LICENSE file for details.