├── .gitignore ├── LICENSE ├── README.md ├── examples ├── Example1-HelloWorld │ └── Example1-HelloWorld.ino ├── Example10-TurnOffDisplay │ └── Example10-TurnOffDisplay.ino ├── Example11-TextDirection │ └── Example11-TextDirection.ino ├── Example12-SerialToDisplay │ └── Example12-SerialToDisplay.ino ├── Example13-FastBacklight │ └── Example13-FastBacklight.ino ├── Example14-ShowFirmwareVersion │ └── Example14-ShowFirmwareVersion.ino ├── Example15-MessageEnable │ └── Example15-MessageEnable.ino ├── Example16-SetSplash │ └── Example16-SetSplash.ino ├── Example17-ChangeI2cAddress │ └── Example17-ChangeI2cAddress.ino ├── Example2-Backlight │ └── Example2-Backlight.ino ├── Example3-SetCursorPosition │ └── Example3-SetCursorPosition.ino ├── Example4-MoveCursor │ └── Example4-MoveCursor.ino ├── Example5-EnableCursor │ └── Example5-EnableCursor.ino ├── Example6-BlinkCursor │ └── Example6-BlinkCursor.ino ├── Example7-Scroll │ └── Example7-Scroll.ino ├── Example8-AutoscrollWithText │ └── Example8-AutoscrollWithText.ino ├── Example9-CustomCharacter │ └── Example9-CustomCharacter.ino └── Serial │ └── Example1-HelloWorld │ └── Example1-HelloWorld.ino ├── keywords.txt ├── library.properties ├── src ├── SerLCD.cpp └── SerLCD.h └── tests ├── HelloWorld_OpenLCD_SPI └── HelloWorld_OpenLCD_SPI.ino ├── HelloWorld_OpenLCD_Serial └── HelloWorld_OpenLCD_Serial.ino ├── OpenLCD_Lib_SPI_Test └── OpenLCD_Lib_SPI_Test.ino └── OpenLCD_Lib_Serial_Test └── OpenLCD_Lib_Serial_Test.ino /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## SparkFun Useful stuff 3 | ################# 4 | 5 | ## AVR Development 6 | *.eep 7 | *.elf 8 | *.lst 9 | *.lss 10 | *.sym 11 | *.d 12 | *.o 13 | *.srec 14 | *.map 15 | 16 | ## Notepad++ backup files 17 | *.bak 18 | 19 | ## BOM files 20 | *bom* 21 | 22 | ################# 23 | ## Eclipse 24 | ################# 25 | 26 | *.pydevproject 27 | .project 28 | .metadata 29 | bin/ 30 | tmp/ 31 | *.tmp 32 | *.bak 33 | *.swp 34 | *~.nib 35 | local.properties 36 | .classpath 37 | .settings/ 38 | .loadpath 39 | 40 | # External tool builders 41 | .externalToolBuilders/ 42 | 43 | # Locally stored "Eclipse launch configurations" 44 | *.launch 45 | 46 | # CDT-specific 47 | .cproject 48 | 49 | # PDT-specific 50 | .buildpath 51 | 52 | 53 | ############# 54 | ## Eagle 55 | ############# 56 | 57 | # Ignore the board and schematic backup files 58 | *.b#? 59 | *.s#? 60 | *.l#? 61 | 62 | 63 | ################# 64 | ## Visual Studio 65 | ################# 66 | 67 | ## Ignore Visual Studio temporary files, build results, and 68 | ## files generated by popular Visual Studio add-ons. 69 | 70 | # User-specific files 71 | *.suo 72 | *.user 73 | *.sln.docstates 74 | 75 | # Build results 76 | [Dd]ebug/ 77 | [Rr]elease/ 78 | *_i.c 79 | *_p.c 80 | *.ilk 81 | *.meta 82 | *.obj 83 | *.pch 84 | *.pdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.vspscc 94 | .builds 95 | *.dotCover 96 | 97 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 98 | #packages/ 99 | 100 | # Visual C++ cache files 101 | ipch/ 102 | *.aps 103 | *.ncb 104 | *.opensdf 105 | *.sdf 106 | 107 | # Visual Studio profiler 108 | *.psess 109 | *.vsp 110 | 111 | # ReSharper is a .NET coding add-in 112 | _ReSharper* 113 | 114 | # Installshield output folder 115 | [Ee]xpress 116 | 117 | # DocProject is a documentation generator add-in 118 | DocProject/buildhelp/ 119 | DocProject/Help/*.HxT 120 | DocProject/Help/*.HxC 121 | DocProject/Help/*.hhc 122 | DocProject/Help/*.hhk 123 | DocProject/Help/*.hhp 124 | DocProject/Help/Html2 125 | DocProject/Help/html 126 | 127 | # Click-Once directory 128 | publish 129 | 130 | # Others 131 | [Bb]in 132 | [Oo]bj 133 | sql 134 | TestResults 135 | *.Cache 136 | ClientBin 137 | stylecop.* 138 | ~$* 139 | *.dbmdl 140 | Generated_Code #added for RIA/Silverlight projects 141 | 142 | # Backup & report files from converting an old project file to a newer 143 | # Visual Studio version. Backup files are not needed, because we have git ;-) 144 | _UpgradeReport_Files/ 145 | Backup*/ 146 | UpgradeLog*.XML 147 | 148 | 149 | ############ 150 | ## Windows 151 | ############ 152 | 153 | # Windows image file caches 154 | Thumbs.db 155 | 156 | # Folder config file 157 | Desktop.ini 158 | 159 | 160 | ############# 161 | ## Mac OS 162 | ############# 163 | 164 | .DS_Store 165 | 166 | 167 | ############# 168 | ## Linux 169 | ############# 170 | 171 | # backup files (*.bak on Win) 172 | *~ 173 | 174 | 175 | ############# 176 | ## Python 177 | ############# 178 | 179 | *.py[co] 180 | 181 | # Packages 182 | *.egg 183 | *.egg-info 184 | dist 185 | build 186 | eggs 187 | parts 188 | bin 189 | var 190 | sdist 191 | develop-eggs 192 | .installed.cfg 193 | 194 | # Installer logs 195 | pip-log.txt 196 | 197 | # Unit test / coverage reports 198 | .coverage 199 | .tox 200 | 201 | #Translations 202 | *.mo 203 | 204 | #Mr Developer 205 | .mr.developer.cfg 206 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Gaston Williams (aka fourstix) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SparkFun SerLCD Library 2 | =========================================================== 3 | 4 | ![SparkFun SerLCD](https://cdn.sparkfun.com//assets/parts/1/1/9/2/7/14074-SparkFun_20x4_SerLCD_-_Black_on_RGB_3.3V-05.jpg) 5 | 6 | [*SparkFun 20x4 SerLCD - Black on RGB 3.3V (LCD-14074)*](https://www.sparkfun.com/products/14074) 7 | 8 | The SparkFun SerLCD is an AVR-based, serial enabled LCD that provides a simple and cost effective solution for adding a 20x4 Black on RGB Liquid Crystal Display into your project. We’ve overhauled the design to include an ATmega328P that handles all of the screen control, meaning a backpack is no longer needed! This display can now accept three different types of communication protocols: serial, I2C, and SPI. This simplifies the number of wires needed and allows your project to display all kinds of text and numbers. 9 | 10 | The SerLCD is Qwiic compatible! We recommend adding a [Qwiic Adapter](https://www.sparkfun.com/products/14495) to the back of the SerLCD to get it onto the Qwiic bus. 11 | 12 | The on-board ATmega328P AVR microcontroller utilizes 11.0592 MHz crystal for greater communication accuracy with adjustable baud rates of 1200 through 1000000 but is default set at 9600. The firmware for this SerLCD is fully opensource and allows for any customizations you may need. 13 | 14 | Library written by Gaston Williams and Nathan Seidle ([SparkFun](http://www.sparkfun.com)). 15 | 16 | Repository Contents 17 | ------------------- 18 | 19 | * **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE. 20 | * **/src** - Source files for the library (.cpp, .h). 21 | * **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE. 22 | * **library.properties** - General library properties for the Arduino package manager. 23 | 24 | Documentation 25 | -------------- 26 | 27 | * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library. 28 | 29 | License Information 30 | ------------------- 31 | 32 | This product is _**open source**_! 33 | 34 | Various bits of the code have different licenses applied. Anything SparkFun wrote is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 35 | 36 | Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license. 37 | 38 | Distributed as-is; no warranty is given. 39 | 40 | - Your friends at SparkFun. -------------------------------------------------------------------------------- /examples/Example1-HelloWorld/Example1-HelloWorld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Hello World 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD 6 | and shows the time over I2C using the Qwiic system. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | This code is based on the LiquidCrystal code originally by David A. Mellis 24 | and the OpenLCD code by Nathan Seidle at SparkFun. 25 | 26 | License: This example code is in the public domain. 27 | 28 | More info on Qwiic here: https://www.sparkfun.com/qwiic 29 | 30 | AVR-Based Serial Enabled LCDs Hookup Guide 31 | https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide 32 | */ 33 | 34 | #include 35 | 36 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 37 | SerLCD lcd; // Initialize the library with default I2C address 0x72 38 | 39 | void setup() { 40 | Wire.begin(); 41 | 42 | lcd.begin(Wire); //Set up the LCD for I2C communication 43 | 44 | lcd.setBacklight(255, 255, 255); //Set backlight to bright white 45 | lcd.setContrast(5); //Set contrast. Lower to 0 for higher contrast. 46 | 47 | lcd.clear(); //Clear the display - this moves the cursor to home position as well 48 | lcd.print("Hello, World!"); 49 | } 50 | 51 | void loop() { 52 | // Set the cursor to column 0, line 1 53 | // (note: line 1 is the second row, since counting begins with 0): 54 | lcd.setCursor(0, 1); 55 | // Print the number of seconds since reset: 56 | lcd.print(millis() / 1000); 57 | } 58 | -------------------------------------------------------------------------------- /examples/Example10-TurnOffDisplay/Example10-TurnOffDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - display() and noDisplay() 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD and uses the 6 | display() and noDisplay() functions to turn on and off 7 | the display. 8 | 9 | The circuit: 10 | SparkFun RGB OpenLCD Serial display connected through 11 | a Sparkfun Qwiic adpater to an Ardruino with a 12 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 13 | 14 | The Qwiic adapter should be attached to the display as follows: 15 | Display / Qwiic Cable Color 16 | GND / Black 17 | RAW / Red 18 | SDA / Blue 19 | SCL / Yellow 20 | 21 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 22 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 23 | 24 | License: This example code is in the public domain. 25 | */ 26 | 27 | #include 28 | 29 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 30 | SerLCD lcd; // Initialize the library with default I2C address 0x72 31 | 32 | void setup() { 33 | Wire.begin(); 34 | lcd.begin(Wire); 35 | 36 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 37 | 38 | // Print a message to the LCD. 39 | lcd.print("Display on/off example"); 40 | } 41 | 42 | void loop() { 43 | // Turn off the display: 44 | lcd.noDisplay(); 45 | delay(500); 46 | // Turn on the display: 47 | lcd.display(); 48 | delay(500); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /examples/Example11-TextDirection/Example11-TextDirection.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Text Direction 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch demonstrates how to use leftToRight() and rightToLeft() 6 | to change the where the next character will be printed. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | This code is based on the LiquidCrystal code originally by David A. Mellis 24 | and the OpenLCD code by Nathan Seidle at SparkFun. 25 | 26 | License: This example code is in the public domain. 27 | 28 | More info on Qwiic here: https://www.sparkfun.com/qwiic 29 | 30 | AVR-Based Serial Enabled LCDs Hookup Guide 31 | https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide 32 | */ 33 | 34 | #include 35 | 36 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 37 | SerLCD lcd; // Initialize the library with default I2C address 0x72 38 | 39 | char thisChar = 'a'; 40 | 41 | void setup() { 42 | Wire.begin(); 43 | 44 | lcd.begin(Wire); //Set up the LCD for I2C 45 | 46 | // turn on the cursor: 47 | lcd.cursor(); 48 | } 49 | 50 | void loop() { 51 | // reverse directions at 'm': 52 | if (thisChar == 'm') { 53 | // go right for the next letter 54 | lcd.rightToLeft(); 55 | } 56 | // reverse again at 's': 57 | if (thisChar == 's') { 58 | // go left for the next letter 59 | lcd.leftToRight(); 60 | } 61 | // reset at 'z': 62 | if (thisChar > 'z') { 63 | // go to (0,0): 64 | lcd.home(); 65 | // start again at 0 66 | thisChar = 'a'; 67 | } 68 | // print the character 69 | lcd.write(thisChar); 70 | // wait a second: 71 | delay(1000); 72 | // increment the letter: 73 | thisChar++; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /examples/Example12-SerialToDisplay/Example12-SerialToDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Serial Input 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch takes serial characters from the serial port 6 | (e.g. from the Serial Monitor) and displays them on the SerLCD. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | License: This example code is in the public domain. 24 | */ 25 | 26 | #include 27 | 28 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 29 | SerLCD lcd; // Initialize the library with default I2C address 0x72 30 | 31 | void setup() { 32 | //Setup the LCD 33 | Wire.begin(); 34 | lcd.begin(Wire); 35 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 36 | 37 | //Setup serial port 38 | Serial.begin(9600); 39 | } 40 | 41 | void loop() { 42 | // when characters arrive over the serial port... 43 | if (Serial.available()) { 44 | // wait a bit for the entire message to arrive 45 | delay(100); 46 | // clear the screen 47 | lcd.clear(); 48 | // read all the available characters 49 | while (Serial.available() > 0) { 50 | // display each character to the LCD 51 | lcd.write(Serial.read()); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/Example13-FastBacklight/Example13-FastBacklight.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Fast Backlight Control 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch changes the backlight color and displays text using 6 | the OpenLCD functions. 7 | 8 | This method, setFastBacklight(), only works with v1.1 of SerLCD and newer. 9 | 10 | The circuit: 11 | SparkFun RGB OpenLCD Serial display connected through 12 | a Sparkfun Qwiic adpater to an Ardruino with a 13 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 14 | 15 | The Qwiic adapter should be attached to the display as follows: 16 | Display / Qwiic Cable Color 17 | GND / Black 18 | RAW / Red 19 | SDA / Blue 20 | SCL / Yellow 21 | 22 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 23 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 24 | 25 | License: This example code is in the public domain. 26 | */ 27 | 28 | #include 29 | 30 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 31 | SerLCD lcd; // Initialize the library with default I2C address 0x72 32 | 33 | void setup() { 34 | Wire.begin(); 35 | lcd.begin(Wire); 36 | 37 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 38 | } 39 | 40 | void loop() { 41 | lcd.setFastBacklight(255, 0, 0); //bright red 42 | lcd.clear(); 43 | lcd.print("Red"); 44 | delay(30); 45 | 46 | lcd.setFastBacklight(0xFF8C00); //orange 47 | lcd.clear(); 48 | lcd.print("Orange"); 49 | delay(30); 50 | } 51 | -------------------------------------------------------------------------------- /examples/Example14-ShowFirmwareVersion/Example14-ShowFirmwareVersion.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Show the firmware version 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints the device's firmware version to the screen. 6 | 7 | The circuit: 8 | SparkFun RGB OpenLCD Serial display connected through 9 | a Sparkfun Qwiic adpater to an Ardruino with a 10 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 11 | 12 | The Qwiic adapter should be attached to the display as follows: 13 | Display / Qwiic Cable Color 14 | GND / Black 15 | RAW / Red 16 | SDA / Blue 17 | SCL / Yellow 18 | 19 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 20 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 21 | 22 | This code is based on the LiquidCrystal code originally by David A. Mellis 23 | and the OpenLCD code by Nathan Seidle at SparkFun. 24 | 25 | License: This example code is in the public domain. 26 | */ 27 | 28 | #include 29 | 30 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 31 | SerLCD lcd; // Initialize the library with default I2C address 0x72 32 | 33 | void setup() { 34 | Wire.begin(); 35 | 36 | lcd.begin(Wire); //Set up the LCD for I2C 37 | } 38 | 39 | void loop() { 40 | lcd.command(','); //Send the comma to display the firmware version 41 | //Firmware will be displayed for 500ms so keep re-printing it 42 | delay(500); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/Example15-MessageEnable/Example15-MessageEnable.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Control when system message are displayed 3 | Nathan Seidle - February 16, 2019 4 | 5 | This sketch demonstrates how to turn off the system messages displayed when 6 | the user changes a setting. For instance 'Contrast: 5' or 'UART: 57600' is 7 | no longer displays. 8 | 9 | Note - This example and the disableSystemMessages and enableSystemMessages() 10 | commands are only supported on SerLCD v1.2 and above. 11 | 12 | The circuit: 13 | SparkFun RGB OpenLCD Serial display connected through 14 | a SparkFun Qwiic adpater to an Ardruino with a 15 | Qwiic shield or a SparkFun Blackboard with Qwiic built in. 16 | 17 | The Qwiic adapter should be attached to the display as follows: 18 | Display / Qwiic Cable Color 19 | GND / Black 20 | RAW / Red 21 | SDA / Blue 22 | SCL / Yellow 23 | 24 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 25 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 26 | 27 | This code is based on the LiquidCrystal code originally by David A. Mellis 28 | and the OpenLCD code by Nathan Seidle at SparkFun. 29 | 30 | License: This example code is in the public domain. 31 | 32 | More info on Qwiic here: https://www.sparkfun.com/qwiic 33 | 34 | AVR-Based Serial Enabled LCDs Hookup Guide 35 | https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide 36 | */ 37 | 38 | #include 39 | 40 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 41 | SerLCD lcd; // Initialize the library with default I2C address 0x72 42 | 43 | void setup() { 44 | Wire.begin(); 45 | 46 | lcd.begin(Wire); //Set up the LCD for I2C communication 47 | 48 | lcd.setBacklight(255, 255, 255); //Set backlight to bright white 49 | lcd.setContrast(5); //Set contrast. Lower to 0 for higher contrast. 50 | 51 | lcd.clear(); //Clear the display - this moves the cursor to home position as well 52 | lcd.print("Hello, World!"); 53 | 54 | lcd.disableSystemMessages(); //Now whenever you change a system setting like UART, or Contrast 55 | //SerLCD will not display the setting. This makes changing the setting faster, and also 56 | //invisible to the user. 57 | 58 | //lcd.enableSystemMessages(); //This will re-enable the printing of system messages 59 | 60 | lcd.setContrast(0); 61 | } 62 | 63 | void loop() { 64 | // Set the cursor to column 0, line 1 65 | // (note: line 1 is the second row, since counting begins with 0): 66 | lcd.setCursor(0, 1); 67 | // Print the number of seconds since reset: 68 | lcd.print(millis() / 1000); 69 | } 70 | -------------------------------------------------------------------------------- /examples/Example16-SetSplash/Example16-SetSplash.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Control splash and system message 3 | Nathan Seidle - February 16, 2019 4 | 5 | This sketch demonstrates how to create your own custom splash screen. 6 | 7 | This is done by first writing the text you want as your splash to the display, 8 | then 'saving' it as a splash screen. 9 | 10 | You can also disable or enable the displaying of the splash screen. 11 | 12 | Note - The disableSplash() and enableSplash() commands 13 | are only supported on SerLCD v1.2 and above. But you can still use the 14 | toggle splash command (Ctrl+i) to enable/disable the splash. 15 | 16 | The circuit: 17 | SparkFun RGB OpenLCD Serial display connected through 18 | a SparkFun Qwiic adpater to an Ardruino with a 19 | Qwiic shield or a SparkFun Blackboard with Qwiic built in. 20 | 21 | The Qwiic adapter should be attached to the display as follows: 22 | Display / Qwiic Cable Color 23 | GND / Black 24 | RAW / Red 25 | SDA / Blue 26 | SCL / Yellow 27 | 28 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 29 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 30 | 31 | This code is based on the LiquidCrystal code originally by David A. Mellis 32 | and the OpenLCD code by Nathan Seidle at SparkFun. 33 | 34 | License: This example code is in the public domain. 35 | 36 | More info on Qwiic here: https://www.sparkfun.com/qwiic 37 | 38 | AVR-Based Serial Enabled LCDs Hookup Guide 39 | https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide 40 | */ 41 | 42 | #include 43 | 44 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 45 | SerLCD lcd; // Initialize the library with default I2C address 0x72 46 | 47 | void setup() { 48 | Wire.begin(); 49 | 50 | lcd.begin(Wire); //Set up the LCD for I2C communication 51 | 52 | lcd.setBacklight(255, 255, 255); //Set backlight to bright white 53 | lcd.setContrast(5); //Set contrast. Lower to 0 for higher contrast. 54 | 55 | lcd.clear(); //Clear the display - this moves the cursor to home position as well 56 | lcd.print("Fozziwig's Chicken Factory!"); 57 | 58 | lcd.saveSplash(); //Save this current text as the splash screen at next power on 59 | 60 | lcd.enableSplash(); //This will cause the splash to be displayed at power on 61 | //lcd.disableSplash(); //This will supress any splash from being displayed at power on 62 | } 63 | 64 | void loop() { 65 | // Set the cursor to column 0, line 1 66 | // (note: line 1 is the second row, since counting begins with 0): 67 | lcd.setCursor(0, 1); 68 | // Print the number of seconds since reset: 69 | lcd.print(millis() / 1000); 70 | } 71 | -------------------------------------------------------------------------------- /examples/Example17-ChangeI2cAddress/Example17-ChangeI2cAddress.ino: -------------------------------------------------------------------------------- 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 52 | 53 | #include //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 | } -------------------------------------------------------------------------------- /examples/Example2-Backlight/Example2-Backlight.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Backlight 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch changes the backlight color and displays text using 6 | the OpenLCD functions. This works with the original version of 7 | SerLCD. See FastBacklight example for version 1.1 and later. 8 | 9 | The circuit: 10 | SparkFun RGB OpenLCD Serial display connected through 11 | a Sparkfun Qwiic adpater to an Ardruino with a 12 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 13 | 14 | The Qwiic adapter should be attached to the display as follows: 15 | Display / Qwiic Cable Color 16 | GND / Black 17 | RAW / Red 18 | SDA / Blue 19 | SCL / Yellow 20 | 21 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 22 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 23 | 24 | License: This example code is in the public domain. 25 | */ 26 | 27 | #include 28 | 29 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 30 | SerLCD lcd; // Initialize the library with default I2C address 0x72 31 | 32 | void setup() { 33 | Wire.begin(); 34 | 35 | lcd.begin(Wire); 36 | 37 | //By default .begin() will set I2C SCL to Standard Speed mode of 100kHz 38 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 39 | } 40 | 41 | void loop() { 42 | lcd.setBacklight(0, 0, 0); //black is off 43 | lcd.clear(); //Clear the display - this moves the cursor to home position as well 44 | lcd.print("Black (off)"); 45 | delay(3000); 46 | 47 | lcd.setBacklight(255, 0, 0); //bright red 48 | lcd.clear(); 49 | lcd.print("Red"); 50 | delay(3000); 51 | 52 | lcd.setBacklight(0xFF8C00); //orange 53 | lcd.clear(); 54 | lcd.print("Orange"); 55 | delay(3000); 56 | 57 | lcd.setBacklight(255, 255, 0); //bright yellow 58 | lcd.clear(); 59 | lcd.print("Yellow"); 60 | delay(3000); 61 | 62 | lcd.setBacklight(0, 255, 0); //bright green 63 | lcd.clear(); 64 | lcd.print("Green"); 65 | delay(3000); 66 | 67 | lcd.setBacklight(0, 0, 255); //bright blue 68 | lcd.clear(); 69 | lcd.print("Blue"); 70 | delay(3000); 71 | 72 | lcd.setBacklight(0x4B0082); //indigo, a kind of dark purplish blue 73 | lcd.clear(); 74 | lcd.print("Indigo"); 75 | delay(3000); 76 | 77 | lcd.setBacklight(0xA020F0); //violet 78 | lcd.clear(); 79 | lcd.print("Violet"); 80 | delay(3000); 81 | 82 | lcd.setBacklight(0x808080); //grey 83 | lcd.clear(); 84 | lcd.print("Grey"); 85 | delay(3000); 86 | 87 | lcd.setBacklight(255, 255, 255); //bright white 88 | lcd.clear(); 89 | lcd.print("White"); 90 | delay(3000); 91 | } 92 | -------------------------------------------------------------------------------- /examples/Example3-SetCursorPosition/Example3-SetCursorPosition.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Set Cursor 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch randomly picks a cursor position, goes to 6 | that position using the setCursor() method, and prints a character 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | License: This example code is in the public domain. 24 | */ 25 | 26 | #include 27 | 28 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 29 | SerLCD lcd; // Initialize the library with default I2C address 0x72 30 | 31 | // These constants won't change. But you can change the size of 32 | // your LCD using them: 33 | const int numRows = 2; 34 | //const int numRows = 4; 35 | const int numCols = 16; 36 | //const int numCols = 20; 37 | 38 | char thisLetter = 'a'; 39 | 40 | void setup() { 41 | Wire.begin(); 42 | lcd.begin(Wire); 43 | 44 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 45 | 46 | randomSeed(analogRead(A0)); //Feed the random number generator 47 | } 48 | 49 | void loop() { 50 | int randomColumn = random(0, numCols); 51 | int randomRow = random(0, numRows); 52 | 53 | // set the cursor position: 54 | lcd.setCursor(randomColumn, randomRow); 55 | // print the letter: 56 | lcd.write(thisLetter); 57 | delay(200); 58 | 59 | thisLetter++; 60 | if(thisLetter > 'z') thisLetter = 'a'; //Wrap the variable 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /examples/Example4-MoveCursor/Example4-MoveCursor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Move Cursor 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch displays text and then moves the cursor back and forth. These 6 | functions are not usually part of the LiquidCrystal library, but the functions 7 | are available in the Serial OpenLCD display, so I created functions for it. 8 | 9 | The circuit: 10 | SparkFun RGB OpenLCD Serial display connected through 11 | a Sparkfun Qwiic adpater to an Ardruino with a 12 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 13 | 14 | The Qwiic adapter should be attached to the display as follows: 15 | Display / Qwiic Cable Color 16 | GND / Black 17 | RAW / Red 18 | SDA / Blue 19 | SCL / Yellow 20 | 21 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 22 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 23 | 24 | License: This example code is in the public domain. 25 | */ 26 | 27 | #include 28 | 29 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 30 | SerLCD lcd; // Initialize the library with default I2C address 0x72 31 | 32 | void setup() { 33 | Wire.begin(); 34 | lcd.begin(Wire); 35 | 36 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 37 | 38 | lcd.clear(); 39 | lcd.cursor(); //Turn on the underline cursor 40 | lcd.print("Watch the cursor!"); 41 | } 42 | 43 | void loop() { 44 | //move cursor left in 3 steps 45 | lcd.moveCursorLeft(); 46 | delay(500); 47 | lcd.moveCursorLeft(); 48 | delay(500); 49 | lcd.moveCursorLeft(); 50 | delay(500); 51 | 52 | //move back in one step 53 | lcd.moveCursorRight(3); 54 | delay(500); 55 | 56 | //move cursor ahead 3 places in 1 step 57 | lcd.moveCursorRight(3); 58 | delay(500); 59 | 60 | //move back in 3 steps 61 | lcd.moveCursorLeft(); 62 | delay(500); 63 | lcd.moveCursorLeft(); 64 | delay(500); 65 | lcd.moveCursorLeft(); 66 | delay(500); 67 | } //loop 68 | -------------------------------------------------------------------------------- /examples/Example5-EnableCursor/Example5-EnableCursor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Cursor 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD and 6 | uses the cursor() and noCursor() methods to turn 7 | on and off the cursor. 8 | 9 | The circuit: 10 | SparkFun RGB OpenLCD Serial display connected through 11 | a Sparkfun Qwiic adpater to an Ardruino with a 12 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 13 | 14 | The Qwiic adapter should be attached to the display as follows: 15 | Display / Qwiic Cable Color 16 | GND / Black 17 | RAW / Red 18 | SDA / Blue 19 | SCL / Yellow 20 | 21 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 22 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 23 | 24 | License: This example code is in the public domain.*/ 25 | 26 | #include 27 | 28 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 29 | SerLCD lcd; // Initialize the library with default I2C address 0x72 30 | 31 | void setup() { 32 | Wire.begin(); 33 | lcd.begin(Wire); 34 | 35 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 36 | 37 | // Print a message to the LCD. 38 | lcd.print("hello, world!"); 39 | } 40 | 41 | void loop() { 42 | // Turn off the cursor: 43 | lcd.noCursor(); 44 | delay(500); 45 | // Turn on the cursor: 46 | lcd.cursor(); 47 | delay(500); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /examples/Example6-BlinkCursor/Example6-BlinkCursor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Blink 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD and makes the 6 | cursor block blink. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | License: This example code is in the public domain.*/ 24 | 25 | #include 26 | 27 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 28 | SerLCD lcd; // Initialize the library with default I2C address 0x72 29 | 30 | void setup() { 31 | Wire.begin(); 32 | lcd.begin(Wire); 33 | 34 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 35 | 36 | // Print a message to the LCD. 37 | lcd.print("hello, world!"); 38 | } 39 | 40 | void loop() { 41 | // Turn off the blinking cursor: 42 | lcd.noBlink(); 43 | delay(3000); 44 | // Turn on the blinking cursor: 45 | lcd.blink(); 46 | delay(3000); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/Example7-Scroll/Example7-Scroll.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - scrollDisplayLeft() and scrollDisplayRight() 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD and uses the 6 | scrollDisplayLeft() and scrollDisplayRight() methods to scroll 7 | the text. 8 | 9 | The circuit: 10 | SparkFun RGB OpenLCD Serial display connected through 11 | a Sparkfun Qwiic adpater to an Ardruino with a 12 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 13 | 14 | The Qwiic adapter should be attached to the display as follows: 15 | Display / Qwiic Cable Color 16 | GND / Black 17 | RAW / Red 18 | SDA / Blue 19 | SCL / Yellow 20 | 21 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 22 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 23 | 24 | License: This example code is in the public domain. 25 | */ 26 | 27 | #include 28 | 29 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 30 | SerLCD lcd; // Initialize the library with default I2C address 0x72 31 | 32 | void setup() { 33 | Wire.begin(); 34 | lcd.begin(Wire); 35 | 36 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 37 | 38 | // Print a message to the LCD. 39 | lcd.print("hello, world!"); 40 | delay(1000); 41 | } 42 | 43 | void loop() { 44 | // scroll 13 positions (string length) to the left 45 | // to move it offscreen left: 46 | for (int positionCounter = 0; positionCounter < 13; positionCounter++) { 47 | // scroll one position left: 48 | lcd.scrollDisplayLeft(); 49 | // wait a bit: 50 | delay(150); 51 | } 52 | 53 | // scroll 29 positions (string length + display length) to the right 54 | // to move it offscreen right: 55 | for (int positionCounter = 0; positionCounter < 29; positionCounter++) { 56 | // scroll one position right: 57 | lcd.scrollDisplayRight(); 58 | // wait a bit: 59 | delay(150); 60 | } 61 | 62 | // scroll 16 positions (display length + string length) to the left 63 | // to move it back to center: 64 | for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 65 | // scroll one position left: 66 | lcd.scrollDisplayLeft(); 67 | // wait a bit: 68 | delay(150); 69 | } 70 | 71 | // delay at the end of the full loop: 72 | delay(1000); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /examples/Example8-AutoscrollWithText/Example8-AutoscrollWithText.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Autoscroll with Text 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch demonstrates the use of the autoscroll() 6 | and noAutoscroll() functions to make new text scroll or not. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | License: This example code is in the public domain. 24 | */ 25 | 26 | #include 27 | 28 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 29 | SerLCD lcd; // Initialize the library with default I2C address 0x72 30 | 31 | void setup() { 32 | Wire.begin(); 33 | lcd.begin(Wire); 34 | 35 | Wire.setClock(400000); //Optional - set I2C SCL to High Speed Mode of 400kHz 36 | } 37 | 38 | void loop() { 39 | // set the cursor to (0,0): 40 | lcd.setCursor(0, 0); 41 | // print from 0 to 9: 42 | for (int thisChar = 0; thisChar < 10; thisChar++) { 43 | lcd.print(thisChar); 44 | delay(500); 45 | } 46 | 47 | // set the cursor to (16,1): 48 | lcd.setCursor(16, 1); 49 | // set the display to automatically scroll: 50 | lcd.autoscroll(); 51 | // print from 0 to 9: 52 | for (int thisChar = 0; thisChar < 10; thisChar++) { 53 | lcd.print(thisChar); 54 | delay(500); 55 | } 56 | // turn off automatic scrolling 57 | lcd.noAutoscroll(); 58 | 59 | // clear screen for the next loop: 60 | lcd.clear(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /examples/Example9-CustomCharacter/Example9-CustomCharacter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | QwiicSerLCD Library - Custom Characters 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "I SerLCD!" and a little dancing man 6 | to the LCD. Since the Serial OpenLCD display uses a serial command 7 | to display a customer character, the writeChar() method was added 8 | for this function. 9 | 10 | Custom characters are recorded to SerLCD and are remembered even after power is lost. 11 | There is a maximum of 8 custom characters that can be recorded. 12 | 13 | Based on Adafruit's example at 14 | https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde 15 | 16 | This example code is in the public domain. 17 | http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter 18 | 19 | Also useful: 20 | http://icontexto.com/charactercreator/ 21 | 22 | The circuit: 23 | SparkFun RGB OpenLCD Serial display connected through 24 | a Sparkfun Qwiic adpater to an Ardruino with a 25 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 26 | 27 | The Qwiic adapter should be attached to the display as follows: 28 | Display / Qwiic Cable Color 29 | GND / Black 30 | RAW / Red 31 | SDA / Blue 32 | SCL / Yellow 33 | 34 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 35 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 36 | */ 37 | 38 | #include 39 | 40 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 41 | SerLCD lcd; // Initialize the library with default I2C address 0x72 42 | 43 | // make some custom characters: 44 | byte heart[8] = { 45 | 0b00000, 46 | 0b01010, 47 | 0b11111, 48 | 0b11111, 49 | 0b11111, 50 | 0b01110, 51 | 0b00100, 52 | 0b00000 53 | }; 54 | 55 | byte smiley[8] = { 56 | 0b00000, 57 | 0b00000, 58 | 0b01010, 59 | 0b00000, 60 | 0b00000, 61 | 0b10001, 62 | 0b01110, 63 | 0b00000 64 | }; 65 | 66 | byte frownie[8] = { 67 | 0b00000, 68 | 0b00000, 69 | 0b01010, 70 | 0b00000, 71 | 0b00000, 72 | 0b00000, 73 | 0b01110, 74 | 0b10001 75 | }; 76 | 77 | byte armsDown[8] = { 78 | 0b00100, 79 | 0b01010, 80 | 0b00100, 81 | 0b00100, 82 | 0b01110, 83 | 0b10101, 84 | 0b00100, 85 | 0b01010 86 | }; 87 | 88 | byte armsUp[8] = { 89 | 0b00100, 90 | 0b01010, 91 | 0b00100, 92 | 0b10101, 93 | 0b01110, 94 | 0b00100, 95 | 0b00100, 96 | 0b01010 97 | }; 98 | 99 | void setup() { 100 | Wire.begin(); 101 | lcd.begin(Wire); 102 | 103 | //Send custom characters to display 104 | //These are recorded to SerLCD and are remembered even after power is lost 105 | //There is a maximum of 8 custom characters that can be recorded 106 | lcd.createChar(0, heart); 107 | lcd.createChar(1, smiley); 108 | lcd.createChar(2, frownie); 109 | lcd.createChar(3, armsDown); 110 | lcd.createChar(4, armsUp); 111 | 112 | // set the cursor to the top left 113 | lcd.setCursor(0, 0); 114 | 115 | // Print a message to the LCD. 116 | lcd.print("I "); 117 | lcd.writeChar(0); // Print the heart character. We have to use writeChar since it's a serial display. 118 | lcd.print(" SerLCD! "); 119 | lcd.writeChar(1); // Print smiley 120 | } 121 | 122 | void loop() { 123 | int delayTime = 200; 124 | 125 | lcd.setCursor(4, 1); //Column, row 126 | lcd.writeChar(3); // Print the little man, arms down 127 | delay(delayTime); 128 | 129 | lcd.setCursor(4, 1); 130 | lcd.writeChar(4); // Print the little man, arms up 131 | delay(delayTime); 132 | 133 | } 134 | -------------------------------------------------------------------------------- /examples/Serial/Example1-HelloWorld/Example1-HelloWorld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerLCD Library - Hello World 3 | Gaston Williams - August 29, 2018 4 | 5 | This sketch prints "Hello World!" to the LCD 6 | and shows the time over I2C using the Qwiic system. 7 | 8 | The circuit: 9 | SparkFun RGB OpenLCD Serial display connected through 10 | a Sparkfun Qwiic adpater to an Ardruino with a 11 | Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 12 | 13 | The Qwiic adapter should be attached to the display as follows: 14 | Display / Qwiic Cable Color 15 | GND / Black 16 | RAW / Red 17 | SDA / Blue 18 | SCL / Yellow 19 | 20 | Note: If you connect directly to a 5V Arduino instead, you *MUST* use 21 | a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 22 | 23 | This code is based on the LiquidCrystal code originally by David A. Mellis 24 | and the OpenLCD code by Nathan Seidle at SparkFun. 25 | 26 | License: This example code is in the public domain. 27 | 28 | More info on Qwiic here: https://www.sparkfun.com/qwiic 29 | 30 | AVR-Based Serial Enabled LCDs Hookup Guide 31 | https://learn.sparkfun.com/tutorials/avr-based-serial-enabled-lcds-hookup-guide 32 | */ 33 | 34 | #include 35 | 36 | #include //Click here to get the library: http://librarymanager/All#SparkFun_SerLCD 37 | SerLCD lcd; // Initialize the library with default I2C address 0x72 38 | 39 | void setup() { 40 | Serial.begin(9600); 41 | 42 | lcd.begin(Serial); //Set up the LCD for Serial communication at 9600bps 43 | 44 | lcd.setBacklight(255, 255, 255); //Set backlight to bright white 45 | lcd.setContrast(5); //Set contrast. Lower to 0 for higher contrast. 46 | 47 | lcd.clear(); //Clear the display - this moves the cursor to home position as well 48 | lcd.print("Hello, World!"); 49 | } 50 | 51 | void loop() { 52 | // Set the cursor to column 0, line 1 53 | // (note: line 1 is the second row, since counting begins with 0): 54 | lcd.setCursor(0, 1); 55 | // Print the number of seconds since reset: 56 | lcd.print(millis() / 1000); 57 | } 58 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For CharacterOLED 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SerLCD KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | clear KEYWORD2 17 | home KEYWORD2 18 | setCursor KEYWORD2 19 | createChar KEYWORD2 20 | writeChar KEYWORD2 21 | write KEYWORD2 22 | noDisplay KEYWORD2 23 | display KEYWORD2 24 | noCursor KEYWORD2 25 | cursor KEYWORD2 26 | noBlink KEYWORD2 27 | blink KEYWORD2 28 | scrollDisplayLeft KEYWORD2 29 | scrollDisplayRight KEYWORD2 30 | moveCursorLeft KEYWORD2 31 | moveCursorRight KEYWORD2 32 | setBacklight KEYWORD2 33 | setFastBacklight KEYWORD2 34 | leftToRight KEYWORD2 35 | rightToLeft KEYWORD2 36 | autoscroll KEYWORD2 37 | noAutoscroll KEYWORD2 38 | setContrast KEYWORD2 39 | setAddress KEYWORD2 40 | command KEYWORD2 41 | specialCommand KEYWORD2 42 | enableSystemMessages KEYWORD2 43 | disableSystemMessages KEYWORD2 44 | enableSplash KEYWORD2 45 | disableSplash KEYWORD2 46 | saveSplash KEYWORD2 47 | getAddress KEYWORD2 48 | 49 | 50 | ####################################### 51 | # Constants (LITERAL1) 52 | ####################################### 53 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SparkFun SerLCD Arduino Library 2 | version=1.0.9 3 | author=Gaston R. Williams and Nathan Seidle 4 | maintainer=SparkFun Electronics 5 | sentence=Library for I2C, SPI, and Serial Communication with SparkFun SerLCD Displays 6 | paragraph=An Arduino Library to allow simple control of 16x2 and 20x4 character SerLCDs from SparkFun. Includes RGB backlight control, display scrolling, cursor movement, and custom characters all over I2C, SPI, or Serial. 7 | category=Display 8 | url=https://github.com/sparkfun/SparkFun_SerLCD_Arduino_Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/SerLCD.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * LCD library for SparkFun RGB 3.3v Serial Open LCD display 3 | * with an attached Qwiic adapter. 4 | * 5 | * By: Gaston R. Williams 6 | * Date: August 22, 2018 7 | * Update: March 23, 2020 - fixed missing return value in write(uint8_t) 8 | * 9 | * License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 10 | * 11 | * This library is based heavily on the LiquidCrystal_I2C library and the sample code provided with 12 | * the SparkFun Serial OpenLCD display. The original LiquidCrystal library by David A. Mellis and 13 | * modified by Limor Fried and the OpenLCD code by Nathan Seidle at SparkFun. 14 | * 15 | * The LiquidCrystal_I2C library was based on the work by DFRobot. 16 | * (That's the only attribution I found in the code I have. If anyone can provide better information, 17 | * Plese let me know and I'll be happy to give credit where credit is due.) 18 | * 19 | * Original information copied from OpenLCD: 20 | * 21 | * The OpenLCD display information is based based on code by 22 | * Nathan Seidle 23 | * SparkFun Electronics 24 | * Date: April 19th, 2015 25 | * 26 | * License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 27 | * OpenLCD gives the user multiple interfaces (serial, I2C, and SPI) to control an LCD. SerLCD was the original 28 | * serial LCD from SparkFun that ran on the PIC 16F88 with only a serial interface and limited feature set. 29 | * This is an updated serial LCD. 30 | * 31 | * Please Note: 0x72 is the 7-bit I2C address. If you are using a different language than Arduino you will probably 32 | * need to add the Read/Write bit to the end of the address. This means the default read address for the OpenLCD 33 | * is 0b.1110.0101 or 0xE5 and the write address is 0b.1110.0100 or 0xE4. 34 | * For more information see https://learn.sparkfun.com/tutorials/i2c 35 | * Note: This code expects the display to be listening at the default I2C address. If your display is not at 0x72, you can 36 | * do a hardware reset. Tie the RX pin to ground and power up OpenLCD. You should see the splash screen 37 | * then "System reset Power cycle me" and the backlight will begin to blink. Now power down OpenLCD and remove 38 | * the RX/GND jumper. OpenLCD is now reset. 39 | * 40 | * To get this code to work, attach a Qwiic adapter to an OpenLCD. Use the Qwiic cable to attach adapter to a SparkFun Blackboard or 41 | * an Arduino Uno with the Qwiic shield. 42 | * 43 | * The OpenLCD has 4.7k pull up resistors on SDA and SCL. If you have other devices on the 44 | * I2C bus then you may want to disable the pull up resistors by clearing the PU (pull up) jumper. 45 | 46 | * OpenLCD will work at 400kHz Fast I2C. Use the .setClock() call shown below to set the data rate 47 | * faster if needed. 48 | * Command cheat sheet: 49 | * ASCII / DEC / HEX 50 | * '|' / 124 / 0x7C - Put into setting mode 51 | * Ctrl+c / 3 / 0x03 - Change width to 20 52 | * Ctrl+d / 4 / 0x04 - Change width to 16 53 | * Ctrl+e / 5 / 0x05 - Change lines to 4 54 | * Ctrl+f / 6 / 0x06 - Change lines to 2 55 | * Ctrl+g / 7 / 0x07 - Change lines to 1 56 | * Ctrl+h / 8 / 0x08 - Software reset of the system 57 | * Ctrl+i / 9 / 0x09 - Enable/disable splash screen 58 | * Ctrl+j / 10 / 0x0A - Save currently displayed text as splash 59 | * Ctrl+k / 11 / 0x0B - Change baud to 2400bps 60 | * Ctrl+l / 12 / 0x0C - Change baud to 4800bps 61 | * Ctrl+m / 13 / 0x0D - Change baud to 9600bps 62 | * Ctrl+n / 14 / 0x0E - Change baud to 14400bps 63 | * Ctrl+o / 15 / 0x0F - Change baud to 19200bps 64 | * Ctrl+p / 16 / 0x10 - Change baud to 38400bps 65 | * Ctrl+q / 17 / 0x11 - Change baud to 57600bps 66 | * Ctrl+r / 18 / 0x12 - Change baud to 115200bps 67 | * Ctrl+s / 19 / 0x13 - Change baud to 230400bps 68 | * Ctrl+t / 20 / 0x14 - Change baud to 460800bps 69 | * Ctrl+u / 21 / 0x15 - Change baud to 921600bps 70 | * Ctrl+v / 22 / 0x16 - Change baud to 1000000bps 71 | * Ctrl+w / 23 / 0x17 - Change baud to 1200bps 72 | * Ctrl+x / 24 / 0x18 - Change the contrast. Follow Ctrl+x with number 0 to 255. 120 is default. 73 | * Ctrl+y / 25 / 0x19 - Change the TWI address. Follow Ctrl+x with number 0 to 255. 114 (0x72) is default. 74 | * Ctrl+z / 26 / 0x1A - Enable/disable ignore RX pin on startup (ignore emergency reset) 75 | * '+' / 43 / 0x2B - Set RGB backlight with three following bytes, 0-255 76 | * ',' / 44 / 0x2C - Display current firmware version 77 | * '-' / 45 / 0x2D - Clear display. Move cursor to home position. 78 | * '.' / 46 / 0x2E - Enable system messages (ie, display 'Contrast: 5' when changed) 79 | * '/' / 47 / 0x2F - Disable system messages (ie, don't display 'Contrast: 5' when changed) 80 | * '0' / 48 / 0x30 - Enable splash screen 81 | * '1' / 49 / 0x31 - Disable splash screen 82 | * / 128-157 / 0x80-0x9D - Set the primary backlight brightness. 128 = Off, 157 = 100%. 83 | * / 158-187 / 0x9E-0xBB - Set the green backlight brightness. 158 = Off, 187 = 100%. 84 | * / 188-217 / 0xBC-0xD9 - Set the blue backlight brightness. 188 = Off, 217 = 100%. 85 | * For example, to change the baud rate to 115200 send 124 followed by 18. 86 | * 87 | */ 88 | #include "SerLCD.h" 89 | 90 | //<> setup using defaults 91 | SerLCD::SerLCD() 92 | { 93 | } 94 | 95 | //<> 96 | SerLCD::~SerLCD() 97 | { /*nothing to destruct*/ 98 | } 99 | 100 | /* 101 | * Set up the i2c communication with the SerLCD. 102 | * wirePort - TwoWire port 103 | * ic2_addr - I2C address 104 | */ 105 | void SerLCD::begin(TwoWire &wirePort, byte i2c_addr) 106 | { 107 | _i2cAddr = i2c_addr; 108 | 109 | begin(wirePort); 110 | } // begin 111 | 112 | /* 113 | * Set up the i2c communication with the SerLCD. 114 | */ 115 | void SerLCD::begin(TwoWire &wirePort) 116 | { 117 | _i2cPort = &wirePort; //Grab which port the user wants us to use 118 | _serialPort = NULL; //Set to null to be safe 119 | _spiPort = NULL; //Set to null to be safe 120 | 121 | //Call init function since display may have been left in unknown state 122 | init(); 123 | } // begin 124 | 125 | /* 126 | * Set up the serial communication with the SerLCD. 127 | */ 128 | void SerLCD::begin(Stream &serialPort) 129 | { 130 | _serialPort = &serialPort; //Grab which port the user wants us to use 131 | _i2cPort = NULL; //Set to null to be safe 132 | _spiPort = NULL; //Set to null to be safe 133 | 134 | //Call init function since display may have been left in unknown state 135 | init(); 136 | } // begin 137 | 138 | //Only available in Arduino 1.6 or later 139 | #ifdef SPI_HAS_TRANSACTION 140 | /* 141 | * Set up the SPI communication with the SerLCD using SPI transactions 142 | * 143 | * NB we pass SPISettings by value, since many of the examples for the SPI 144 | * transactions create the settings object in the function call, and that only 145 | * works if the function passes the object by value. 146 | */ 147 | void SerLCD::begin(SPIClass &spiPort, byte csPin, SPISettings spiSettings) 148 | { 149 | _spiSettings = spiSettings; 150 | _spiTransaction = true; 151 | 152 | begin(spiPort, csPin); 153 | } // begin 154 | #endif 155 | 156 | /* 157 | * Set up the SPI communication with the SerLCD. 158 | */ 159 | void SerLCD::begin(SPIClass &spiPort, byte csPin) 160 | { 161 | _csPin = csPin; 162 | 163 | pinMode(csPin, OUTPUT); //set pin to output, in case user forgot 164 | digitalWrite(csPin, HIGH); //deselect dispaly, in case user forgot 165 | 166 | _spiPort = &spiPort; //Grab the port the user wants us to use 167 | _i2cPort = NULL; //Set to null to be safe 168 | _serialPort = NULL; //Set to null to be safe 169 | 170 | _spiPort->begin(); //call begin, in case the user forgot 171 | 172 | //Call init function since display may have been left in unknown state 173 | init(); 174 | } // begin 175 | 176 | //private functions for serial transmission 177 | /* 178 | * Begin transmission to the device 179 | */ 180 | void SerLCD::beginTransmission() 181 | { 182 | //do nothing if using serialPort 183 | if (_i2cPort) 184 | { 185 | _i2cPort->beginTransmission(_i2cAddr); // transmit to device 186 | } 187 | else if (_spiPort) 188 | { 189 | #ifdef SPI_HAS_TRANSACTION 190 | if (_spiTransaction) 191 | { 192 | _spiPort->beginTransaction(_spiSettings); //gain control of the SPI bus 193 | } //if _spiSettings 194 | #endif 195 | digitalWrite(_csPin, LOW); 196 | delay(10); //wait a bit for display to enable 197 | } // if-else 198 | } //beginTransmission 199 | 200 | /* 201 | * Send data to the device 202 | * 203 | * data - byte to send 204 | */ 205 | void SerLCD::transmit(uint8_t data) 206 | { 207 | if (_i2cPort) 208 | { 209 | _i2cPort->write(data); // transmit to device 210 | } 211 | else if (_serialPort) 212 | { 213 | _serialPort->write(data); 214 | } 215 | else if (_spiPort) 216 | { 217 | _spiPort->transfer(data); 218 | } // if-else 219 | } //transmit 220 | 221 | /* 222 | * Begin transmission to the device 223 | */ 224 | void SerLCD::endTransmission() 225 | { 226 | //do nothing if using Serial port 227 | if (_i2cPort) 228 | { 229 | _i2cPort->endTransmission(); // transmit to device 230 | } 231 | else if (_spiPort) 232 | { 233 | digitalWrite(_csPin, HIGH); //disable display 234 | #ifdef SPI_HAS_TRANSACTION 235 | if (_spiTransaction) 236 | { 237 | _spiPort->endTransaction(); //let go of the SPI bus 238 | } //if _spiSettings 239 | #endif 240 | delay(10); //wait a bit for display to disable 241 | } // if-else 242 | } //beginTransmission 243 | 244 | /* 245 | * Initialize the display 246 | * 247 | */ 248 | void SerLCD::init() 249 | { 250 | beginTransmission(); 251 | transmit(SPECIAL_COMMAND); //Send special command character 252 | transmit(LCD_DISPLAYCONTROL | _displayControl); //Send the display command 253 | transmit(SPECIAL_COMMAND); //Send special command character 254 | transmit(LCD_ENTRYMODESET | _displayMode); //Send the entry mode command 255 | transmit(SETTING_COMMAND); //Put LCD into setting mode 256 | transmit(CLEAR_COMMAND); //Send clear display command 257 | endTransmission(); //Stop transmission 258 | delay(50); //let things settle a bit 259 | } //init 260 | 261 | /* 262 | * Send a command to the display. 263 | * Used by other functions. 264 | * 265 | * byte command to send 266 | */ 267 | void SerLCD::command(byte command) 268 | { 269 | beginTransmission(); // transmit to device 270 | transmit(SETTING_COMMAND); //Put LCD into setting mode 271 | transmit(command); //Send the command code 272 | endTransmission(); //Stop transmission 273 | 274 | delay(10); //Hang out for a bit 275 | } 276 | 277 | /* 278 | * Send a special command to the display. Used by other functions. 279 | * 280 | * byte command to send 281 | */ 282 | void SerLCD::specialCommand(byte command) 283 | { 284 | beginTransmission(); // transmit to device 285 | transmit(SPECIAL_COMMAND); //Send special command character 286 | transmit(command); //Send the command code 287 | endTransmission(); //Stop transmission 288 | 289 | delay(50); //Wait a bit longer for special display commands 290 | } 291 | 292 | /* 293 | * Send multiple special commands to the display. 294 | * Used by other functions. 295 | * 296 | * byte command to send 297 | * byte count number of times to send 298 | */ 299 | void SerLCD::specialCommand(byte command, byte count) 300 | { 301 | beginTransmission(); // transmit to device 302 | 303 | for (int i = 0; i < count; i++) 304 | { 305 | transmit(SPECIAL_COMMAND); //Send special command character 306 | transmit(command); //Send command code 307 | } // for 308 | endTransmission(); //Stop transmission 309 | 310 | delay(50); //Wait a bit longer for special display commands 311 | } 312 | 313 | /* 314 | * Send the clear command to the display. This clears the 315 | * display and forces the cursor to return to the beginning 316 | * of the display. 317 | */ 318 | void SerLCD::clear() 319 | { 320 | command(CLEAR_COMMAND); 321 | delay(10); // a little extra delay after clear 322 | } 323 | 324 | /* 325 | * Send the home command to the display. This returns the cursor 326 | * to return to the beginning of the display, without clearing 327 | * the display. 328 | */ 329 | void SerLCD::home() 330 | { 331 | specialCommand(LCD_RETURNHOME); 332 | } 333 | 334 | /* 335 | * Set the cursor position to a particular column and row. 336 | * 337 | * column - byte 0 to 19 338 | * row - byte 0 to 3 339 | * 340 | */ 341 | void SerLCD::setCursor(byte col, byte row) 342 | { 343 | int row_offsets[] = {0x00, 0x40, 0x14, 0x54}; 344 | 345 | //kepp variables in bounds 346 | row = min(row, (byte)(MAX_ROWS - 1)); //row cannot be greater than max rows 347 | 348 | //send the command 349 | specialCommand(LCD_SETDDRAMADDR | (col + row_offsets[row])); 350 | } // setCursor 351 | 352 | /* 353 | * Create a customer character 354 | * byte location - character number 0 to 7 355 | * byte[] charmap - byte array for character 356 | */ 357 | void SerLCD::createChar(byte location, byte charmap[]) 358 | { 359 | location &= 0x7; // we only have 8 locations 0-7 360 | beginTransmission(); 361 | //Send request to create a customer character 362 | transmit(SETTING_COMMAND); //Put LCD into setting mode 363 | transmit(27 + location); 364 | for (int i = 0; i < 8; i++) 365 | { 366 | transmit(charmap[i]); 367 | } // for 368 | endTransmission(); 369 | delay(50); //This takes a bit longer 370 | } 371 | 372 | /* 373 | * Write a customer character to the display 374 | * 375 | * byte location - character number 0 to 7 376 | */ 377 | void SerLCD::writeChar(byte location) 378 | { 379 | location &= 0x7; // we only have 8 locations 0-7 380 | 381 | command(35 + location); 382 | } 383 | 384 | /* 385 | * Write a byte to the display. 386 | * Required for Print. 387 | */ 388 | size_t SerLCD::write(uint8_t b) 389 | { 390 | beginTransmission(); // transmit to device 391 | transmit(b); 392 | endTransmission(); //Stop transmission 393 | delay(10); // wait a bit 394 | return 1; 395 | } // write 396 | 397 | /* 398 | * Write a character buffer to the display. 399 | * Required for Print. 400 | */ 401 | size_t SerLCD::write(const uint8_t *buffer, size_t size) 402 | { 403 | size_t n = 0; 404 | beginTransmission(); // transmit to device 405 | while (size--) 406 | { 407 | transmit(*buffer++); 408 | n++; 409 | } //while 410 | endTransmission(); //Stop transmission 411 | delay(10); // 412 | return n; 413 | } //write 414 | 415 | /* 416 | * Write a string to the display. 417 | * Required for Print. 418 | */ 419 | size_t SerLCD::write(const char *str) 420 | { 421 | if (str == NULL) 422 | return 0; 423 | return write((const uint8_t *)str, strlen(str)); 424 | } 425 | 426 | /* 427 | * Turn the display off quickly. 428 | */ 429 | void SerLCD::noDisplay() 430 | { 431 | _displayControl &= ~LCD_DISPLAYON; 432 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 433 | } // noDisplay 434 | 435 | /* 436 | * Turn the display on quickly. 437 | */ 438 | void SerLCD::display() 439 | { 440 | _displayControl |= LCD_DISPLAYON; 441 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 442 | } // display 443 | 444 | /* 445 | * Turn the underline cursor off. 446 | */ 447 | void SerLCD::noCursor() 448 | { 449 | _displayControl &= ~LCD_CURSORON; 450 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 451 | } // noCursor 452 | 453 | /* 454 | * Turn the underline cursor on. 455 | */ 456 | void SerLCD::cursor() 457 | { 458 | _displayControl |= LCD_CURSORON; 459 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 460 | } // cursor 461 | 462 | /* 463 | * Turn the blink cursor off. 464 | */ 465 | void SerLCD::noBlink() 466 | { 467 | _displayControl &= ~LCD_BLINKON; 468 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 469 | } // noBlink 470 | 471 | /* 472 | * Turn the blink cursor on. 473 | */ 474 | void SerLCD::blink() 475 | { 476 | _displayControl |= LCD_BLINKON; 477 | specialCommand(LCD_DISPLAYCONTROL | _displayControl); 478 | } // blink 479 | 480 | /* 481 | * Scroll the display one character to the left, without 482 | * changing the text 483 | */ 484 | void SerLCD::scrollDisplayLeft() 485 | { 486 | specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 487 | } // scrollDisplayLeft 488 | 489 | /* 490 | * Scroll the display multiple characters to the left, without 491 | * changing the text 492 | * 493 | * count byte - number of characters to scroll 494 | */ 495 | void SerLCD::scrollDisplayLeft(byte count) 496 | { 497 | specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT, count); 498 | } // scrollDisplayLeft 499 | 500 | /* 501 | * Scroll the display one character to the right, without 502 | * changing the text 503 | */ 504 | void SerLCD::scrollDisplayRight() 505 | { 506 | specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 507 | } // scrollDisplayRight 508 | 509 | /* 510 | * Scroll the display multiple characters to the right, without 511 | * changing the text 512 | * 513 | * count byte - number of characters to scroll 514 | */ 515 | void SerLCD::scrollDisplayRight(byte count) 516 | { 517 | specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT, count); 518 | } // scrollDisplayRight 519 | 520 | /* 521 | * Move the cursor one character to the left. 522 | */ 523 | void SerLCD::moveCursorLeft() 524 | { 525 | specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT); 526 | } // moveCursorLeft 527 | 528 | /* 529 | * Move the cursor multiple characters to the left. 530 | * 531 | * count byte - number of characters to move 532 | */ 533 | void SerLCD::moveCursorLeft(byte count) 534 | { 535 | specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT, count); 536 | } // moveCursorLeft 537 | 538 | /* 539 | * Move the cursor one character to the right. 540 | */ 541 | void SerLCD::moveCursorRight() 542 | { 543 | specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT); 544 | } // moveCursorRight 545 | 546 | /* 547 | * Move the cursor multiple characters to the right. 548 | * 549 | * count byte - number of characters to move 550 | */ 551 | void SerLCD::moveCursorRight(byte count) 552 | { 553 | specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT, count); 554 | } // moveCursorRight 555 | 556 | /* 557 | * Use a standard hex rgb value (0x00000000 to 0x00FFFFFF) to set 558 | * the backlight color. 559 | * 560 | * The encoded long value has form (0x00RRGGBB) where RR, GG and BB 561 | * are red, green, blue byte values in hex. The remaining two most 562 | * significant bytes of the long value are ignored. 563 | * 564 | * rgb - unsigned long hex encoded rgb value. 565 | */ 566 | void SerLCD::setBacklight(unsigned long rgb) 567 | { 568 | // convert from hex triplet to byte values 569 | byte r = (rgb >> 16) & 0x0000FF; 570 | byte g = (rgb >> 8) & 0x0000FF; 571 | byte b = rgb & 0x0000FF; 572 | 573 | setBacklight(r, g, b); 574 | } 575 | 576 | /* 577 | * Uses a standard rgb byte triplit eg. (255, 0, 255) to 578 | * set the backlight color. 579 | */ 580 | void SerLCD::setBacklight(byte r, byte g, byte b) 581 | { 582 | // map the byte value range to backlight command range 583 | byte red = 128 + map(r, 0, 255, 0, 29); 584 | byte green = 158 + map(g, 0, 255, 0, 29); 585 | byte blue = 188 + map(b, 0, 255, 0, 29); 586 | 587 | //send commands to the display to set backlights 588 | beginTransmission(); // transmit to device 589 | 590 | //Turn display off to hide confirmation messages 591 | _displayControl &= ~LCD_DISPLAYON; 592 | transmit(SPECIAL_COMMAND); //Send special command character 593 | transmit(LCD_DISPLAYCONTROL | _displayControl); 594 | 595 | //Set the red, green and blue values 596 | transmit(SETTING_COMMAND); //Set red backlight amount 597 | transmit(red); 598 | transmit(SETTING_COMMAND); //Set green backlight amount 599 | transmit(green); 600 | transmit(SETTING_COMMAND); //Set blue backlight amount 601 | transmit(blue); 602 | 603 | //Turn display back on and end 604 | _displayControl |= LCD_DISPLAYON; 605 | transmit(SPECIAL_COMMAND); //Send special command character 606 | transmit(LCD_DISPLAYCONTROL | _displayControl); //Turn display on as before 607 | endTransmission(); //Stop transmission 608 | delay(50); //This one is a bit slow 609 | } // setBacklight 610 | 611 | // New backlight function 612 | void SerLCD::setFastBacklight(unsigned long rgb) 613 | { 614 | // convert from hex triplet to byte values 615 | byte r = (rgb >> 16) & 0x0000FF; 616 | byte g = (rgb >> 8) & 0x0000FF; 617 | byte b = rgb & 0x0000FF; 618 | 619 | setFastBacklight(r, g, b); 620 | } 621 | 622 | //New command - set backlight with LCD messages or delays 623 | void SerLCD::setFastBacklight(byte r, byte g, byte b) 624 | { 625 | //send commands to the display to set backlights 626 | beginTransmission(); // transmit to device 627 | transmit(SETTING_COMMAND); //Send special command character 628 | transmit(SET_RGB_COMMAND); //Send the set RGB character '+' or plus 629 | transmit(r); //Send the red value 630 | transmit(g); //Send the green value 631 | transmit(b); //Send the blue value 632 | endTransmission(); //Stop transmission 633 | delay(10); 634 | } // setFastBacklight 635 | 636 | //Enable system messages 637 | //This allows user to see printing messages like 'UART: 57600' and 'Contrast: 5' 638 | void SerLCD::enableSystemMessages() 639 | { 640 | beginTransmission(); // transmit to device 641 | transmit(SETTING_COMMAND); //Send special command character 642 | transmit(ENABLE_SYSTEM_MESSAGE_DISPLAY); //Send the set '.' character 643 | endTransmission(); //Stop transmission 644 | delay(10); 645 | } 646 | 647 | //Disable system messages 648 | //This allows user to disable printing messages like 'UART: 57600' and 'Contrast: 5' 649 | void SerLCD::disableSystemMessages() 650 | { 651 | beginTransmission(); // transmit to device 652 | transmit(SETTING_COMMAND); //Send special command character 653 | transmit(DISABLE_SYSTEM_MESSAGE_DISPLAY); //Send the set '.' character 654 | endTransmission(); //Stop transmission 655 | delay(10); 656 | } 657 | 658 | //Enable splash screen at power on 659 | void SerLCD::enableSplash() 660 | { 661 | beginTransmission(); // transmit to device 662 | transmit(SETTING_COMMAND); //Send special command character 663 | transmit(ENABLE_SPLASH_DISPLAY); //Send the set '.' character 664 | endTransmission(); //Stop transmission 665 | delay(10); 666 | } 667 | 668 | //Disable splash screen at power on 669 | void SerLCD::disableSplash() 670 | { 671 | beginTransmission(); // transmit to device 672 | transmit(SETTING_COMMAND); //Send special command character 673 | transmit(DISABLE_SPLASH_DISPLAY); //Send the set '.' character 674 | endTransmission(); //Stop transmission 675 | delay(10); 676 | } 677 | 678 | //Save the current display as the splash 679 | void SerLCD::saveSplash() 680 | { 681 | //Save whatever is currently being displayed into EEPROM 682 | //This will be displayed at next power on as the splash screen 683 | beginTransmission(); // transmit to device 684 | transmit(SETTING_COMMAND); //Send special command character 685 | transmit(SAVE_CURRENT_DISPLAY_AS_SPLASH); //Send the set Ctrl+j character 686 | endTransmission(); //Stop transmission 687 | delay(10); 688 | } 689 | 690 | /* 691 | * Set the text to flow from left to right. This is the direction 692 | * that is common to most Western languages. 693 | */ 694 | void SerLCD::leftToRight() 695 | { 696 | _displayMode |= LCD_ENTRYLEFT; 697 | specialCommand(LCD_ENTRYMODESET | _displayMode); 698 | } // leftToRight 699 | 700 | /* 701 | * Set the text to flow from right to left. 702 | */ 703 | void SerLCD::rightToLeft() 704 | { 705 | _displayMode &= ~LCD_ENTRYLEFT; 706 | specialCommand(LCD_ENTRYMODESET | _displayMode); 707 | } //rightToLeft 708 | 709 | /* 710 | * Turn autoscrolling on. This will 'right justify' text from 711 | * the cursor. 712 | */ 713 | void SerLCD::autoscroll() 714 | { 715 | _displayMode |= LCD_ENTRYSHIFTINCREMENT; 716 | specialCommand(LCD_ENTRYMODESET | _displayMode); 717 | } //autoscroll 718 | 719 | /* 720 | * Turn autoscrolling off. 721 | */ 722 | void SerLCD::noAutoscroll() 723 | { 724 | _displayMode &= ~LCD_ENTRYSHIFTINCREMENT; 725 | specialCommand(LCD_ENTRYMODESET | _displayMode); 726 | } //noAutoscroll 727 | 728 | /* 729 | * Change the contrast from 0 to 255. 120 is default. 730 | * 731 | * byte new_val - new contrast value 732 | */ 733 | void SerLCD::setContrast(byte new_val) 734 | { 735 | //send commands to the display to set backlights 736 | beginTransmission(); // transmit to device 737 | transmit(SETTING_COMMAND); //Send contrast command 738 | transmit(CONTRAST_COMMAND); //0x18 739 | transmit(new_val); //Send new contrast value 740 | endTransmission(); //Stop transmission 741 | 742 | delay(10); //Wait a little bit 743 | } //setContrast 744 | 745 | /* 746 | * Change the I2C Address. 0x72 is the default. 747 | * Note that this change is persistent. If anything 748 | * goes wrong you may need to do a hardware reset 749 | * to unbrick the display. 750 | * 751 | * byte new_addr - new i2c address 752 | */ 753 | void SerLCD::setAddress(byte new_addr) 754 | { 755 | //send commands to the display to set backlights 756 | beginTransmission(); // transmit to device on old address 757 | transmit(SETTING_COMMAND); //Send contrast command 758 | transmit(ADDRESS_COMMAND); //0x19 759 | transmit(new_addr); //Send new contrast value 760 | endTransmission(); //Stop transmission 761 | 762 | //Update our own address so we can still talk to the display 763 | _i2cAddr = new_addr; 764 | 765 | delay(50); //This may take awhile 766 | } //setAddress 767 | 768 | /* 769 | * getAddress 770 | * 771 | * Returns private variable I2C address 772 | */ 773 | byte SerLCD::getAddress() 774 | { 775 | return _i2cAddr; 776 | } //getAddress 777 | -------------------------------------------------------------------------------- /src/SerLCD.h: -------------------------------------------------------------------------------- 1 | #ifndef QWIIC_SER_LCD_H 2 | #define QWIIC_SER_LCD_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define DISPLAY_ADDRESS1 0x72 //This is the default address of the OpenLCD 10 | #define MAX_ROWS 4 11 | #define MAX_COLUMNS 20 12 | 13 | //OpenLCD command characters 14 | #define SPECIAL_COMMAND 254 //Magic number for sending a special command 15 | #define SETTING_COMMAND 0x7C //124, |, the pipe character: The command to change settings: baud, lines, width, backlight, splash, etc 16 | 17 | //OpenLCD commands 18 | #define CLEAR_COMMAND 0x2D //45, -, the dash character: command to clear and home the display 19 | #define CONTRAST_COMMAND 0x18 //Command to change the contrast setting 20 | #define ADDRESS_COMMAND 0x19 //Command to change the i2c address 21 | #define SET_RGB_COMMAND 0x2B //43, +, the plus character: command to set backlight RGB value 22 | #define ENABLE_SYSTEM_MESSAGE_DISPLAY 0x2E //46, ., command to enable system messages being displayed 23 | #define DISABLE_SYSTEM_MESSAGE_DISPLAY 0x2F //47, /, command to disable system messages being displayed 24 | #define ENABLE_SPLASH_DISPLAY 0x30 //48, 0, command to enable splash screen at power on 25 | #define DISABLE_SPLASH_DISPLAY 0x31 //49, 1, command to disable splash screen at power on 26 | #define SAVE_CURRENT_DISPLAY_AS_SPLASH 0x0A //10, Ctrl+j, command to save current text on display as splash 27 | 28 | // special commands 29 | #define LCD_RETURNHOME 0x02 30 | #define LCD_ENTRYMODESET 0x04 31 | #define LCD_DISPLAYCONTROL 0x08 32 | #define LCD_CURSORSHIFT 0x10 33 | #define LCD_SETDDRAMADDR 0x80 34 | 35 | // flags for display entry mode 36 | #define LCD_ENTRYRIGHT 0x00 37 | #define LCD_ENTRYLEFT 0x02 38 | #define LCD_ENTRYSHIFTINCREMENT 0x01 39 | #define LCD_ENTRYSHIFTDECREMENT 0x00 40 | 41 | // flags for display on/off control 42 | #define LCD_DISPLAYON 0x04 43 | #define LCD_DISPLAYOFF 0x00 44 | #define LCD_CURSORON 0x02 45 | #define LCD_CURSOROFF 0x00 46 | #define LCD_BLINKON 0x01 47 | #define LCD_BLINKOFF 0x00 48 | 49 | // flags for display/cursor shift 50 | #define LCD_DISPLAYMOVE 0x08 51 | #define LCD_CURSORMOVE 0x00 52 | #define LCD_MOVERIGHT 0x04 53 | #define LCD_MOVELEFT 0x00 54 | 55 | class SerLCD : public Print 56 | { 57 | 58 | public: 59 | SerLCD(); 60 | ~SerLCD(); 61 | void begin(TwoWire &wirePort); 62 | void begin(TwoWire &wirePort, byte i2c_addr); 63 | void begin(Stream &serial); 64 | void begin(SPIClass &spiPort, byte csPin); 65 | //Only available for Arduino 1.6 and greater 66 | #ifdef SPI_HAS_TRANSACTION 67 | //pass SPISettings by value to allow settings object creation in fucntion call like examples 68 | void begin(SPIClass &spiPort, byte csPin, SPISettings spiSettings); 69 | #endif 70 | void clear(); 71 | void home(); 72 | void setCursor(byte col, byte row); 73 | void createChar(byte location, byte charmap[]); 74 | void writeChar(byte location); 75 | virtual size_t write(uint8_t); 76 | virtual size_t write(const uint8_t *buffer, size_t size); 77 | virtual size_t write(const char *str); 78 | void noDisplay(); 79 | void display(); 80 | void noCursor(); 81 | void cursor(); 82 | void noBlink(); 83 | void blink(); 84 | void scrollDisplayLeft(); 85 | void scrollDisplayRight(); 86 | void scrollDisplayLeft(byte count); 87 | void scrollDisplayRight(byte count); 88 | void moveCursorLeft(); 89 | void moveCursorRight(); 90 | void moveCursorLeft(byte count); 91 | void moveCursorRight(byte count); 92 | void setBacklight(unsigned long rgb); 93 | void setBacklight(byte r, byte g, byte b); 94 | void setFastBacklight(unsigned long rgb); 95 | void setFastBacklight(byte r, byte g, byte b); 96 | void leftToRight(); 97 | void rightToLeft(); 98 | void autoscroll(); 99 | void noAutoscroll(); 100 | void setContrast(byte new_val); 101 | void setAddress(byte new_addr); 102 | void command(byte command); 103 | void specialCommand(byte command); 104 | void specialCommand(byte command, byte count); 105 | 106 | void enableSystemMessages(); 107 | void disableSystemMessages(); 108 | void enableSplash(); 109 | void disableSplash(); 110 | void saveSplash(); 111 | byte getAddress(); 112 | 113 | private: 114 | TwoWire *_i2cPort = NULL; //The generic connection to user's chosen I2C hardware 115 | Stream *_serialPort = NULL; //The generic connection to user's chosen serial hardware 116 | SPIClass *_spiPort = NULL; //The generic connection to user's chosen spi hardware 117 | 118 | //SPI transactions only available for Arduino 1.6 and later 119 | #ifdef SPI_HAS_TRANSACTION 120 | SPISettings _spiSettings = SPISettings(100000, MSBFIRST, SPI_MODE0); 121 | bool _spiTransaction = false; //since we pass by value, we need a flag 122 | #endif 123 | byte _csPin = 10; 124 | byte _i2cAddr = DISPLAY_ADDRESS1; 125 | byte _displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 126 | byte _displayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 127 | void init(); 128 | void beginTransmission(); 129 | void transmit(byte data); 130 | void endTransmission(); 131 | }; 132 | 133 | #endif -------------------------------------------------------------------------------- /tests/HelloWorld_OpenLCD_SPI/HelloWorld_OpenLCD_SPI.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is example code that shows how to send data over SPI to the display. 3 | * 4 | * To get this code to work, attached an OpenLCD to an Arduino Uno using the following pins: 5 | * CS (OpenLCD) to 10 (Arduino) 6 | * SDI to 11 7 | * SDO to 12 (optional) 8 | * SCK to 13 9 | */ 10 | 11 | // include the Qwiic OpenLCD library code: 12 | #include 13 | #include 14 | 15 | byte csPin = 10; //You can use any output pin but for this example we use 10 16 | 17 | 18 | // initialize the library 19 | QwiicSerLCD lcd; 20 | 21 | void setup() { 22 | pinMode(csPin, OUTPUT); 23 | SPI.begin(); 24 | 25 | lcd.begin(SPI, csPin, SPISettings(100000, MSBFIRST, SPI_MODE0)); 26 | //For Arduino versions before 1.6, use the two lines below instead 27 | // SPI.setClockDivider(SPI_CLOCK_DIV128); //Slow down the master a bit 28 | // lcd.begin(SPI, csPin); 29 | 30 | //Clear the display 31 | lcd.clear(); 32 | 33 | //Print a message to the LCD. 34 | lcd.print("Hello, World!"); 35 | } 36 | 37 | void loop() { 38 | // set the cursor to column 0, line 1 39 | // (note: line 1 is the second row, since counting begins with 0): 40 | lcd.setCursor(0, 1); 41 | // print the number of seconds since reset: 42 | lcd.print(millis() / 1000); 43 | } 44 | 45 | -------------------------------------------------------------------------------- /tests/HelloWorld_OpenLCD_Serial/HelloWorld_OpenLCD_Serial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | QwiicSerLCD Library - Hello World 3 | 4 | Demonstrates the use of a Sparkfun AVR-Based Serial Enabled LCD 5 | display with a Qwiic adapter. 6 | 7 | This sketch prints "Hello World!" to the LCD 8 | and shows the time. 9 | 10 | The circuit: 11 | * Sparkfun RGB OpenLCD Serial display connected through 12 | * a Sparkfun Qwiic adpater to an Ardruino with a 13 | * Qwiic shield or a Sparkfun Blackboard with Qwiic built in. 14 | * 15 | * The Qwiic adapter should be attached to the display as follows: 16 | * 17 | * Display Qwiic Qwiic Cable Color 18 | * GND GND Black 19 | * RAW 3.3V Red 20 | * SDA SDA Blue 21 | * SCL SCL Yellow 22 | * 23 | * Note: If you connect directly to a 5V Arduino instead, you *MUST* use 24 | * a level-shifter to convert the i2c voltage levels down to 3.3V for the display. 25 | 26 | 27 | Based on the LiquidCrystal code originally by David A. Mellis 28 | and the OpenLCD code by Nathan Seidle at Sparkfun. 29 | 30 | modified 5 Jul 2009 31 | by Limor Fried (http://www.ladyada.net) 32 | example added 9 Jul 2009 33 | by Tom Igoe 34 | modified 22 Nov 2010 35 | by Tom Igoe 36 | modified 7 Nov 2016 37 | by Arturo Guadalupi 38 | modified 29 Aug 2018 39 | by Gaston Williams 40 | 41 | This example code is in the public domain. 42 | http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld 43 | 44 | More info on Qwiic here: 45 | 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 the Qwiic OpenLCD library code: 52 | #include 53 | #include 54 | 55 | SoftwareSerial mySerial(6, 7); //RX, TX 56 | 57 | // initialize the library 58 | QwiicSerLCD lcd; 59 | 60 | void setup() { 61 | mySerial.begin(9600); //Start communication with OpenLCD 62 | 63 | lcd.begin(mySerial); 64 | // Print a message to the LCD. 65 | lcd.print("Hello, World!"); 66 | } 67 | 68 | void loop() { 69 | // set the cursor to column 0, line 1 70 | // (note: line 1 is the second row, since counting begins with 0): 71 | lcd.setCursor(0, 1); 72 | // print the number of seconds since reset: 73 | lcd.print(millis() / 1000); 74 | } 75 | 76 | -------------------------------------------------------------------------------- /tests/OpenLCD_Lib_SPI_Test/OpenLCD_Lib_SPI_Test.ino: -------------------------------------------------------------------------------- 1 | /* 2 | OpenLCD is an LCD with Serial/I2C/SPI interfaces. 3 | By: Nathan Seidle 4 | SparkFun Electronics 5 | Date: April 19th, 2015 6 | License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 7 | 8 | This is example code that shows how to send data over SPI to the display. 9 | 10 | To get this code to work, attached an OpenLCD to an Arduino Uno using the following pins: 11 | CS (OpenLCD) to 10 (Arduino) 12 | SDI to 11 13 | SDO to 12 (optional) 14 | SCK to 13 15 | VIN to 5V 16 | GND to GND 17 | 18 | Command cheat sheet: 19 | ASCII / DEC / HEX 20 | '|' / 124 / 0x7C - Put into setting mode 21 | Ctrl+c / 3 / 0x03 - Change width to 20 22 | Ctrl+d / 4 / 0x04 - Change width to 16 23 | Ctrl+e / 5 / 0x05 - Change lines to 4 24 | Ctrl+f / 6 / 0x06 - Change lines to 2 25 | Ctrl+g / 7 / 0x07 - Change lines to 1 26 | Ctrl+h / 8 / 0x08 - Software reset of the system 27 | Ctrl+i / 9 / 0x09 - Enable/disable splash screen 28 | Ctrl+j / 10 / 0x0A - Save currently displayed text as splash 29 | Ctrl+k / 11 / 0x0B - Change baud to 2400bps 30 | Ctrl+l / 12 / 0x0C - Change baud to 4800bps 31 | Ctrl+m / 13 / 0x0D - Change baud to 9600bps 32 | Ctrl+n / 14 / 0x0E - Change baud to 14400bps 33 | Ctrl+o / 15 / 0x0F - Change baud to 19200bps 34 | Ctrl+p / 16 / 0x10 - Change baud to 38400bps 35 | Ctrl+q / 17 / 0x11 - Change baud to 57600bps 36 | Ctrl+r / 18 / 0x12 - Change baud to 115200bps 37 | Ctrl+s / 19 / 0x13 - Change baud to 230400bps 38 | Ctrl+t / 20 / 0x14 - Change baud to 460800bps 39 | Ctrl+u / 21 / 0x15 - Change baud to 921600bps 40 | Ctrl+v / 22 / 0x16 - Change baud to 1000000bps 41 | Ctrl+w / 23 / 0x17 - Change baud to 1200bps 42 | Ctrl+x / 24 / 0x18 - Change the contrast. Follow Ctrl+x with number 0 to 255. 120 is default. 43 | Ctrl+y / 25 / 0x19 - Change the TWI address. Follow Ctrl+x with number 0 to 255. 114 (0x72) is default. 44 | Ctrl+z / 26 / 0x1A - Enable/disable ignore RX pin on startup (ignore emergency reset) 45 | '-' / 45 / 0x2D - Clear display. Move cursor to home position. 46 | / 128-157 / 0x80-0x9D - Set the primary backlight brightness. 128 = Off, 157 = 100%. 47 | / 158-187 / 0x9E-0xBB - Set the green backlight brightness. 158 = Off, 187 = 100%. 48 | / 188-217 / 0xBC-0xD9 - Set the blue backlight brightness. 188 = Off, 217 = 100%. 49 | 50 | For example, to change the baud rate to 115200 send 124 followed by 18. 51 | */ 52 | // include the Qwiic OpenLCD library code: 53 | #include 54 | #include 55 | 56 | int csPin = 10; //You can use any output pin but for this example we use 10 57 | 58 | int cycles = 0; 59 | 60 | // initialize the library 61 | QwiicSerLCD lcd; 62 | void setup() 63 | { 64 | pinMode(csPin, OUTPUT); 65 | digitalWrite(csPin, HIGH); //By default, don't be selecting OpenLCD 66 | 67 | SPI.begin(); //Start SPI communication 68 | 69 | lcd.begin(SPI, csPin, SPISettings(100000, MSBFIRST, SPI_MODE0)); 70 | //For Arduino versions before 1.6, use the two lines below instead 71 | // SPI.setClockDivider(SPI_CLOCK_DIV128); //Slow down the master a bit 72 | // lcd.begin(SPI, csPin); 73 | } 74 | 75 | void loop() 76 | { 77 | cycles++; //Counting cycles! Yay! 78 | 79 | lcd.clear(); 80 | char tempString[50]; //Needs to be large enough to hold the entire string with up to 5 digits 81 | sprintf(tempString, "Cycles: %d", cycles); 82 | 83 | lcd.print(tempString); 84 | 85 | //25ms works well 86 | //15ms slight flickering 87 | //5ms causes flickering 88 | delay(250); 89 | } 90 | 91 | 92 | -------------------------------------------------------------------------------- /tests/OpenLCD_Lib_Serial_Test/OpenLCD_Lib_Serial_Test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SoftwareSerial mySerial(6, 7); //RX, TX 5 | 6 | byte counter = 0; 7 | byte contrast = 10; 8 | 9 | // initialize the library 10 | QwiicSerLCD lcd; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); //Start serial communication at 9600 for debug statements 15 | Serial.println("OpenLCD Example Code"); 16 | 17 | mySerial.begin(9600); //Start communication with OpenLCD 18 | 19 | lcd.begin(mySerial); 20 | //Send contrast setting 21 | // mySerial.write('|'); //Put LCD into setting mode 22 | // mySerial.write(24); //Send contrast command 23 | // mySerial.write(contrast); 24 | lcd.setContrast(contrast); 25 | 26 | 27 | } 28 | 29 | void loop() 30 | { 31 | //Send the clear command to the display - this returns the cursor to the beginning of the display 32 | // mySerial.write('|'); //Setting character 33 | // mySerial.write('-'); //Clear display 34 | lcd.clear(); 35 | 36 | //mySerial.print("Hello World! Counter: "); //For 16x2 LCD 37 | //mySerial.print("Hello World! Counter: "); //For 20x4 LCD 38 | lcd.print("Hello World! Counter: "); //For 20x4 LCD 39 | //mySerial.print(counter++); 40 | lcd.print(counter++); 41 | // mySerial.print(millis()/1000); 42 | delay(250); //Hang out for a bit 43 | } 44 | --------------------------------------------------------------------------------