Introduction: LCD IP/ Clock
This instructable will show you how to build an LCD display that shows you the current time and the IP/ host of the RPi.
- Raspberry Pi
- SD card with raspbian
- WiFi Connection
- Geek PI IIC/I2C 2004 2 Arduino UNO Raspberry Pi LCD display (20x4)
- 4x Female to female jumper wires
- Keyboard and mouse
Step 1: Step 1: Wiring
- Connect the ground pin of the LCD to a ground pin on the RPi
- Connect the VCC pin of the LCD to a 5v pin on the RPi
- Connect the SDA pin of the LCD to the SDA 2 pin on the RPi
- Connect the SCL pin of the LCD to the SCL 3 pin on the RPi
As shown in the pictures
Step 2: Step 2: Cloning Git Repo
- Boot the RPI
- Open terminal
- Type the following
sudo apt-get update sudo apt-get upgrade<br>
git clone https://github.com/Benjonesmtb/LCD-Instructable</a> sudo reboot
Step 3: Step 3: Installing Python3
**YOU CAN SKIP THIS STEP IF YOU HAVE PYTHON3 AND PYTHON3-PIP INSTALLED ALREADY**
Just input the following lines of code into the terminal
sudo apt-get install python3 sudo apt-get install python3-pip sudo reboot sudo apt-get update sudo apt-get full-upgrade
Step 4: Step 4: Testing Code
So you now have everything installed ready to run. So go to the place where the files you cloned are and type:
This program shows that the LCD works. Now you can run the next demo:
This program runs a basic clock setup. The time should be displayed on the screen and changes when the time changes.
Step 5: Step 5: the Code
This step will show you how to code the clock and IP python program.
The code starts by importing all the relevant libraries.
import lcddriver import time import datetime import socket display = lcd.driver.lcd()
Now you can get the IP and hostname:
testIP = "184.108.40.206"
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ipaddr = s.getsockname()
host = socket.gethostname()
This code will get the IP from the RPi and set it as "ipaddr".
Now you can get the text to print:
text = str(input("Input Text:"))
This code gets some text from the user (you will need a keyboard and display for this). Next you can output everything to the display:
print("Writing to display") display.lcd_display_string(text, 1) # Write line of text to first line of display display.lcd_display_string(ipaddr, 3) display.lcd_display_string(host, 4) while True: display.lcd_display_string(str(datetime.datetime.now().time()), 2) # Write just the time to the display # Program then loops with no delay (Can be added with a time.sleep)
except KeyboardInterrupt: # If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!") display.lcd_clear()
This part of the code outputs all the variables to the LCD Display and refreshes the time as it goes up.