Skip to content

Commit f93fb64

Browse files
author
Pete Lewis
committed
ex15 working, also verified enable and disable splash functions working
1 parent e03c818 commit f93fb64

File tree

2 files changed

+238
-0
lines changed

2 files changed

+238
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex15_qwiic_serlcd_message_enable.py
4+
#
5+
# This example demonstrates how to turn off the system messages displayed when
6+
# the user changes a setting. For instance 'Contrast: 5' or 'Backlight: 100%' is
7+
# no longer displayed.
8+
#
9+
# Note - This example and the disableSystemMessages() and enableSystemMessages()
10+
# commands are only supported on SerLCD v1.2 and above.
11+
#
12+
#------------------------------------------------------------------------
13+
#
14+
# Written by SparkFun Electronics, August 2020
15+
#
16+
# Ported from Arduino Library code with many contributions from
17+
# Gaston Williams - August 29, 2018
18+
#
19+
# This python library supports the SparkFun Electroncis qwiic
20+
# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
21+
# board computers.
22+
#
23+
# More information on qwiic is at https://www.sparkfun.com/qwiic
24+
#
25+
# Do you like this library? Help support SparkFun. Buy a board!
26+
#
27+
#==================================================================================
28+
# Copyright (c) 2020 SparkFun Electronics
29+
#
30+
# Permission is hereby granted, free of charge, to any person obtaining a copy
31+
# of this software and associated documentation files (the "Software"), to deal
32+
# in the Software without restriction, including without limitation the rights
33+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34+
# copies of the Software, and to permit persons to whom the Software is
35+
# furnished to do so, subject to the following conditions:
36+
#
37+
# The above copyright notice and this permission notice shall be included in all
38+
# copies or substantial portions of the Software.
39+
#
40+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46+
# SOFTWARE.
47+
#==================================================================================
48+
# Example 15
49+
#
50+
51+
from __future__ import print_function
52+
import qwiic_serlcd
53+
import time
54+
import sys
55+
56+
def runExample():
57+
58+
print("\nSparkFun Qwiic SerLCD Example 15\n")
59+
print("\nType CTRL+C to end.\n")
60+
myLCD = qwiic_serlcd.QwiicSerlcd()
61+
62+
if myLCD.connected == False:
63+
print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
64+
file=sys.stderr)
65+
return
66+
67+
myLCD.setBacklight(255, 255, 255) # bright white
68+
myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
69+
myLCD.begin() # call this for default settings (no
70+
myLCD.leftToRight()
71+
myLCD.noCursor()
72+
time.sleep(1) # give a sec for system messages to complete
73+
74+
myLCD.disableSystemMessages() # Now whenever you change a system setting like Contrast,
75+
# SerLCD will not display the setting. This makes changing the setting faster, and also
76+
# invisible to the user.
77+
78+
#myLCD.enableSystemMessages() # This will re-enable the printing of system messages
79+
80+
myLCD.clearScreen()
81+
myLCD.print("Hello World!")
82+
83+
counter = 0
84+
85+
while True:
86+
# do something that would normally cause a system message
87+
# let's change color of backlight values every other count value
88+
if (counter % 2) == 0:
89+
myLCD.setBacklight(255, 0, 0)
90+
else:
91+
myLCD.setBacklight(0, 255, 0)
92+
93+
time.sleep(0.1) # give it a sec to change backlight
94+
95+
print("counter: %d" % counter)
96+
myLCD.setCursor(0,1)
97+
myLCD.print(str(counter))
98+
counter = counter + 1
99+
time.sleep(1)
100+
101+
if __name__ == '__main__':
102+
try:
103+
runExample()
104+
except (KeyboardInterrupt, SystemExit) as exErr:
105+
print("\nEnding Example 15")
106+
sys.exit(0)
107+
108+

