1
+ /*
2
+ SparkFun Electronics
3
+ SerLCD Library - Change I2C address
4
+ Pete Lewis - August 18, 2020
5
+
6
+ This example demonstrates how to change the i2c address on your LCD.
7
+ Note, once you change the address, then you will need to call ".begin()" again.
8
+
9
+ There is a set range of available addresses from 0x07 to 0x78, so make sure your
10
+ chosen address falls within this range.
11
+
12
+ The next thing to note is that when you change the address you'll
13
+ need to call .begin again to talk to that screen.
14
+
15
+ Finally if for some reason you've forgotten your new address. No big deal, run a
16
+ hardware reset on your screen to get it back to the default address (0x72).
17
+ To cause a hardware reset, simply tie the RX pin LOW, and they cycle power
18
+ (while continuing to hold RX low). Then release RX, and cycle power again.
19
+
20
+ The circuit:
21
+ SparkFun RGB OpenLCD Serial display connected through
22
+ a SparkFun Qwiic cable/adpater to an qwiic-enabled Arduino.
23
+
24
+ The Qwiic adapter should be attached to the display as follows:
25
+ Display / Qwiic Cable Color
26
+ GND / Black
27
+ RAW / Red
28
+ SDA / Blue
29
+ SCL / Yellow
30
+
31
+ Note: If you connect directly to a 5V Arduino instead, you *MUST* use
32
+ a level-shifter to convert the i2c voltage levels down to 3.3V for the display.
33
+
34
+ This code is based on the LiquidCrystal code originally by David A. Mellis
35
+ and the OpenLCD code by Nathan Seidle at SparkFun.
36
+
37
+ Also based off the original Arduino Library code with many contributions from
38
+ Gaston Williams - August 29, 2018
39
+
40
+ Some code/comments/ideas ported from the Qwiic Quad Relay Arduino Library
41
+ Written by Elias Santistevan, July 2019
42
+
43
+ License: This example code is in the public domain.
44
+
45
+ More info on Qwiic here: https://www.sparkfun.com/qwiic
46
+
47
+ AVR-Based Serial Enabled LCDs Hookup Guide
48
+ https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide
49
+ */
50
+
51
+ #include < Wire.h>
52
+
53
+ #include < SerLCD.h> // Click here to get the library: http://librarymanager/All#SparkFun_SerLCD
54
+ SerLCD lcd; // Initialize the library with default I2C address 0x72
55
+
56
+ byte oldAddress = 0x72 ; // default 0x72
57
+ byte newAddress = 0x71 ; // must be within 0x07 to 0x78, DEFAULT: 0x72
58
+
59
+ void setup () {
60
+ Wire.begin ();
61
+ Serial.begin (115200 );
62
+
63
+ Serial.print (" Connecting to SerLCD at 0x" );
64
+ Serial.println (oldAddress, HEX);
65
+ lcd.begin (Wire, oldAddress); // Set up the LCD for I2C communication
66
+ Serial.println (" Done\n\r " );
67
+
68
+ lcd.setBacklight (255 , 255 , 255 ); // Set backlight to bright white
69
+ lcd.setContrast (5 ); // Set contrast. Lower to 0 for higher contrast.
70
+
71
+ lcd.clear (); // Clear the display - this moves the cursor to home position as well
72
+
73
+ // command to change address
74
+ // note this will also change class private variable "lcd._i2cAddr"
75
+ Serial.print (" Changing address to 0x" );
76
+ Serial.println (newAddress, HEX);
77
+ lcd.setAddress (newAddress);
78
+ Serial.println (" Done\n\r " );
79
+
80
+ Serial.print (" Connecting to SerLCD at 0x" );
81
+ Serial.println (newAddress, HEX);
82
+ lcd.begin (Wire); // note, new address argument is not needed. lcd._i2cAddr has been updated by ".setAddress()"
83
+ Serial.println (" Done\n\r " );
84
+
85
+ lcd.print (" My new address: 0x" ); // print it to the LCD for user victory experience
86
+ lcd.print (lcd.getAddress (), HEX); // note, we need to use public function to access private lcd._i2cAddr
87
+ }
88
+
89
+ void loop () {
90
+ // do nothing
91
+ }
0 commit comments