Comments (5)
BACKLIGHT CONTROL 😉✌️
STEP 1 - Adjustment
edit lcddriver.py
- Add custom code to end of file
- Mind code indent
# CUSTOM CODE
# define backlight on/off ( on = lcd_backlight(1); off = lcd_backlight(0) )
def lcd_backlight(self, state): # for state, 1 = on, 0 = off
if state == 1:
self.lcd_device.write_cmd(LCD_BACKLIGHT)
elif state == 0:
self.lcd_device.write_cmd(LCD_NOBACKLIGHT)
STEP 2 - Use backlight control in your code (.py)
for example create new demo file demo_lcd_backlight.py
- Turn ON backlight >>> display.lcd_backlight(1)
- Turn OFF backlight >>> display.lcd_backlight(0)
# Simple string program. Writes and updates strings.
# Demo program for the I2C 16x2 Display from Ryanteck.uk
# Created by Matthew Timmons-Brown for The Raspberry Pi Guy YouTube channel
# Backlight: Enhanced by TOMDENKT - backlight control (on/off)
# Backlight: Caution - adjustments mandatory: add custom code to end of lcddriver.py file
# Backlight: Only copy custom code lines 8-14 into lcddriver.py (drop lines with quotation marks, mind code indent)
"""
# CUSTOM CODE
# define backlight on/off ( on = lcd_backlight(1); off = lcd_backlight(0) )
def lcd_backlight(self, state): # for state, 1 = on, 0 = off
if state == 1:
self.lcd_device.write_cmd(LCD_BACKLIGHT)
elif state == 0:
self.lcd_device.write_cmd(LCD_NOBACKLIGHT)
"""
# Import necessary libraries for communication and display use
import lcddriver
import time
# Load the driver and set it to "display"
# If you use something from the driver library use the "display." prefix first
display = lcddriver.lcd()
# Main body of code
try:
while True:
# Remember that your sentences can only be 16 characters long!
print("Writing to display and toggle backlight...")
display.lcd_backlight(1) # Make sure backlight is on / turn on
time.sleep(0.5) # Waiting for backlight toggle
display.lcd_backlight(0) # Turn backlight off
time.sleep(0.5) # Waiting for turning backlight on again
display.lcd_backlight(1) # Turn backlight on again
time.sleep(1) # Waiting for text
display.lcd_display_string("Greetings Human!", 1) # Write line of text to first line of display
display.lcd_display_string("Demo Backlight", 2) # Write line of text to second line of display
time.sleep(2) # Waiting for backlight toggle
display.lcd_backlight(0) # Turn backlight off
time.sleep(0.5) # Waiting for turning backlight on again
display.lcd_backlight(1) # Turn backlight on again
time.sleep(0.5) # Waiting for turning backlight off again
display.lcd_backlight(0) # Turn backlight off
time.sleep(0.5) # Waiting for turning backlight on again
display.lcd_backlight(1) # Turn backlight on again
time.sleep(2) # Give time for the message to be read
display.lcd_display_string("I am a display!", 1) # Refresh the first line of display with a different message
time.sleep(2) # Give time for the message to be read
display.lcd_clear() # Clear the display of any data
time.sleep(1) # Give time for the message to be read
display.lcd_backlight(0) # Turn backlight off
time.sleep(1.5) # Waiting until restart
except KeyboardInterrupt: # If there is a KeyboardInterrupt (when you press ctrl+c), exit the program and cleanup
print("Cleaning up!")
display.lcd_clear()
display.lcd_backlight(1) # Make sure backlight is on / turn on by leaving
from lcd.
from lcd.
Hey @Tomtom0201 - nice stuff getting this to work (but only on some LCD hardware, is that right? What is the deal with this?)
If you've added functionality, the appropriate place to do this is in a pull request - that way I can approve your changes and they become part of the main repo too, rather than just a side note in a buried (closed) issue. Would you be able to rework this into some additional examples to include in the official repo and then submit a PR?
from lcd.
Hi Matt,
I followed your YouTube instructions for adding a 16x2 LCD display to my Pi Zero and was searching for backlight control, too - so I came here. Due to the lack of any code examples I invented a solution by myself ;-)
Regarding your questions:
1) "but only on some LCD hardware, is that right?"
I used a kind of "standard" LCD 1602 display (HD44780) with I2C interface (I2C port expander PCF8574), followed your instructions and afterwards just added lcd_backlight()-function to lcddriver.py. Definitions for LCD_BACKLIGHT resp. LCD_NOBACKLIGHT state were already in place in lcddriver.py. So from this point: I think it will work for other displays with HD44780 chip/controller too, but I cannot completely confirm functionality under certain conditions. That's why there is this precaution "may depend on your LCD hardware".
2) To be honest: I'm quite "new" to github development process flow ;-) But I will do my best to open a pull request to work amendments into it, so backlight control can become part of official repository.
Regards
Tom
from lcd.
Closing as functionality integrated by Tomtom0201
from lcd.
Related Issues (20)
- smbus is not recognized HOT 20
- No module named smbus HOT 1
- No module named smbus HOT 4
- No module named smbus (sorry if not correct label..)
- Maintaining Python 2.7 compatibility moving forward HOT 1
- Favourite HOT 1
- Removal of the default 'pi' user
- turn off the lcd screen HOT 6
- > ```python
- module not imported running python script at startup raspberry pi /etc/profiles HOT 2
- Cannot run install.sh HOT 5
- would like the cpu/gpu temp display code HOT 3
- Display IP adress HOT 2
- Displaying the IP address shows a b' in front of IP address HOT 2
- demo_tiny_dashboard is broken as Theysaidso api is no longer public
- demo_forex.py is broken because requests is blocked by cloudflare HOT 1
- Omision on README about quotable.io quote length restrictions HOT 2
- LCD Spotify Now Playing + Telegram Bot HOT 7
- BACKLIGHT can't stay in OFF mode
- cc.load_custom_characters_data() not working HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lcd.