qwiic_serlcd.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,133 @@ def setFastBacklight(self, r, g, b):
734734
result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
735735
time.sleep(0.01)
736736
return result
737+
738+
# ----------------------------------
739+
# enableSystemMessages()
740+
#
741+
# Enable system messages
742+
# This allows user to see printing messages like'Contrast: 5'
743+
def enableSystemMessages(self):
744+
"""
745+
Enable system messages
746+
747+
:return: Returns true if the I2C write was successful, otherwise False.
748+
:rtype: bool
749+
750+
"""
751+
752+
# send command
753+
result = self.command(ENABLE_SYSTEM_MESSAGE_DISPLAY)
754+
time.sleep(0.01)
755+
return result
756+
757+
# ----------------------------------
758+
# disableSystemMessages()
759+
#
760+
# Disable system messages
761+
# This allows user to disable printing messages like'Contrast: 5'
762+
def disableSystemMessages(self):
763+
"""
764+
Disable system messages
765+
766+
:return: Returns true if the I2C write was successful, otherwise False.
767+
:rtype: bool
768+
769+
"""
770+
771+
# send command
772+
result = self.command(DISABLE_SYSTEM_MESSAGE_DISPLAY)
773+
time.sleep(0.01)
774+
return result
775+
776+
# ----------------------------------
777+
# enableSplash()
778+
#
779+
# Enable splash screen at power on
780+
def enableSplash(self):
781+
"""
782+
Enable splash screen at power on
783+
784+
:return: Returns true if the I2C write was successful, otherwise False.
785+
:rtype: bool
786+
787+
"""
788+
789+
# send command
790+
result = self.command(ENABLE_SPLASH_DISPLAY)
791+
time.sleep(0.01)
792+
return result
793+
794+
# ----------------------------------
795+
# disableSplash()
796+
#
797+
# Disable splash screen at power on
798+
def disableSplash(self):
799+
"""
800+
Disable splash screen at power on
801+
802+
:return: Returns true if the I2C write was successful, otherwise False.
803+
:rtype: bool
804+
805+
"""
806+
807+
# send command
808+
result = self.command(DISABLE_SPLASH_DISPLAY)
809+
time.sleep(0.01)
810+
return result
811+
812+
# ----------------------------------
813+
# saveSplash()
814+
#
815+
# Save the current display as the splash
816+
# Saves whatever is currently being displayed into EEPROM
817+
# This will be displayed at next power on as the splash screen
818+
def saveSplash(self):
819+
"""
820+
Save the current display as the splash
821+
Saves whatever is currently being displayed into EEPROM
822+
This will be displayed at next power on as the splash screen
823+
824+
:return: Returns true if the I2C write was successful, otherwise False.
825+
:rtype: bool
826+
827+
"""
828+
829+
# send command
830+
result = self.command(SAVE_CURRENT_DISPLAY_AS_SPLASH)
831+
time.sleep(0.01)
832+
return result
833+
834+
# ----------------------------------
835+
# setAddress()
836+
#
837+
# Change the I2C Address. 0x72 is the default.
838+
# Note that this change is persistent. If anything
839+
# goes wrong you may need to do a hardware reset
840+
# to unbrick the display.
841+
#
842+
# byte new_addr - new i2c address
843+
def setAddress(self, new_addr):
844+
"""
845+
Change the I2C Address. 0x72 is the default.
846+
Note that this change is persistent. If anything
847+
goes wrong you may need to do a hardware reset
848+
to unbrick the display.
849+
:param new_addr: new i2c address
850+
851+
:return: Returns true if the I2C write was successful, otherwise False.
852+
:rtype: bool
853+
854+
"""
855+
856+
# create a block of data bytes to send to the screen
857+
# This will include the ADDRESS_COMMAND, and the new address byte value.
858+
block = [0,1]
859+
860+
block[0] = ADDRESS_COMMAND # command
861+
block[1] = new_addr
862+
863+
# send the complete bytes (address, settings command , address command , new_addr byte)
864+
result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
865+
time.sleep(0.05)
866+
return result

0 commit comments

Comments
 (0)