Skip to content

Commit 82a0178

Browse files
author
Pete Lewis
committed
ex17 change address working
1 parent b58e76f commit 82a0178

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

examples/ex16_qwiic_serlcd_set_splash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#-----------------------------------------------------------------------------
33
# ex16_qwiic_serlcd_set_splash.py
44
#
5-
# This sketch demonstrates how to create your own custom splash screen.
5+
# This example demonstrates how to create your own custom splash screen.
66
#
77
# This is done by first writing the text you want as your splash to the display,
88
# then 'saving' it as a splash screen.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env python
2+
#-----------------------------------------------------------------------------
3+
# ex17_qwiic_serlcd_change_i2c_address.py
4+
#
5+
# This example demonstrates how to change the i2c address on your LCD.
6+
# Note, once you change the address, then you will need to intatiate your class
7+
# using your new address.
8+
#
9+
# Once you have changed the address, you can try using the optional instantiation
10+
# line of code that is currently commented out.
11+
#
12+
# There is a set range of available addresses from 0x07 to 0x78, so make sure your
13+
# chosen address falls within this range.
14+
#
15+
# The next thing to note is that when you change the address you'll
16+
# need to call an instance of the QwiicSerlcd class that includes your new
17+
# address, like so: "myLCD = qwiic_serlcd.QwiicSerlcd(address=YOUR_NEW_ADDRESS_HERE)"
18+
# so that the new address is fed to all the available functions.
19+
#
20+
# Finally if for some reason you've forgotten your new address. No big deal, run a
21+
# hardware reset on your screen to get it back to the default address (0x72).
22+
# To cause a hardware reset, simply tie the RX pin LOW, and they cycle power
23+
# (while continuing to hold RX low). Then release RX, and cycle power again.
24+
#
25+
#------------------------------------------------------------------------
26+
#
27+
# Written by SparkFun Electronics, August 2020
28+
#
29+
# Ported from Arduino Library code with many contributions from
30+
# Gaston Williams - August 29, 2018
31+
#
32+
# Some code/comments/ideas ported from the Qwiic Quad Relay Arduino Library
33+
# Written by Elias Santistevan, July 2019
34+
#
35+
# This python library supports the SparkFun Electroncis qwiic
36+
# qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
37+
# board computers.
38+
#
39+
# More information on qwiic is at https://www.sparkfun.com/qwiic
40+
#
41+
# Do you like this library? Help support SparkFun. Buy a board!
42+
#
43+
#==================================================================================
44+
# Copyright (c) 2020 SparkFun Electronics
45+
#
46+
# Permission is hereby granted, free of charge, to any person obtaining a copy
47+
# of this software and associated documentation files (the "Software"), to deal
48+
# in the Software without restriction, including without limitation the rights
49+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50+
# copies of the Software, and to permit persons to whom the Software is
51+
# furnished to do so, subject to the following conditions:
52+
#
53+
# The above copyright notice and this permission notice shall be included in all
54+
# copies or substantial portions of the Software.
55+
#
56+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
62+
# SOFTWARE.
63+
#==================================================================================
64+
# Example 17
65+
#
66+
67+
from __future__ import print_function
68+
import qwiic_serlcd
69+
import time
70+
import sys
71+
72+
old_address = 0x72 # default
73+
new_address = 0x71 # must be within 0x07 to 0x78, DEFAULT: 0x72
74+
75+
def runExample():
76+
77+
print("\nSparkFun Qwiic SerLCD Example 17\n")
78+
print("\nType CTRL+C to end.\n")
79+
myLCD = qwiic_serlcd.QwiicSerlcd(address=old_address)
80+
81+
print("Attemping to connect to %s..." % hex(myLCD.address))
82+
83+
if myLCD.connected == False:
84+
print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
85+
file=sys.stderr)
86+
return
87+
else:
88+
print("Connected!")
89+
myLCD.setBacklight(255, 255, 255) # bright white
90+
myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
91+
myLCD.begin() # call this for default settings (no
92+
myLCD.leftToRight()
93+
myLCD.noCursor()
94+
time.sleep(1) # give a sec for system messages to complete
95+
96+
myLCD.clearScreen()
97+
98+
myLCD.setAddress(new_address) # note this updates class member myLCD.address to the new_address
99+
100+
if myLCD.connected == True:
101+
print("Address changed to %s successfully!" % hex(myLCD.address))
102+
myLCD.clearScreen()
103+
myLCD.print("My new add: %s" % hex(myLCD.address))
104+
else:
105+
print("Address change failed :(")
106+
while True:
107+
time.sleep(1) # do nothing
108+
109+
if __name__ == '__main__':
110+
try:
111+
runExample()
112+
except (KeyboardInterrupt, SystemExit) as exErr:
113+
print("\nEnding Example 17")
114+
sys.exit(0)
115+
116+

qwiic_serlcd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,4 +863,5 @@ def setAddress(self, new_addr):
863863
# send the complete bytes (address, settings command , address command , new_addr byte)
864864
result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
865865
time.sleep(0.05)
866-
return result
866+
self.address = new_addr # update our own address, so we can stil talk to the display
867+
return result

0 commit comments

Comments
 (0)