├── .github
└── workflows
│ └── build-deploy-ghpages.yml
├── .gitmodules
├── DESCRIPTION.rst
├── LICENSE
├── README.md
├── docs
├── _static
│ └── favicon.ico
├── doxygen
│ ├── doxygen-config
│ └── doxygen-custom
│ │ ├── custom.css
│ │ └── header.html
├── images
│ ├── gh-banner-py-qwiic-serlcd.png
│ └── sfe_flame.png
└── requirements.txt
├── examples
├── README.md
├── ex10_qwiic_serlcd_turn_off_display.py
├── ex11_qwiic_serlcd_text_direction.py
├── ex12_qwiic_serlcd_console_input_to_display.py
├── ex13_qwiic_serlcd_fast_backlight.py
├── ex14_qwiic_serlcd_show_firmware_version.py
├── ex15_qwiic_serlcd_message_enable.py
├── ex16_qwiic_serlcd_set_splash.py
├── ex17_qwiic_serlcd_change_i2c_address.py
├── ex1_qwiic_serlcd_hello_world.py
├── ex2_qwiic_serlcd_backlight.py
├── ex3_qwiic_serlcd_set_cursor_position.py
├── ex4_qwiic_serlcd_move_cursor.py
├── ex5_qwiic_serlcd_enable_cursor.py
├── ex6_qwiic_serlcd_blink_cursor.py
├── ex7_qwiic_serlcd_scroll.py
├── ex8_qwiic_serlcd_autoscroll_with_text.py
└── ex9_qwiic_serlcd_custom_character.py
├── package.json
├── pyproject.toml
├── qwiic_serlcd.py
└── requirements.txt
/.github/workflows/build-deploy-ghpages.yml:
--------------------------------------------------------------------------------
1 | name: Build Documentation and Deploy
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | - documentation/doxygen
8 | workflow_dispatch:
9 |
10 | permissions:
11 | contents: read
12 | id-token: write
13 | pages: write
14 |
15 | concurrency:
16 | group: "pages"
17 | cancel-in-progress: true
18 |
19 | jobs:
20 | # Build job
21 | build:
22 | runs-on: ubuntu-latest
23 | steps:
24 | # Checkout the repository
25 | - name: Checkout repository
26 | uses: actions/checkout@v2
27 | with:
28 | fetch-depth: 0
29 | submodules: "true"
30 |
31 | - name: Set Version
32 | run: echo "PROJECT_NUMBER = `git describe --tags`" >> ./docs/doxygen/doxygen-config
33 |
34 | - name: Build Documentation
35 | uses: mattnotmitt/doxygen-action@v1.9.5
36 | with:
37 | doxyfile-path: "./docs/doxygen/doxygen-config"
38 |
39 | # Upload the documentation as an artifact
40 | - name: Upload documentation
41 | uses: actions/upload-pages-artifact@v3.0.1
42 | with:
43 | path: ./docs/html
44 |
45 | # Deploy job
46 | deploy:
47 | # Add a dependency to the build job
48 | needs: build
49 |
50 | # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
51 | permissions:
52 | pages: write # to deploy to Pages
53 | id-token: write # to verify the deployment originates from an appropriate source
54 |
55 | # Deploy to the github-pages environment
56 | environment:
57 | name: github-pages
58 | url: ${{ steps.deployment.outputs.page_url }}
59 |
60 | # Specify runner + deployment step
61 | runs-on: ubuntu-latest
62 | steps:
63 | - name: Deploy to GitHub Pages
64 | id: deployment
65 | uses: actions/deploy-pages@v4 # or specific "vX.X.X" version tag for this action
66 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "docs/doxygen/doxygen-awesome-css"]
2 | path = docs/doxygen/doxygen-awesome-css
3 | url = https://github.com/jothepro/doxygen-awesome-css.git
4 |
--------------------------------------------------------------------------------
/DESCRIPTION.rst:
--------------------------------------------------------------------------------
1 | Qwiic Dual Encoder Reader
2 | ==========================
3 |
4 | This package provides support to use three varieties of the SparkFun SerLCD screens: 16x2 SerLCD - RGB Backlight (QWIIC), 16x2 SerLCD - RGB Text (QWIIC), and 20x4 SerLCD - RGB Backlight (QWIIC).
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2020 SparkFun Electronics
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | # SparkFun Qwiic SerLCD - Python Package
4 |
5 | 
6 | 
7 | 
8 | 
9 | [](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html)
10 |
11 | The line of SparkFun Qwiic SerLCD products provide a simple and cost effective solution for adding a "text based" LCD display to your project. Implementing a SparkFun Qwiic interface, a SerLCD is rapidly added to any board that is part of the SparkFun Qwiic ecosystem.
12 |
13 | This repository implements a Python package for the SparkFun Qwiic SerLCD series of products. This package works with Python, MicroPython and CircuitPython.
14 |
15 | ### Contents
16 |
17 | * [About](#about-the-package)
18 | * [Getting Started](#getting-started)
19 | * [Installation](#installation)
20 | * [Supported Platforms](#supported-platforms)
21 | * [Documentation](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html)
22 | * [Examples](#examples)
23 |
24 | ## About the Package
25 |
26 | This python package enables the user to access all of the features of these LCD products via a single Qwiic cable. This includes writing text to the screen, adjusting backlight levels (color), customizing splash screen and much much more. They come pre-programmed with the fully open-sourced [OpenLCD firmware](https://github.com/sparkfun/OpenLCD). All of the capabilities of these LCD screens are each demonstrated in the included examples.
27 |
28 |
29 | New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic).
30 | ### Supported SparkFun Products
31 |
32 | This Python package supports the following SparkFun qwiic products on Python, MicroPython and Circuit python.
33 |
34 | * [SparkFun SerLCD 16x2 - RGB Backlight (QWIIC)](https://www.sparkfun.com/products/16396)
35 | * [SparkFun SerLCD 16x2 - RGB Text (QWIIC)](https://www.sparkfun.com/products/16397)
36 | * [SparkFun SerLCD 20x4 - RGB Backlight (QWIIC)](https://www.sparkfun.com/products/16398)
37 |
38 | ### Supported Platforms
39 |
40 | | Python | Platform | Boards |
41 | |--|--|--|
42 | | Python | Linux | [Raspberry Pi](https://www.sparkfun.com/raspberry-pi-5-8gb.html) , [NVIDIA Jetson Orin Nano](https://www.sparkfun.com/nvidia-jetson-orin-nano-developer-kit.html) via the [SparkFun Qwiic SHIM](https://www.sparkfun.com/sparkfun-qwiic-shim-for-raspberry-pi.html) |
43 | | MicroPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html)
44 | |CircuitPython | Raspberry Pi - RP2, ESP32 | [SparkFun RP2040 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2040.html), [SparkFun RP2350 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-rp2350.html), [SparkFun ESP32 Thing+](https://www.sparkfun.com/sparkfun-thing-plus-esp32-wroom-usb-c.html)
45 |
46 | > [!NOTE]
47 | > The listed supported platforms and boards are the primary platform targets tested. It is fully expected that this package will work across a wide variety of Python enabled systems.
48 |
49 | ## Installation
50 |
51 | The first step to using this package is installing it on your system. The install method depends on the python platform. The following sections outline installation on Python, MicroPython and CircuitPython.
52 |
53 | ### Python
54 |
55 | The package is primarily installed using the `pip3` command, downloading the package from the Python Index - "PyPi". Note - the below instructions outline installation an Linux-based (Raspberry Pi) system.
56 |
57 | #### PyPi Installation
58 |
59 | First, setup a virtual environment from a specific directory using venv:
60 | ```sh
61 | python3 -m venv path/to/venv
62 | ```
63 | You can pass any path as path/to/venv, just make sure you use the same one for all future steps. For more information on venv [click here](https://docs.python.org/3/library/venv.html).
64 |
65 | Next, install the qwiic package with:
66 | ```sh
67 | path/to/venv/bin/pip3 install sparkfun-qwiic-serlcd
68 | ```
69 | Now you should be able to run any example or custom python scripts that have `import qwiic_serlcd` by running e.g.:
70 | ```sh
71 | path/to/venv/bin/python3 example_script.py
72 | ```
73 |
74 | #### MicroPython Installation
75 | If not already installed, follow the [instructions here](https://docs.micropython.org/en/latest/reference/mpremote.html) to install mpremote on your computer.
76 |
77 | Connect a device with MicroPython installed to your computer and then install the package directly to your device with mpremote mip.
78 | ```sh
79 | mpremote mip install github:sparkfun/qwiic_serlcd_py
80 | ```
81 |
82 | If you would also like to install the examples for this repository, issue the following mip command as well:
83 | ```sh
84 | mprmeote mip install github:sparkfun/qwiic_serlcd_py@examples
85 | ```
86 |
87 | #### CircuitPython Installation
88 | If not already installed, follow the [instructions here](https://docs.circuitpython.org/projects/circup/en/latest/#installation) to install CircUp on your computer.
89 |
90 | Ensure that you have the latest version of the SparkFun Qwiic CircuitPython bundle.
91 | ```sh
92 | circup bundle-add sparkfun/Qwiic_Py
93 | ```
94 |
95 | Finally, connect a device with CircuitPython installed to your computer and then install the package directly to your device with circup.
96 | ```sh
97 | circup install --py qwiic_serlcd
98 | ```
99 |
100 | If you would like to install any of the examples from this repository, issue the corresponding circup command from below. (NOTE: The below syntax assumes you are using CircUP on Windows. Linux and Mac will have different path seperators (i.e. "/" vs. "\"). See the [CircUp "example" command documentation](https://learn.adafruit.com/keep-your-circuitpython-libraries-on-devices-up-to-date-with-circup/example-command) for more information)
101 | ```sh
102 | circup example qwiic_serlcd\ex1_qwiic_serlcd_hello_world
103 | circup example qwiic_serlcd\ex2_qwiic_serlcd_backlight
104 | circup example qwiic_serlcd\ex3_qwiic_serlcd_set_cursor_position
105 | circup example qwiic_serlcd\ex4_qwiic_serlcd_move_cursor
106 | circup example qwiic_serlcd\ex5_qwiic_serlcd_enable_cursor
107 | circup example qwiic_serlcd\ex6_qwiic_serlcd_blink_cursor
108 | circup example qwiic_serlcd\ex7_qwiic_serlcd_scroll
109 | circup example qwiic_serlcd\ex8_qwiic_serlcd_autoscroll_with_text
110 | circup example qwiic_serlcd\ex9_qwiic_serlcd_custom_character
111 | circup example qwiic_serlcd\ex10_qwiic_serlcd_turn_off_display
112 | circup example qwiic_serlcd\ex11_qwiic_serlcd_text_direction
113 | circup example qwiic_serlcd\ex12_qwiic_serlcd_console_input_to_display
114 | circup example qwiic_serlcd\ex13_qwiic_serlcd_fast_backlight
115 | circup example qwiic_serlcd\ex14_qwiic_serlcd_show_firmware_version
116 | circup example qwiic_serlcd\ex15_qwiic_serlcd_message_enable
117 | circup example qwiic_serlcd\ex16_qwiic_serlcd_set_splash
118 | circup example qwiic_serlcd\ex17_qwiic_serlcd_change_i2c_address.py
119 | ```
120 |
121 | ## Examples
122 | Below is a quickstart program to print "Hello World!" to the Serial LCD.
123 |
124 | See the examples directory for more detailed use examples and [examples/README.md](https://github.com/sparkfun/qwiic_serlcd_py/blob/main/examples/README.md) for a summary of the available examples.
125 |
126 | ```python
127 | from __future__ import print_function
128 | import qwiic_serlcd
129 | import time
130 | import sys
131 |
132 | def runExample():
133 |
134 | print("\nSparkFun Qwiic SerLCD Example 1\n")
135 | myLCD = qwiic_serlcd.QwiicSerlcd()
136 |
137 | if myLCD.connected == False:
138 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
139 | file=sys.stderr)
140 | return
141 |
142 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
143 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
144 | myLCD.clearScreen() # clear the screen - this moves the cursor to the home position as well
145 |
146 | time.sleep(1) # give a sec for system messages to complete
147 |
148 | myLCD.print("Hello World!")
149 | counter = 0
150 | while True:
151 | print("counter: %d" % counter)
152 | myLCD.setCursor(0,1)
153 | myLCD.print(str(counter))
154 | counter = counter + 1
155 | time.sleep(1)
156 |
157 | if __name__ == '__main__':
158 | try:
159 | runExample()
160 | except (KeyboardInterrupt, SystemExit) as exErr:
161 | print("\nEnding Example 1")
162 | sys.exit(0)
163 | ```
164 |
165 |
--------------------------------------------------------------------------------
/docs/_static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/qwiic_serlcd_py/5aa62c6e41cd775464abbc5bd87b635e9d05f4ed/docs/_static/favicon.ico
--------------------------------------------------------------------------------
/docs/doxygen/doxygen-custom/custom.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --side-nav-fixed-width: 300px;
3 | }
4 |
5 | .github-corner svg {
6 | fill: var(--primary-light-color);
7 | color: var(--page-background-color);
8 | width: 72px;
9 | height: 72px;
10 | }
11 |
12 | #projectnumber {
13 | margin-right: 22px;
14 | }
15 |
16 | @media screen and (max-width: 767px) {
17 | .github-corner svg {
18 | width: 55px;
19 | height: 55px;
20 | }
21 | }
--------------------------------------------------------------------------------
/docs/doxygen/doxygen-custom/header.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |  |
95 |
96 |
97 |
98 | $projectname
99 | $projectnumber
101 |
102 |
103 | $projectbrief
104 | |
105 |
106 |
107 |
108 |
109 | $projectbrief
110 | |
111 |
112 |
113 |
114 |
115 | $searchbox |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/docs/images/gh-banner-py-qwiic-serlcd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/qwiic_serlcd_py/5aa62c6e41cd775464abbc5bd87b635e9d05f4ed/docs/images/gh-banner-py-qwiic-serlcd.png
--------------------------------------------------------------------------------
/docs/images/sfe_flame.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/qwiic_serlcd_py/5aa62c6e41cd775464abbc5bd87b635e9d05f4ed/docs/images/sfe_flame.png
--------------------------------------------------------------------------------
/docs/requirements.txt:
--------------------------------------------------------------------------------
1 | m2r
2 | sparkfun-qwiic-i2c
3 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Sparkfun SerLCD Examples Reference
2 | Below is a brief summary of each of the example programs included in this repository. To report a bug in any of these examples or to request a new feature or example [file an issue in our GitHub issues.](https://github.com/sparkfun/qwiic_serlcd_py/issues)
3 |
4 | ## Example 1: Hello World
5 | This example demonstrates basic bringup of the LCD to print "Hello World!".
6 |
7 | It showcases the following methods:
8 |
9 | - [setBacklight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a81afb76ad0cc0b03b2def16c29ceaf06)
10 | - [setContrast()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a2dea2487f84df67519f61ff3004c7d12)
11 | - [clearScreen()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a35e73e1105f1db0be89372a5f4500714)
12 | - [print()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a30a4a9383c96b81763c6a32fa8b3f8dc)
13 | - [setCursor()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ab62f2dd063749b4418373f3320f2a38a)
14 |
15 |
16 | ## Example 2: Backlight
17 | This example shows how to change the color of the backlight by cycling through backlight colors and printing the name of the current backlight color to the display.
18 |
19 | The key method showcased by this example is [setBacklight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a81afb76ad0cc0b03b2def16c29ceaf06)
20 |
21 | ## Example 3: Set Cursor Position
22 | This example shows how to set the cursor to a specific column and row to print a character. It cycles through the lowercase letters of the alphabet (a-z) and prints each to a random row and column of the display.
23 |
24 | The key method showcased by this example is [setCursor()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ab62f2dd063749b4418373f3320f2a38a)
25 |
26 | ## Example 4: Move Cursor
27 | This example shows how to manually move the cursor left or right. It cycles between moving the cursor left three spaces and then moving it right three spaces.
28 |
29 | The key methods showcased by this example are [moveCursorLeft()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ac6dda0410878a153b193b05d4eeb62ee) and [moveCursorRight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a7d8891c7fb78d2e684c7cdf38556b813)
30 |
31 | ## Example 5: Enable Cursor
32 | This example shows how to turn the cursor on and off. It prints "Hello World!" to the LCD and then cycles between turning the cursor on for a second and off for a second.
33 |
34 | The key methods showcased by this example are [cursor()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ab11b11f6eaca0dd22e7c14b816e10bed) and [noCursor()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#abafa73de35582185e9db2c74f91df116)
35 |
36 | ## Example 6: Blink Cursor
37 | This example shows how to turn blinking of the cursor on and off. It prints "Hello World!" to the LCD and then cycles between turning the blinking on for 5 seconds and off for 5 seconds.
38 |
39 | The key methods showcased by this example are [blink()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a4c92d4fa2a89bbda03bcca43d82cd95a) and [noBlink()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#aae22aaee6f6d748c2921fc7b3008014b)
40 |
41 | ## Example 7: Scroll
42 | This example demonstrates the scrolling controls on the SerLCD. It prints "Hello World!" to the LCD and then cycles between scrolling it offscreen to the left, then offscreen to the right before finally centering it again.
43 |
44 | The key methods showcased by this example are [scrollDisplayLeft()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a5770a90358b2bad368e67aa23f8d0148) and [scrollDisplayRight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#abcb7784572d86a1ca3beec4b73481a6f)
45 |
46 | ## Example 8: Autoscroll Text
47 | This example demonstrates the autoscroll feature on the SerLCD. It cycles between printing the characters 0 to 9 and turning on and off autoscroll.
48 |
49 | The key methods showcased by this example are:
50 |
51 | - [leftToRight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a3a1c4c6cf831084a78f09fb535fb69fc)
52 | - [autoScroll()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a1ed67c384ab25e363e8129bc4d5c37e8)
53 | - [noAutoScroll()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#abbbd2c0c047d37f88209b6dd27a34359)
54 |
55 |
56 | ## Example 9: Custom Character
57 | This example demonstrates how to print custom characters to the LCD. It demonstrates printing a heart and a smiley face and then a little man waving his arms up and down.
58 |
59 | The key methods showcased by this example are [createChar()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#af75050abc733dd3ada34e79bd9a3b21b) and [writeChar()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a1b7e9f17fd0f061eef860416ce846783)
60 |
61 | ## Example 10: Turn off Display
62 | This example prints "Hello World!" to the LCD and turns on and off
63 | the display for a second each.
64 |
65 | The key methods showcased by this example are [display()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#acef2bfe9d6a0b2629150f0d18bf6849d) and [noDisplay()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ae5db2e051be1530b742aacef0b4ccd3f)
66 |
67 | ## Example 11: Text Direction
68 | This example demonstrates how to change where the next character will be printed. It walks through the alphabet and cycles between printing characters from right to left then left to right.
69 |
70 | The key methods showcased by this example are [rightToLeft()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#add5f1d9c4796f5f73d8944eb1e825575), [leftToRight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a3a1c4c6cf831084a78f09fb535fb69fc) and [home()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a26bb593af77460f92a2dc1791096c294).
71 |
72 | ## Example 12: Console Input to Display
73 | This example demonstrates printing arbitrary strings to the LCD. It takes user input from the Python repl until the user presses "enter" and then prints it to the LCD.
74 |
75 | The key method showcased by this example is [print()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a30a4a9383c96b81763c6a32fa8b3f8dc)
76 |
77 |
78 | ## Example 13: Fast Backlight
79 | This example shows how to set the backlight fast. It is advantageous because using this method doesn't show any system messages and sends the values in one concatenated block of data (a single command for all 3 values). It alternates between turning the backlight red for a second an then orange for a second.
80 |
81 | The key method showcased by this example is [setFastBacklight()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#afbc44537d3f324299f6a94433e338ef1)
82 |
83 | ## Example 14: Show Firmware Version
84 | This example shows how to get the devices firmware version. It repeatedly sends the command to display the firmware version.
85 |
86 | The key method showcased by this example is [command()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#aed9378ca8da9030c62fe29ac96513cf4)
87 |
88 | ## Example 15: Message Enable
89 | This example demonstrates how to turn off the system messages displayed when
90 | the user changes a setting. For instance 'Contrast: 5' or 'Backlight: 100%' is
91 | no longer displayed. It first sets the backlight and contrast while system messages are enabled, and then disables them and repeatedly changes the backlight color to demonstrate that the system messages are no longer printed.
92 |
93 | The key method showcased by this example is [disableSystemMessages()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a748362f1dfd4a4af65a19e1c07c6fbca)
94 |
95 | ## Example 16: Set Splash
96 | This example demonstrates how to create your own custom splash screen.
97 |
98 | This is done by first writing the text you want as your splash to the display,
99 | then 'saving' it as a splash screen.
100 |
101 | You can also disable or enable the displaying of the splash screen.
102 |
103 | Note - The disableSplash() and enableSplash() commands
104 | are only supported on SerLCD v1.2 and above. But you can still use the
105 | toggle splash command (Ctrl+i) to enable/disable the splash.
106 |
107 | The example sets the custom splash screen to "Tea-O-Matic".
108 |
109 | The key methods showcased by this example are [saveSplash()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#ae80dc2c1c37bd22f8aba75336ea9cedb) and [enableSplash()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a4783eaf3f021b51e0c8b877d64742063)
110 |
111 | ## Example 17: Change I2C Address
112 | This example demonstrates how to change the I2C address on your LCD.
113 |
114 | The key method showcased by this example is [setAddress()](https://docs.sparkfun.com/qwiic_serlcd_py/classqwiic__serlcd_1_1_qwiic_serlcd.html#a4783eaf3f021b51e0c8b877d64742063)
--------------------------------------------------------------------------------
/examples/ex10_qwiic_serlcd_turn_off_display.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex10_qwiic_serlcd_turn_off_display.py
4 | #
5 | # This example prints "Hello World!" to the LCD and uses the
6 | # display() and noDisplay() functions to turn on and off
7 | # the display.
8 | #
9 | #------------------------------------------------------------------------
10 | #
11 | # Written by SparkFun Electronics, August 2020
12 | #
13 | # Ported from Arduino Library code with many contributions from
14 | # Gaston Williams - August 29, 2018
15 | #
16 | # This python library supports the SparkFun Electroncis qwiic
17 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
18 | # board computers.
19 | #
20 | # More information on qwiic is at https://www.sparkfun.com/qwiic
21 | #
22 | # Do you like this library? Help support SparkFun. Buy a board!
23 | #
24 | #==================================================================================
25 | # Copyright (c) 2020 SparkFun Electronics
26 | #
27 | # Permission is hereby granted, free of charge, to any person obtaining a copy
28 | # of this software and associated documentation files (the "Software"), to deal
29 | # in the Software without restriction, including without limitation the rights
30 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31 | # copies of the Software, and to permit persons to whom the Software is
32 | # furnished to do so, subject to the following conditions:
33 | #
34 | # The above copyright notice and this permission notice shall be included in all
35 | # copies or substantial portions of the Software.
36 | #
37 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 | # SOFTWARE.
44 | #==================================================================================
45 | # Example 10
46 | #
47 |
48 | import qwiic_serlcd
49 | import time
50 | import sys
51 |
52 | def runExample():
53 |
54 | print("\nSparkFun Qwiic SerLCD Example 10\n")
55 | myLCD = qwiic_serlcd.QwiicSerlcd()
56 |
57 | if myLCD.connected == False:
58 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
59 | file=sys.stderr)
60 | return
61 |
62 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
63 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
64 | myLCD.begin() # call this for default settings (no
65 | myLCD.leftToRight()
66 | myLCD.noCursor()
67 | time.sleep(1) # give a sec for system messages to complete
68 |
69 | # Print a message to the LCD.
70 | myLCD.print("Hello World!")
71 |
72 | while True:
73 | myLCD.display() #turn on display
74 | time.sleep(1)
75 |
76 | myLCD.noDisplay() # turn off display
77 | time.sleep(1)
78 |
79 | if __name__ == '__main__':
80 | try:
81 | runExample()
82 | except (KeyboardInterrupt, SystemExit) as exErr:
83 | print("\nEnding Example 10")
84 | sys.exit(0)
85 |
86 |
87 |
--------------------------------------------------------------------------------
/examples/ex11_qwiic_serlcd_text_direction.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex11_qwiic_serlcd_text_direction.py
4 | #
5 | # This example demonstrates how to use leftToRight() and rightToLeft()
6 | # to change the where the next character will be printed.
7 | #
8 | #------------------------------------------------------------------------
9 | #
10 | # Written by SparkFun Electronics, August 2020
11 | #
12 | # Ported from Arduino Library code with many contributions from
13 | # Gaston Williams - August 29, 2018
14 | #
15 | # This python library supports the SparkFun Electroncis qwiic
16 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
17 | # board computers.
18 | #
19 | # More information on qwiic is at https://www.sparkfun.com/qwiic
20 | #
21 | # Do you like this library? Help support SparkFun. Buy a board!
22 | #
23 | #==================================================================================
24 | # Copyright (c) 2020 SparkFun Electronics
25 | #
26 | # Permission is hereby granted, free of charge, to any person obtaining a copy
27 | # of this software and associated documentation files (the "Software"), to deal
28 | # in the Software without restriction, including without limitation the rights
29 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 | # copies of the Software, and to permit persons to whom the Software is
31 | # furnished to do so, subject to the following conditions:
32 | #
33 | # The above copyright notice and this permission notice shall be included in all
34 | # copies or substantial portions of the Software.
35 | #
36 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42 | # SOFTWARE.
43 | #==================================================================================
44 | # Example 11
45 | #
46 |
47 | import qwiic_serlcd
48 | import time
49 | import sys
50 |
51 | def runExample():
52 |
53 | print("\nSparkFun Qwiic SerLCD Example 11\n")
54 | myLCD = qwiic_serlcd.QwiicSerlcd()
55 |
56 | if myLCD.connected == False:
57 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
58 | file=sys.stderr)
59 | return
60 |
61 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
62 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
63 | myLCD.begin() # call this for default settings (no
64 | myLCD.leftToRight()
65 | myLCD.cursor()
66 | time.sleep(1) # give a sec for system messages to complete
67 |
68 | thisChar = 'a'
69 |
70 | while True:
71 |
72 | if thisChar == 'j': # reverse directions at 'm'
73 | myLCD.rightToLeft() # go right for the next letter
74 |
75 | if thisChar == 'q': # reverse again at 's'
76 | myLCD.leftToRight() # go left for the next letter
77 | time.sleep(1)
78 |
79 | if thisChar > 'z': # reset at 'z'
80 | myLCD.home() # go to (0,0)
81 | myLCD.clearScreen() # clear screen
82 | thisChar = 'a' # start again at 0
83 |
84 | myLCD.print(thisChar) # print the character
85 | time.sleep(0.5) # wait a second
86 | thisChar = chr(ord(thisChar) + 1) # increment the letter
87 |
88 | if __name__ == '__main__':
89 | try:
90 | runExample()
91 | except (KeyboardInterrupt, SystemExit) as exErr:
92 | print("\nEnding Example 11")
93 | sys.exit(0)
94 |
95 |
96 |
--------------------------------------------------------------------------------
/examples/ex12_qwiic_serlcd_console_input_to_display.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex12_qwiic_serlcd_console_input_to_display.py
4 | #
5 | # This example demonstrates how to take text input from the python console
6 | # and send it to the LCD.
7 | #
8 | #------------------------------------------------------------------------
9 | #
10 | # Written by SparkFun Electronics, August 2020
11 | #
12 | # Ported from Arduino Library code with many contributions from
13 | # Gaston Williams - August 29, 2018
14 | #
15 | # This python library supports the SparkFun Electroncis qwiic
16 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
17 | # board computers.
18 | #
19 | # More information on qwiic is at https://www.sparkfun.com/qwiic
20 | #
21 | # Do you like this library? Help support SparkFun. Buy a board!
22 | #
23 | #==================================================================================
24 | # Copyright (c) 2020 SparkFun Electronics
25 | #
26 | # Permission is hereby granted, free of charge, to any person obtaining a copy
27 | # of this software and associated documentation files (the "Software"), to deal
28 | # in the Software without restriction, including without limitation the rights
29 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 | # copies of the Software, and to permit persons to whom the Software is
31 | # furnished to do so, subject to the following conditions:
32 | #
33 | # The above copyright notice and this permission notice shall be included in all
34 | # copies or substantial portions of the Software.
35 | #
36 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
42 | # SOFTWARE.
43 | #==================================================================================
44 | # Example 12
45 | #
46 |
47 | import qwiic_serlcd
48 | import time
49 | import sys
50 |
51 | def runExample():
52 |
53 | print("\nSparkFun Qwiic SerLCD Example 12\n")
54 | print("\nType CTRL+C to end.\n")
55 | myLCD = qwiic_serlcd.QwiicSerlcd()
56 |
57 | if myLCD.connected == False:
58 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
59 | file=sys.stderr)
60 | return
61 |
62 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
63 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
64 | myLCD.begin() # call this for default settings
65 | myLCD.leftToRight()
66 | myLCD.noCursor()
67 | time.sleep(1) # give a sec for system messages to complete
68 |
69 | while True:
70 |
71 | # promt the user to input some text
72 | user_input = input("Please type something to display on the LCD: ")
73 |
74 | myLCD.clearScreen() # clear the screen
75 |
76 | myLCD.print(user_input) # print what the user just typed in
77 |
78 | time.sleep(0.5) # wait a second
79 |
80 | if __name__ == '__main__':
81 | try:
82 | runExample()
83 | except (KeyboardInterrupt, SystemExit) as exErr:
84 | print("\nEnding Example 12")
85 | sys.exit(0)
86 |
87 |
88 |
--------------------------------------------------------------------------------
/examples/ex13_qwiic_serlcd_fast_backlight.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex13_qwiic_serlcd_fast_backlight.py
4 | #
5 | # This example shows how to use the fastBacklight() method.
6 | # It is nice because it doesn't show system messages, and sends the values
7 | # in one concatinated block of data (a single command for all 3 values).
8 | #
9 | #------------------------------------------------------------------------
10 | #
11 | # Written by SparkFun Electronics, August 2020
12 | #
13 | # Ported from Arduino Library code with many contributions from
14 | # Gaston Williams - August 29, 2018
15 | #
16 | # This python library supports the SparkFun Electroncis qwiic
17 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
18 | # board computers.
19 | #
20 | # More information on qwiic is at https://www.sparkfun.com/qwiic
21 | #
22 | # Do you like this library? Help support SparkFun. Buy a board!
23 | #
24 | #==================================================================================
25 | # Copyright (c) 2020 SparkFun Electronics
26 | #
27 | # Permission is hereby granted, free of charge, to any person obtaining a copy
28 | # of this software and associated documentation files (the "Software"), to deal
29 | # in the Software without restriction, including without limitation the rights
30 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31 | # copies of the Software, and to permit persons to whom the Software is
32 | # furnished to do so, subject to the following conditions:
33 | #
34 | # The above copyright notice and this permission notice shall be included in all
35 | # copies or substantial portions of the Software.
36 | #
37 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 | # SOFTWARE.
44 | #==================================================================================
45 | # Example 13
46 | #
47 |
48 | import qwiic_serlcd
49 | import time
50 | import sys
51 |
52 | def runExample():
53 |
54 | print("\nSparkFun Qwiic SerLCD Example 13\n")
55 | print("\nType CTRL+C to end.\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
64 | myLCD.begin() # call this for default settings (no
65 | myLCD.leftToRight()
66 | myLCD.noCursor()
67 | time.sleep(1) # give a sec for system messages to complete
68 |
69 | while True:
70 | myLCD.setFastBacklight(255, 0, 0) # bright red
71 | myLCD.clearScreen()
72 | myLCD.print("Red")
73 | time.sleep(1)
74 |
75 | myLCD.setFastBacklight(0xFF, 0x8C, 0x00) # orange
76 | myLCD.clearScreen()
77 | myLCD.print("Orange")
78 | time.sleep(1)
79 |
80 | if __name__ == '__main__':
81 | try:
82 | runExample()
83 | except (KeyboardInterrupt, SystemExit) as exErr:
84 | print("\nEnding Example 13")
85 | sys.exit(0)
86 |
87 |
88 |
--------------------------------------------------------------------------------
/examples/ex14_qwiic_serlcd_show_firmware_version.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex14_qwiic_serlcd_show_firmware_version.py
4 | #
5 | # This example prints the devices firmware version on the screen.
6 | #
7 | #------------------------------------------------------------------------
8 | #
9 | # Written by SparkFun Electronics, August 2020
10 | #
11 | # Ported from Arduino Library code with many contributions from
12 | # Gaston Williams - August 29, 2018
13 | #
14 | # This python library supports the SparkFun Electroncis qwiic
15 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
16 | # board computers.
17 | #
18 | # More information on qwiic is at https://www.sparkfun.com/qwiic
19 | #
20 | # Do you like this library? Help support SparkFun. Buy a board!
21 | #
22 | #==================================================================================
23 | # Copyright (c) 2020 SparkFun Electronics
24 | #
25 | # Permission is hereby granted, free of charge, to any person obtaining a copy
26 | # of this software and associated documentation files (the "Software"), to deal
27 | # in the Software without restriction, including without limitation the rights
28 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29 | # copies of the Software, and to permit persons to whom the Software is
30 | # furnished to do so, subject to the following conditions:
31 | #
32 | # The above copyright notice and this permission notice shall be included in all
33 | # copies or substantial portions of the Software.
34 | #
35 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41 | # SOFTWARE.
42 | #==================================================================================
43 | # Example 14
44 | #
45 |
46 | import qwiic_serlcd
47 | import time
48 | import sys
49 |
50 | def runExample():
51 |
52 | print("\nSparkFun Qwiic SerLCD Example 14\n")
53 | print("\nType CTRL+C to end.\n")
54 | myLCD = qwiic_serlcd.QwiicSerlcd()
55 |
56 | if myLCD.connected == False:
57 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
58 | file=sys.stderr)
59 | return
60 |
61 | myLCD.setBacklight(255, 255, 255) # bright white
62 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
63 | myLCD.begin() # call this for default settings (no
64 | myLCD.leftToRight()
65 | myLCD.noCursor()
66 | time.sleep(1) # give a sec for system messages to complete
67 |
68 | while True:
69 | myLCD.command(ord(',')) # send the comma to display the frimware version
70 | time.sleep(0.5) # Firmware will be displayed for 500ms, so keep re-printing it
71 |
72 | if __name__ == '__main__':
73 | try:
74 | runExample()
75 | except (KeyboardInterrupt, SystemExit) as exErr:
76 | print("\nEnding Example 14")
77 | sys.exit(0)
78 |
79 |
80 |
--------------------------------------------------------------------------------
/examples/ex15_qwiic_serlcd_message_enable.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex15_qwiic_serlcd_message_enable.py
4 | #
5 | # This example demonstrates how to turn off the system messages displayed when
6 | # the user changes a setting. For instance 'Contrast: 5' or 'Backlight: 100%' is
7 | # no longer displayed.
8 | #
9 | # Note - This example and the disableSystemMessages() and enableSystemMessages()
10 | # commands are only supported on SerLCD v1.2 and above.
11 | #
12 | #------------------------------------------------------------------------
13 | #
14 | # Written by SparkFun Electronics, August 2020
15 | #
16 | # Ported from Arduino Library code with many contributions from
17 | # Gaston Williams - August 29, 2018
18 | #
19 | # This python library supports the SparkFun Electroncis qwiic
20 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
21 | # board computers.
22 | #
23 | # More information on qwiic is at https://www.sparkfun.com/qwiic
24 | #
25 | # Do you like this library? Help support SparkFun. Buy a board!
26 | #
27 | #==================================================================================
28 | # Copyright (c) 2020 SparkFun Electronics
29 | #
30 | # Permission is hereby granted, free of charge, to any person obtaining a copy
31 | # of this software and associated documentation files (the "Software"), to deal
32 | # in the Software without restriction, including without limitation the rights
33 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34 | # copies of the Software, and to permit persons to whom the Software is
35 | # furnished to do so, subject to the following conditions:
36 | #
37 | # The above copyright notice and this permission notice shall be included in all
38 | # copies or substantial portions of the Software.
39 | #
40 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46 | # SOFTWARE.
47 | #==================================================================================
48 | # Example 15
49 | #
50 |
51 | import qwiic_serlcd
52 | import time
53 | import sys
54 |
55 | def runExample():
56 |
57 | print("\nSparkFun Qwiic SerLCD Example 15\n")
58 | print("\nType CTRL+C to end.\n")
59 | myLCD = qwiic_serlcd.QwiicSerlcd()
60 |
61 | if myLCD.connected == False:
62 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
63 | file=sys.stderr)
64 | return
65 |
66 | myLCD.setBacklight(255, 255, 255) # bright white
67 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
68 | myLCD.begin() # call this for default settings (no
69 | myLCD.leftToRight()
70 | myLCD.noCursor()
71 | time.sleep(1) # give a sec for system messages to complete
72 |
73 | myLCD.disableSystemMessages() # Now whenever you change a system setting like Contrast,
74 | # SerLCD will not display the setting. This makes changing the setting faster, and also
75 | # invisible to the user.
76 |
77 | #myLCD.enableSystemMessages() # This will re-enable the printing of system messages
78 |
79 | myLCD.clearScreen()
80 | myLCD.print("Hello World!")
81 |
82 | counter = 0
83 |
84 | while True:
85 | # do something that would normally cause a system message
86 | # let's change color of backlight values every other count value
87 | if (counter % 2) == 0:
88 | myLCD.setBacklight(255, 0, 0)
89 | else:
90 | myLCD.setBacklight(0, 255, 0)
91 |
92 | time.sleep(0.1) # give it a sec to change backlight
93 |
94 | print("counter: %d" % counter)
95 | myLCD.setCursor(0,1)
96 | myLCD.print(str(counter))
97 | counter = counter + 1
98 | time.sleep(1)
99 |
100 | if __name__ == '__main__':
101 | try:
102 | runExample()
103 | except (KeyboardInterrupt, SystemExit) as exErr:
104 | print("\nEnding Example 15")
105 | sys.exit(0)
106 |
107 |
108 |
--------------------------------------------------------------------------------
/examples/ex16_qwiic_serlcd_set_splash.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex16_qwiic_serlcd_set_splash.py
4 | #
5 | # This example 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 | #------------------------------------------------------------------------
17 | #
18 | # Written by SparkFun Electronics, August 2020
19 | #
20 | # Originally written for the Arduino Library by Nathan Seidle 2/16/2019
21 | #
22 | # Ported to this python example by Pete Lewis 8/18/2020
23 | #
24 | # Ported from Arduino Library code with many contributions from
25 | # Gaston Williams - August 29, 2018
26 | #
27 | # This python library supports the SparkFun Electroncis qwiic
28 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
29 | # board computers.
30 | #
31 | # More information on qwiic is at https://www.sparkfun.com/qwiic
32 | #
33 | # Do you like this library? Help support SparkFun. Buy a board!
34 | #
35 | #==================================================================================
36 | # Copyright (c) 2020 SparkFun Electronics
37 | #
38 | # Permission is hereby granted, free of charge, to any person obtaining a copy
39 | # of this software and associated documentation files (the "Software"), to deal
40 | # in the Software without restriction, including without limitation the rights
41 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
42 | # copies of the Software, and to permit persons to whom the Software is
43 | # furnished to do so, subject to the following conditions:
44 | #
45 | # The above copyright notice and this permission notice shall be included in all
46 | # copies or substantial portions of the Software.
47 | #
48 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
49 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
50 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
51 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
52 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
53 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54 | # SOFTWARE.
55 | #==================================================================================
56 | # Example 16
57 | #
58 |
59 | import qwiic_serlcd
60 | import time
61 | import sys
62 |
63 | def runExample():
64 |
65 | print("\nSparkFun Qwiic SerLCD Example 16\n")
66 | print("\nType CTRL+C to end.\n")
67 | myLCD = qwiic_serlcd.QwiicSerlcd()
68 |
69 | if myLCD.connected == False:
70 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
71 | file=sys.stderr)
72 | return
73 |
74 | myLCD.setBacklight(255, 255, 255) # bright white
75 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
76 | myLCD.begin() # call this for default settings (no
77 | myLCD.leftToRight()
78 | myLCD.noCursor()
79 | time.sleep(1) # give a sec for system messages to complete
80 |
81 | myLCD.clearScreen()
82 | myLCD.print("Tea-O-Matic")
83 | time.sleep(1)
84 |
85 | myLCD.saveSplash() # save this current text as the splash screen at next power up
86 |
87 | myLCD.enableSplash() # This will cause the splash to be displayed at power on
88 | #myLCD.disableSplash() # This will supress the splash from being displayed at power on
89 |
90 | counter = 0
91 |
92 | myLCD.clearScreen()
93 | myLCD.print("Cups of tea: ")
94 |
95 | while True:
96 | print("counter: %d" % counter)
97 | myLCD.setCursor(0,1)
98 | myLCD.print(str(counter))
99 | counter = counter + 1
100 | time.sleep(1)
101 |
102 | if __name__ == '__main__':
103 | try:
104 | runExample()
105 | except (KeyboardInterrupt, SystemExit) as exErr:
106 | print("\nEnding Example 16")
107 | sys.exit(0)
108 |
109 |
110 |
--------------------------------------------------------------------------------
/examples/ex17_qwiic_serlcd_change_i2c_address.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex17_qwiic_serlcd_change_i2c_address.py
4 | #
5 | # This example demonstrates how to change the i2c address on your LCD.
6 | # Note, once you change the address, then you will need to intatiate your class
7 | # using your new address.
8 | #
9 | # Once you have changed the address, you can try using the optional instantiation
10 | # line of code that is currently commented out.
11 | #
12 | # There is a set range of available addresses from 0x07 to 0x78, so make sure your
13 | # chosen address falls within this range.
14 | #
15 | # The next thing to note is that when you change the address you'll
16 | # need to call an instance of the QwiicSerlcd class that includes your new
17 | # address, like so: "myLCD = qwiic_serlcd.QwiicSerlcd(address=YOUR_NEW_ADDRESS_HERE)"
18 | # so that the new address is fed to all the available functions.
19 | #
20 | # Finally if for some reason you've forgotten your new address. No big deal, run a
21 | # hardware reset on your screen to get it back to the default address (0x72).
22 | # To cause a hardware reset, simply tie the RX pin LOW, and they cycle power
23 | # (while continuing to hold RX low). Then release RX, and cycle power again.
24 | #
25 | #------------------------------------------------------------------------
26 | #
27 | # Written by SparkFun Electronics, August 2020
28 | #
29 | # Ported from Arduino Library code with many contributions from
30 | # Gaston Williams - August 29, 2018
31 | #
32 | # Some code/comments/ideas ported from the Qwiic Quad Relay Arduino Library
33 | # Written by Elias Santistevan, July 2019
34 | #
35 | # This python library supports the SparkFun Electroncis qwiic
36 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
37 | # board computers.
38 | #
39 | # More information on qwiic is at https://www.sparkfun.com/qwiic
40 | #
41 | # Do you like this library? Help support SparkFun. Buy a board!
42 | #
43 | #==================================================================================
44 | # Copyright (c) 2020 SparkFun Electronics
45 | #
46 | # Permission is hereby granted, free of charge, to any person obtaining a copy
47 | # of this software and associated documentation files (the "Software"), to deal
48 | # in the Software without restriction, including without limitation the rights
49 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50 | # copies of the Software, and to permit persons to whom the Software is
51 | # furnished to do so, subject to the following conditions:
52 | #
53 | # The above copyright notice and this permission notice shall be included in all
54 | # copies or substantial portions of the Software.
55 | #
56 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
62 | # SOFTWARE.
63 | #==================================================================================
64 | # Example 17
65 | #
66 |
67 | import qwiic_serlcd
68 | import time
69 | import sys
70 |
71 | old_address = 0x72 # default
72 | new_address = 0x71 # must be within 0x07 to 0x78, DEFAULT: 0x72
73 |
74 | def runExample():
75 |
76 | print("\nSparkFun Qwiic SerLCD Example 17\n")
77 | print("\nType CTRL+C to end.\n")
78 | myLCD = qwiic_serlcd.QwiicSerlcd(address=old_address)
79 |
80 | print("Attemping to connect to %s..." % hex(myLCD.address))
81 |
82 | if myLCD.connected == False:
83 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
84 | file=sys.stderr)
85 | return
86 | else:
87 | print("Connected!")
88 | myLCD.setBacklight(255, 255, 255) # bright white
89 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
90 | myLCD.begin() # call this for default settings (no
91 | myLCD.leftToRight()
92 | myLCD.noCursor()
93 | time.sleep(1) # give a sec for system messages to complete
94 |
95 | myLCD.clearScreen()
96 |
97 | myLCD.setAddress(new_address) # note this updates class member myLCD.address to the new_address
98 |
99 | if myLCD.connected == True:
100 | print("Address changed to %s successfully!" % hex(myLCD.address))
101 | myLCD.clearScreen()
102 | myLCD.print("My new add: %s" % hex(myLCD.address))
103 | else:
104 | print("Address change failed :(")
105 | while True:
106 | time.sleep(1) # do nothing
107 |
108 | if __name__ == '__main__':
109 | try:
110 | runExample()
111 | except (KeyboardInterrupt, SystemExit) as exErr:
112 | print("\nEnding Example 17")
113 | sys.exit(0)
114 |
115 |
116 |
--------------------------------------------------------------------------------
/examples/ex1_qwiic_serlcd_hello_world.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex1_qwiic_serlcd_hello_world.py
4 | #
5 | # Simple Example demonstrating how to print "hello world" and a counting number to the SerLCD (Qwiic).
6 | #------------------------------------------------------------------------
7 | #
8 | # Written by SparkFun Electronics, August 2020
9 | #
10 | # Ported from Arduino Library code with many contributions from
11 | # Gaston Williams - August 29, 2018
12 | #
13 | # This python library supports the SparkFun Electroncis qwiic
14 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
15 | # board computers.
16 | #
17 | # More information on qwiic is at https://www.sparkfun.com/qwiic
18 | #
19 | # Do you like this library? Help support SparkFun. Buy a board!
20 | #
21 | #==================================================================================
22 | # Copyright (c) 2020 SparkFun Electronics
23 | #
24 | # Permission is hereby granted, free of charge, to any person obtaining a copy
25 | # of this software and associated documentation files (the "Software"), to deal
26 | # in the Software without restriction, including without limitation the rights
27 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28 | # copies of the Software, and to permit persons to whom the Software is
29 | # furnished to do so, subject to the following conditions:
30 | #
31 | # The above copyright notice and this permission notice shall be included in all
32 | # copies or substantial portions of the Software.
33 | #
34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 | # SOFTWARE.
41 | #==================================================================================
42 | # Example 1
43 | #
44 |
45 | import qwiic_serlcd
46 | import time
47 | import sys
48 |
49 | def runExample():
50 |
51 | print("\nSparkFun Qwiic SerLCD Example 1\n")
52 | myLCD = qwiic_serlcd.QwiicSerlcd()
53 |
54 | if myLCD.connected == False:
55 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
56 | file=sys.stderr)
57 | return
58 |
59 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
60 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
61 | myLCD.clearScreen() # clear the screen - this moves the cursor to the home position as well
62 |
63 | time.sleep(1) # give a sec for system messages to complete
64 |
65 | myLCD.print("Hello World!")
66 | counter = 0
67 | while True:
68 | print("counter: %d" % counter)
69 | myLCD.setCursor(0,1)
70 | myLCD.print(str(counter))
71 | counter = counter + 1
72 | time.sleep(1)
73 |
74 | if __name__ == '__main__':
75 | try:
76 | runExample()
77 | except (KeyboardInterrupt, SystemExit) as exErr:
78 | print("\nEnding Example 1")
79 | sys.exit(0)
80 |
81 |
82 |
--------------------------------------------------------------------------------
/examples/ex2_qwiic_serlcd_backlight.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex2_qwiic_serlcd_backlight.py
4 | #
5 | # Simple Example demonstrating various backlight controls on the SerLCD (Qwiic).
6 | #
7 | # This sketch changes the backlight color and displays text using
8 | # the OpenLCD functions. This works with the original version of
9 | # SerLCD. See FastBacklight example for version 1.1 and later.
10 | #------------------------------------------------------------------------
11 | #
12 | # Written by SparkFun Electronics, August 2020
13 | #
14 | # Ported from Arduino Library code with many contributions from
15 | # Gaston Williams - August 29, 2018
16 | #
17 | # This python library supports the SparkFun Electroncis qwiic
18 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19 | # board computers.
20 | #
21 | # More information on qwiic is at https://www.sparkfun.com/qwiic
22 | #
23 | # Do you like this library? Help support SparkFun. Buy a board!
24 | #
25 | #==================================================================================
26 | # Copyright (c) 2020 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | # Example 2
47 | #
48 |
49 | import qwiic_serlcd
50 | import time
51 | import sys
52 |
53 | def runExample():
54 |
55 | print("\nSparkFun Qwiic SerLCD Example 2\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
64 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
65 |
66 | time.sleep(1) # give a sec for system messages to complete
67 |
68 | while True:
69 | myLCD.setBacklight(0, 0, 0) # black is off
70 | myLCD.clearScreen() # Clear the display - this moves the cursor to home position as well
71 | myLCD.print("Black (off)")
72 | time.sleep(5)
73 |
74 | myLCD.setBacklight(255, 0, 0) # bright red
75 | myLCD.clearScreen()
76 | myLCD.print("Red")
77 | time.sleep(5)
78 |
79 | myLCD.setBacklight(0xFF, 0x8C, 0x00) # orange
80 | myLCD.clearScreen()
81 | myLCD.print("Orange")
82 | time.sleep(5)
83 |
84 | myLCD.setBacklight(255, 255, 0) # bright yellow
85 | myLCD.clearScreen()
86 | myLCD.print("Yellow")
87 | time.sleep(5)
88 |
89 | myLCD.setBacklight(0, 255, 0) # bright green
90 | myLCD.clearScreen()
91 | myLCD.print("Green")
92 | time.sleep(5)
93 |
94 | myLCD.setBacklight(0, 0, 255) # bright blue
95 | myLCD.clearScreen()
96 | myLCD.print("Blue")
97 | time.sleep(5)
98 |
99 | myLCD.setBacklight(0x4B, 0x00, 0x82) # indigo, a kind of dark purplish blue
100 | myLCD.clearScreen()
101 | myLCD.print("Indigo")
102 | time.sleep(5)
103 |
104 | myLCD.setBacklight(0xA0, 0x20, 0xF0) # violet
105 | myLCD.clearScreen()
106 | myLCD.print("Violet")
107 | time.sleep(5)
108 |
109 | myLCD.setBacklight(0x80, 0x80, 0x80) # grey
110 | myLCD.clearScreen()
111 | myLCD.print("Grey")
112 | time.sleep(5)
113 |
114 | myLCD.setBacklight(255, 255, 255) # bright white
115 | myLCD.clearScreen()
116 | myLCD.print("White")
117 | time.sleep(5)
118 |
119 | if __name__ == '__main__':
120 | try:
121 | runExample()
122 | except (KeyboardInterrupt, SystemExit) as exErr:
123 | print("\nEnding Example 2")
124 | sys.exit(0)
125 |
126 |
127 |
--------------------------------------------------------------------------------
/examples/ex3_qwiic_serlcd_set_cursor_position.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex3_qwiic_serlcd_set_cursor_position.py
4 | #
5 | # Simple Example demonstrating cursor posistion controls on the SerLCD (Qwiic).
6 | #
7 | # This sketch randomly picks a cursor position, goes to
8 | # that position using the setCursor() method, and prints a character
9 | #------------------------------------------------------------------------
10 | #
11 | # Written by SparkFun Electronics, August 2020
12 | #
13 | # Ported from Arduino Library code with many contributions from
14 | # Gaston Williams - August 29, 2018
15 | #
16 | # This python library supports the SparkFun Electroncis qwiic
17 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
18 | # board computers.
19 | #
20 | # More information on qwiic is at https://www.sparkfun.com/qwiic
21 | #
22 | # Do you like this library? Help support SparkFun. Buy a board!
23 | #
24 | #==================================================================================
25 | # Copyright (c) 2020 SparkFun Electronics
26 | #
27 | # Permission is hereby granted, free of charge, to any person obtaining a copy
28 | # of this software and associated documentation files (the "Software"), to deal
29 | # in the Software without restriction, including without limitation the rights
30 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31 | # copies of the Software, and to permit persons to whom the Software is
32 | # furnished to do so, subject to the following conditions:
33 | #
34 | # The above copyright notice and this permission notice shall be included in all
35 | # copies or substantial portions of the Software.
36 | #
37 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 | # SOFTWARE.
44 | #==================================================================================
45 | # Example 3
46 | #
47 |
48 | import qwiic_serlcd
49 | import time
50 | import sys
51 | import random
52 |
53 |
54 | def runExample():
55 |
56 | print("\nSparkFun Qwiic SerLCD Example 3\n")
57 | myLCD = qwiic_serlcd.QwiicSerlcd()
58 |
59 | if myLCD.connected == False:
60 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
61 | file=sys.stderr)
62 | return
63 |
64 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
65 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
66 | myLCD.clearScreen()
67 |
68 | time.sleep(1) # give a sec for system messages to complete
69 |
70 | # These constants won't change. But you can change the size of
71 | # your LCD using them:
72 | numRows = 2
73 | # numRows = 4
74 | numCols = 16
75 | # numCols = 20
76 |
77 | thisLetter = "a"
78 |
79 | while True:
80 | randomColumn = random.randint(0, numCols)
81 | randomRow = random.randint(0, numRows)
82 |
83 | # set the cursor position:
84 | myLCD.setCursor(randomColumn, randomRow)
85 |
86 | # print the letter:
87 | myLCD.print(thisLetter) # print to screen
88 | time.sleep(0.2)
89 |
90 | thisLetter = chr(ord(thisLetter) + 1)
91 | if thisLetter > "z":
92 | thisLetter = "a" # Wrap the variable
93 |
94 | if __name__ == '__main__':
95 | try:
96 | runExample()
97 | except (KeyboardInterrupt, SystemExit) as exErr:
98 | print("\nEnding Example 3")
99 | sys.exit(0)
100 |
101 |
102 |
--------------------------------------------------------------------------------
/examples/ex4_qwiic_serlcd_move_cursor.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex4_qwiic_serlcd_move_cursor.py
4 | #
5 | # Simple Example demonstrating the move cursor controls on the SerLCD (Qwiic).
6 | #
7 | # This example displays text and then moves the cursor back and forth. These
8 | # functions are not usually part of the LiquidCrystal library, but these functions
9 | # are available in the Serial OpenLCD display.
10 | #------------------------------------------------------------------------
11 | #
12 | # Written by SparkFun Electronics, August 2020
13 | #
14 | # Ported from Arduino Library code with many contributions from
15 | # Gaston Williams - August 29, 2018
16 | #
17 | # This python library supports the SparkFun Electroncis qwiic
18 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19 | # board computers.
20 | #
21 | # More information on qwiic is at https://www.sparkfun.com/qwiic
22 | #
23 | # Do you like this library? Help support SparkFun. Buy a board!
24 | #
25 | #==================================================================================
26 | # Copyright (c) 2020 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | # Example 4
47 | #
48 |
49 | import qwiic_serlcd
50 | import time
51 | import sys
52 |
53 | def runExample():
54 |
55 | print("\nSparkFun Qwiic SerLCD Example 4\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
64 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
65 | myLCD.clearScreen()
66 | myLCD.cursor() # Turn on the underline cursor
67 |
68 | time.sleep(1) # give a sec for system messages to complete
69 | myLCD.print("Watch the cursor!")
70 |
71 | while True:
72 | # move cursor left with three function calls
73 | myLCD.moveCursorLeft()
74 | time.sleep(0.5)
75 | myLCD.moveCursorLeft()
76 | time.sleep(0.5)
77 | myLCD.moveCursorLeft()
78 | time.sleep(0.5)
79 |
80 | # move curor right three spaces in one function call
81 | myLCD.moveCursorRight(3) # notice the optional count argument of "3"
82 | time.sleep(0.5)
83 |
84 | # move cursor left three spaces in one function call
85 | myLCD.moveCursorLeft(3)
86 | time.sleep(0.5)
87 |
88 | # move cursor right with three function calls
89 | myLCD.moveCursorRight()
90 | time.sleep(0.5)
91 | myLCD.moveCursorRight()
92 | time.sleep(0.5)
93 | myLCD.moveCursorRight()
94 | time.sleep(0.5)
95 |
96 | if __name__ == '__main__':
97 | try:
98 | runExample()
99 | except (KeyboardInterrupt, SystemExit) as exErr:
100 | print("\nEnding Example 4")
101 | sys.exit(0)
102 |
103 |
104 |
--------------------------------------------------------------------------------
/examples/ex5_qwiic_serlcd_enable_cursor.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex5_qwiic_serlcd_enable_cursor.py
4 | #
5 | # Simple Example demonstrating the enable and disable cursor controls on the SerLCD (Qwiic).
6 | #
7 | # This example prints "Hello World!" to the LCD and
8 | # uses the cursor() and noCursor() methods to turn
9 | # on and off the cursor.
10 | #------------------------------------------------------------------------
11 | #
12 | # Written by SparkFun Electronics, August 2020
13 | #
14 | # Ported from Arduino Library code with many contributions from
15 | # Gaston Williams - August 29, 2018
16 | #
17 | # This python library supports the SparkFun Electroncis qwiic
18 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19 | # board computers.
20 | #
21 | # More information on qwiic is at https://www.sparkfun.com/qwiic
22 | #
23 | # Do you like this library? Help support SparkFun. Buy a board!
24 | #
25 | #==================================================================================
26 | # Copyright (c) 2020 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | # Example 5
47 | #
48 |
49 | import qwiic_serlcd
50 | import time
51 | import sys
52 |
53 | def runExample():
54 |
55 | print("\nSparkFun Qwiic SerLCD Example 5\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
64 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
65 | myLCD.clearScreen()
66 | myLCD.cursor() # Turn on the underline cursor
67 |
68 | time.sleep(1) # give a sec for system messages to complete
69 | myLCD.print("Hello World!")
70 |
71 | while True:
72 | # turn off the cursor
73 | print("Cursor OFF")
74 | myLCD.noCursor()
75 | time.sleep(1)
76 |
77 | # turn on the cursor
78 | print("Cursor ON")
79 |
80 | myLCD.cursor()
81 | time.sleep(1)
82 |
83 | if __name__ == '__main__':
84 | try:
85 | runExample()
86 | except (KeyboardInterrupt, SystemExit) as exErr:
87 | print("\nEnding Example 5")
88 | sys.exit(0)
89 |
90 |
91 |
--------------------------------------------------------------------------------
/examples/ex6_qwiic_serlcd_blink_cursor.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex6_qwiic_serlcd_blink_cursor.py
4 | #
5 | # Simple example demonstrating the blinking cursor controls on the SerLCD (Qwiic).
6 | #
7 | # This example prints "Hello World!" to the LCD and
8 | # uses the blink() and noBlink() methods to turn
9 | # on and off the blinking.
10 | #------------------------------------------------------------------------
11 | #
12 | # Written by SparkFun Electronics, August 2020
13 | #
14 | # Ported from Arduino Library code with many contributions from
15 | # Gaston Williams - August 29, 2018
16 | #
17 | # This python library supports the SparkFun Electroncis qwiic
18 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19 | # board computers.
20 | #
21 | # More information on qwiic is at https://www.sparkfun.com/qwiic
22 | #
23 | # Do you like this library? Help support SparkFun. Buy a board!
24 | #
25 | #==================================================================================
26 | # Copyright (c) 2020 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | # Example 6
47 | #
48 |
49 | import qwiic_serlcd
50 | import time
51 | import sys
52 |
53 | def runExample():
54 |
55 | print("\nSparkFun Qwiic SerLCD Example 6\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
64 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
65 | myLCD.clearScreen()
66 | myLCD.cursor() # Turn on the underline cursor
67 |
68 | time.sleep(1) # give a sec for system messages to complete
69 | myLCD.print("Hello World!")
70 |
71 | while True:
72 | # turn off the blinking cursor
73 | print("Cursor blinking OFF")
74 | myLCD.noBlink()
75 | time.sleep(5)
76 |
77 | # turn on the blinking cursor
78 | print("Cursor blinking ON")
79 | myLCD.blink()
80 | time.sleep(5)
81 |
82 | if __name__ == '__main__':
83 | try:
84 | runExample()
85 | except (KeyboardInterrupt, SystemExit) as exErr:
86 | print("\nEnding Example 6")
87 | sys.exit(0)
88 |
89 |
90 |
--------------------------------------------------------------------------------
/examples/ex7_qwiic_serlcd_scroll.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex7_qwiic_serlcd_scroll.py
4 | #
5 | # Simple example demonstrating the scroll controls on the SerLCD (Qwiic).
6 | #
7 | # This example prints "Hello World!" to the LCD and uses the
8 | # scrollDisplayLeft() and scrollDisplayRight() methods to scroll
9 | # the text.
10 | #------------------------------------------------------------------------
11 | #
12 | # Written by SparkFun Electronics, August 2020
13 | #
14 | # Ported from Arduino Library code with many contributions from
15 | # Gaston Williams - August 29, 2018
16 | #
17 | # This python library supports the SparkFun Electroncis qwiic
18 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
19 | # board computers.
20 | #
21 | # More information on qwiic is at https://www.sparkfun.com/qwiic
22 | #
23 | # Do you like this library? Help support SparkFun. Buy a board!
24 | #
25 | #==================================================================================
26 | # Copyright (c) 2020 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | # Example 7
47 | #
48 |
49 | import qwiic_serlcd
50 | import time
51 | import sys
52 |
53 | def runExample():
54 |
55 | print("\nSparkFun Qwiic SerLCD Example 7\n")
56 | myLCD = qwiic_serlcd.QwiicSerlcd()
57 |
58 | if myLCD.connected == False:
59 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
60 | file=sys.stderr)
61 | return
62 |
63 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
64 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
65 | myLCD.clearScreen()
66 |
67 | time.sleep(1) # give a sec for system messages to complete
68 | myLCD.print("Hello World!")
69 |
70 | while True:
71 | # scroll 13 positions (string length) to the left
72 | # to move it offscreen left:
73 | for i in range(13):
74 | myLCD.scrollDisplayLeft() # scroll one position left
75 | time.sleep(0.15) # wait a bit
76 |
77 | # scroll 29 positions (string length + display length) to the right
78 | # to move it offscreen right:
79 | for i in range(29):
80 | myLCD.scrollDisplayRight() # scroll one position right
81 | time.sleep(0.15) # wait a bit
82 |
83 | # scroll 16 positions (display length + string length) to the left
84 | # to move it back to center:
85 | for i in range(16):
86 | myLCD.scrollDisplayLeft() # scroll one position left
87 | time.sleep(0.15) # wait a bit
88 |
89 | time.sleep(1) # delay at the end of the full loop
90 |
91 | if __name__ == '__main__':
92 | try:
93 | runExample()
94 | except (KeyboardInterrupt, SystemExit) as exErr:
95 | print("\nEnding Example 7")
96 | sys.exit(0)
97 |
98 |
99 |
--------------------------------------------------------------------------------
/examples/ex8_qwiic_serlcd_autoscroll_with_text.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex8_qwiic_serlcd_autoscroll_with_text.py
4 | #
5 | # Simple example demonstrating the autoscroll feature on the SerLCD (Qwiic).
6 | #
7 | # This example demonstrates the use of the autoscroll()
8 | # and noAutoscroll() functions to make new text scroll or not.
9 | #------------------------------------------------------------------------
10 | #
11 | # Written by SparkFun Electronics, August 2020
12 | #
13 | # Ported from Arduino Library code with many contributions from
14 | # Gaston Williams - August 29, 2018
15 | #
16 | # This python library supports the SparkFun Electroncis qwiic
17 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
18 | # board computers.
19 | #
20 | # More information on qwiic is at https://www.sparkfun.com/qwiic
21 | #
22 | # Do you like this library? Help support SparkFun. Buy a board!
23 | #
24 | #==================================================================================
25 | # Copyright (c) 2020 SparkFun Electronics
26 | #
27 | # Permission is hereby granted, free of charge, to any person obtaining a copy
28 | # of this software and associated documentation files (the "Software"), to deal
29 | # in the Software without restriction, including without limitation the rights
30 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31 | # copies of the Software, and to permit persons to whom the Software is
32 | # furnished to do so, subject to the following conditions:
33 | #
34 | # The above copyright notice and this permission notice shall be included in all
35 | # copies or substantial portions of the Software.
36 | #
37 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 | # SOFTWARE.
44 | #==================================================================================
45 | # Example 8
46 | #
47 |
48 | import qwiic_serlcd
49 | import time
50 | import sys
51 |
52 | def runExample():
53 |
54 | print("\nSparkFun Qwiic SerLCD Example 8\n")
55 | myLCD = qwiic_serlcd.QwiicSerlcd()
56 |
57 | if myLCD.connected == False:
58 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
59 | file=sys.stderr)
60 | return
61 |
62 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
63 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
64 | myLCD.begin() # call this for default settings (no
65 | myLCD.leftToRight()
66 | time.sleep(1) # give a sec for system messages to complete
67 |
68 | while True:
69 | myLCD.setCursor(0, 0) # set the cursor to (0,0)
70 |
71 | for thisChar in range(10): # print from 0 to 9
72 | myLCD.print(str(thisChar))
73 | time.sleep(0.5)
74 |
75 | myLCD.autoscroll() # set the display to automatically scroll
76 |
77 | for thisChar in range(0,10): # print from 0 to 9
78 | myLCD.setCursor(10+thisChar,1)
79 | myLCD.print(str(thisChar))
80 | time.sleep(0.5)
81 |
82 | myLCD.noAutoscroll() # turn off automatic scrolling
83 | myLCD.clearScreen() # clear screen for the next loop
84 |
85 | if __name__ == '__main__':
86 | try:
87 | runExample()
88 | except (KeyboardInterrupt, SystemExit) as exErr:
89 | print("\nEnding Example 8")
90 | sys.exit(0)
91 |
92 |
93 |
--------------------------------------------------------------------------------
/examples/ex9_qwiic_serlcd_custom_character.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #-----------------------------------------------------------------------------
3 | # ex9_qwiic_serlcd_custom_character.py
4 | #
5 | # This example prints "I
SerLCD!" and a little dancing man
6 | # to the LCD.
7 | #
8 | # Custom characters are recorded to SerLCD and are remembered even after power is lost.
9 | # There is a maximum of 8 custom characters that can be recorded.
10 | #
11 | #------------------------------------------------------------------------
12 | #
13 | # Written by SparkFun Electronics, August 2020
14 | #
15 | # Ported from Arduino Library code with many contributions from
16 | # Gaston Williams - August 29, 2018
17 | #
18 | # Based on Adafruit's example at
19 | #
20 | # https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
21 | #
22 | # This example code is in the public domain.
23 | # http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter
24 | #
25 | # Also useful:
26 | # http://icontexto.com/charactercreator/
27 | #
28 | # This python library supports the SparkFun Electroncis qwiic
29 | # qwiic sensor/board ecosystem on a Raspberry Pi (and compatable) single
30 | # board computers.
31 | #
32 | # More information on qwiic is at https://www.sparkfun.com/qwiic
33 | #
34 | # Do you like this library? Help support SparkFun. Buy a board!
35 | #
36 | #==================================================================================
37 | # Copyright (c) 2020 SparkFun Electronics
38 | #
39 | # Permission is hereby granted, free of charge, to any person obtaining a copy
40 | # of this software and associated documentation files (the "Software"), to deal
41 | # in the Software without restriction, including without limitation the rights
42 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43 | # copies of the Software, and to permit persons to whom the Software is
44 | # furnished to do so, subject to the following conditions:
45 | #
46 | # The above copyright notice and this permission notice shall be included in all
47 | # copies or substantial portions of the Software.
48 | #
49 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55 | # SOFTWARE.
56 | #==================================================================================
57 | # Example 9
58 | #
59 |
60 | import qwiic_serlcd
61 | import time
62 | import sys
63 |
64 | def runExample():
65 |
66 | print("\nSparkFun Qwiic SerLCD Example 9\n")
67 | myLCD = qwiic_serlcd.QwiicSerlcd()
68 |
69 | if myLCD.connected == False:
70 | print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \
71 | file=sys.stderr)
72 | return
73 |
74 | myLCD.setBacklight(255, 255, 255) # Set backlight to bright white
75 | myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast.
76 | myLCD.begin() # call this for default settings (no
77 | myLCD.leftToRight()
78 | time.sleep(1) # give a sec for system messages to complete
79 |
80 | # make some custom characters:
81 | heart = [
82 | 0b00000,
83 | 0b01010,
84 | 0b11111,
85 | 0b11111,
86 | 0b11111,
87 | 0b01110,
88 | 0b00100,
89 | 0b00000]
90 |
91 | smiley = [
92 | 0b00000,
93 | 0b00000,
94 | 0b01010,
95 | 0b00000,
96 | 0b00000,
97 | 0b10001,
98 | 0b01110,
99 | 0b00000]
100 |
101 | frownie = [
102 | 0b00000,
103 | 0b00000,
104 | 0b01010,
105 | 0b00000,
106 | 0b00000,
107 | 0b00000,
108 | 0b01110,
109 | 0b10001]
110 |
111 | armsDown = [
112 | 0b00100,
113 | 0b01010,
114 | 0b00100,
115 | 0b00100,
116 | 0b01110,
117 | 0b10101,
118 | 0b00100,
119 | 0b01010]
120 |
121 | armsUp = [
122 | 0b00100,
123 | 0b01010,
124 | 0b00100,
125 | 0b10101,
126 | 0b01110,
127 | 0b00100,
128 | 0b00100,
129 | 0b01010]
130 |
131 | myLCD.createChar(0, heart)
132 | myLCD.createChar(1, smiley)
133 | myLCD.createChar(2, frownie)
134 | myLCD.createChar(3, armsDown)
135 | myLCD.createChar(4, armsUp)
136 |
137 | myLCD.setCursor(0,0) # set cursor to the top left
138 |
139 | # Print a message to the LCD.
140 | myLCD.print("I ")
141 | myLCD.writeChar(0) # Print the heart character, stored in location 0
142 | myLCD.print(" SerLCD! ")
143 | myLCD.writeChar(1) # Print smiley
144 |
145 | while True:
146 |
147 | myLCD.setCursor(4,1) # column, row
148 | myLCD.writeChar(3) # print little man, arms down
149 | time.sleep(0.2)
150 |
151 | myLCD.setCursor(4,1) # column, row
152 | myLCD.writeChar(4) # print little man, arms up
153 | time.sleep(0.2)
154 |
155 | if __name__ == '__main__':
156 | try:
157 | runExample()
158 | except (KeyboardInterrupt, SystemExit) as exErr:
159 | print("\nEnding Example 9")
160 | sys.exit(0)
161 |
162 |
163 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "urls": [
3 | ["qwiic_serlcd.py", "github:sparkfun/Qwiic_SerLCD_Py/qwiic_serlcd.py"]
4 | ],
5 | "deps": [
6 | ["github:sparkfun/Qwiic_I2C_Py", "master"]
7 | ],
8 | "version": "2.0.0"
9 | }
10 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools"]
3 |
4 | [project]
5 | name = "sparkfun_qwiic_serlcd"
6 | version = "2.0.0"
7 | description = "SparkFun Electronics Qwiic SerLCD"
8 | readme = "DESCRIPTION.rst"
9 |
10 | authors = [{name="Sparkfun Electronics", email="info@sparkfun.com"}]
11 | dependencies = ["sparkfun_qwiic_i2c"]
12 |
13 | classifiers=[
14 | # How mature is this project? Common values are
15 | # 3 - Alpha
16 | # 4 - Beta
17 | # 5 - Production/Stable
18 | "Development Status :: 5 - Production/Stable",
19 |
20 | # Indicate who your project is intended for
21 | "Intended Audience :: Developers",
22 | "Topic :: Software Development :: Build Tools",
23 |
24 | # Pick your license as you wish (should match "license" above)
25 | "License :: OSI Approved :: MIT License",
26 |
27 | # Specify the Python versions you support here. In particular, ensure
28 | # that you indicate whether you support Python 2, Python 3 or both.
29 | "Programming Language :: Python :: 3.5",
30 | "Programming Language :: Python :: 3.6",
31 | "Programming Language :: Python :: 3.7",
32 | "Programming Language :: Python :: 3.8",
33 | "Programming Language :: Python :: 3.9",
34 | "Programming Language :: Python :: 3.10",
35 | "Programming Language :: Python :: 3.11",
36 | "Programming Language :: Python :: 3.12",
37 | "Programming Language :: Python :: 3.13",
38 | "Programming Language :: Python :: 3.14",
39 | "Programming Language :: Python :: Implementation :: MicroPython",
40 | # NOTE: CircuitPython is also supported, but no classifier exists for it
41 | ]
42 |
43 | keywords = ["electronics, maker"]
44 |
45 | [project.urls]
46 | homepage = "https://www.sparkfun.com/products/16396"
47 |
48 | [tool.setuptools]
49 | py-modules = ["qwiic_serlcd"]
50 |
--------------------------------------------------------------------------------
/qwiic_serlcd.py:
--------------------------------------------------------------------------------
1 | #-----------------------------------------------------------------------------
2 | # qwiic_serlcd.py
3 | #
4 | # Python library for I2C control of the SparkFun Serial LCDs (QWIIC):
5 | #
6 | # SparkFun 16x2 SerLCD - RGB Backlight (Qwiic)
7 | # https://www.sparkfun.com/products/16396
8 | #
9 | # SparkFun 16x2 SerLCD - RGB Text (Qwiic)
10 | # https://www.sparkfun.com/products/16397
11 | #
12 | # SparkFun 20x4 SerLCD - RGB Backlight (Qwiic)
13 | # https://www.sparkfun.com/products/16398
14 | #
15 | #------------------------------------------------------------------------
16 | #
17 | # Written by SparkFun Electronics, August 2020
18 | #
19 | # This python library supports the SparkFun Electroncis qwiic
20 | # qwiic sensor/board ecosystem
21 | #
22 | # More information on qwiic is at https:// www.sparkfun.com/qwiic
23 | #
24 | # Do you like this library? Help support SparkFun. Buy a board!
25 | #==================================================================================
26 | # Copyright (c) 2019 SparkFun Electronics
27 | #
28 | # Permission is hereby granted, free of charge, to any person obtaining a copy
29 | # of this software and associated documentation files (the "Software"), to deal
30 | # in the Software without restriction, including without limitation the rights
31 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 | # copies of the Software, and to permit persons to whom the Software is
33 | # furnished to do so, subject to the following conditions:
34 | #
35 | # The above copyright notice and this permission notice shall be included in all
36 | # copies or substantial portions of the Software.
37 | #
38 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44 | # SOFTWARE.
45 | #==================================================================================
46 | #
47 | # This is mostly a port of existing Arduino functionaly, so pylint is sad.
48 | # The goal is to keep the public interface pythonic, but internal is internal.
49 | #
50 | # pylint: disable=line-too-long, too-many-public-methods, invalid-name
51 | #
52 |
53 | """
54 | qwiic_serlcd
55 | ===============
56 | Python module for the SparkFun SerLCD QWIIC products:
57 |
58 | [SparkFun 16x2 SerLCD - RGB Backlight (Qwiic)](https://www.sparkfun.com/products/16396)
59 | [SparkFun 16x2 SerLCD - RGB Text (Qwiic)](https://www.sparkfun.com/products/16397)
60 | [SparkFun 20x4 SerLCD - RGB Backlight (Qwiic)](https://www.sparkfun.com/products/16398)
61 |
62 | This python package enables the user to control the SerLCDs via I2C.
63 | It is intended to be used by simply plugging in a qwiic cable for power and I2C communication.
64 |
65 | This package can be used in conjunction with the overall [SparkFun qwiic Python Package](https://github.com/sparkfun/Qwiic_Py)
66 |
67 | New to qwiic? Take a look at the entire [SparkFun qwiic ecosystem](https://www.sparkfun.com/qwiic).
68 |
69 | """
70 | #-----------------------------------------------------------------------------
71 | import struct
72 | import time
73 |
74 | import qwiic_i2c
75 |
76 | # Define the device name and I2C addresses. These are set in the class defintion
77 | # as class variables, making them avilable without having to create a class instance.
78 | # This allows higher level logic to rapidly create a index of qwiic devices at
79 | # runtine
80 | #
81 | # The name of this device
82 | _DEFAULT_NAME = "SparkFun Qwiic SerLCD"
83 |
84 | # Some devices have multiple available addresses - this is a list of these addresses.
85 | # NOTE: The first address in this list is considered the default I2C address for the
86 | # device.
87 | _AVAILABLE_I2C_ADDRESS = [0x72] # default address, note it can be changed via software commands
88 |
89 | # Register codes for the SparkFun SerLCD
90 |
91 | DISPLAY_ADDRESS1 = 0x72 # This is the default address of the OpenLCD
92 | MAX_ROWS = 4
93 | MAX_COLUMNS = 20
94 |
95 | # OpenLCD command characters
96 | SPECIAL_COMMAND = 254 # Magic number for sending a special command
97 | SETTING_COMMAND = 0x7C # 124, |, the pipe character: The command to change settings: baud, lines, width, backlight, splash, etc
98 |
99 | # OpenLCD commands
100 | CLEAR_COMMAND = 0x2D # 45, -, the dash character: command to clear and home the display
101 | CONTRAST_COMMAND = 0x18 # Command to change the contrast setting
102 | ADDRESS_COMMAND = 0x19 # Command to change the i2c address
103 | SET_RGB_COMMAND = 0x2B # 43, +, the plus character: command to set backlight RGB value
104 | ENABLE_SYSTEM_MESSAGE_DISPLAY = 0x2E # 46, ., command to enable system messages being displayed
105 | DISABLE_SYSTEM_MESSAGE_DISPLAY = 0x2F # 47, /, command to disable system messages being displayed
106 | ENABLE_SPLASH_DISPLAY = 0x30 # 48, 0, command to enable splash screen at power on
107 | DISABLE_SPLASH_DISPLAY = 0x31 # 49, 1, command to disable splash screen at power on
108 | SAVE_CURRENT_DISPLAY_AS_SPLASH = 0x0A # 10, Ctrl+j, command to save current text on display as splash
109 |
110 | # special commands
111 | LCD_RETURNHOME = 0x02
112 | LCD_ENTRYMODESET = 0x04
113 | LCD_DISPLAYCONTROL = 0x08
114 | LCD_CURSORSHIFT = 0x10
115 | LCD_SETDDRAMADDR = 0x80
116 |
117 | # flags for display entry mode
118 | LCD_ENTRYRIGHT = 0x00
119 | LCD_ENTRYLEFT = 0x02
120 | LCD_ENTRYSHIFTINCREMENT = 0x01
121 | LCD_ENTRYSHIFTDECREMENT = 0x00
122 |
123 | # flags for display on/off control
124 | LCD_DISPLAYON = 0x04
125 | LCD_DISPLAYOFF = 0x00
126 | LCD_CURSORON = 0x02
127 | LCD_CURSOROFF = 0x00
128 | LCD_BLINKON = 0x01
129 | LCD_BLINKOFF = 0x00
130 |
131 | # flags for display/cursor shift
132 | LCD_DISPLAYMOVE = 0x08
133 | LCD_CURSORMOVE = 0x00
134 | LCD_MOVERIGHT = 0x04
135 | LCD_MOVELEFT = 0x00
136 |
137 | def map(x, in_min, in_max, out_min, out_max):
138 | """!
139 | Map a value from one range to another
140 |
141 | @param float x: The value to be mapped
142 | @param float in_min: Minimum of input range
143 | @param float in_max: Maximum of input range
144 | @param float out_min: Minimum of output range
145 | @param float out_max: Maximum of output range
146 | @return **int** The value scaled to the new range
147 | """
148 | return int((x-in_min) * (out_max-out_min) / (in_max-in_min) + out_min)
149 |
150 | # define the class that encapsulates the device being created. All information associated with this
151 | # device is encapsulated by this class. The device class should be the only value exported
152 | # from this module.
153 |
154 | class QwiicSerlcd(object):
155 | """!
156 | This class implements the basic functions of the Qwiic SerLCD device via the I2C bus.
157 | """
158 | # Constructor
159 | device_name = _DEFAULT_NAME
160 | available_addresses = _AVAILABLE_I2C_ADDRESS
161 | _displayControl = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
162 | _displayMode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
163 |
164 | # Constructor
165 | def __init__(self, address=None, i2c_driver=None):
166 | """!
167 | @param address: The I2C address to use for the device.
168 | If not provided, the default address is used.
169 | @param i2c_driver: An existing i2c driver object. If not provided
170 | a driver object is created.
171 | @return: **Object** The QwiicSerlcd device object.
172 | """
173 | # Did the user specify an I2C address?
174 | self.address = address if address is not None else self.available_addresses[0]
175 |
176 | # load the I2C driver if one isn't provided
177 |
178 | if i2c_driver is None:
179 | self._i2c = qwiic_i2c.getI2CDriver()
180 | if self._i2c is None:
181 | print("Unable to load I2C driver for this platform.")
182 | return
183 | else:
184 | self._i2c = i2c_driver
185 |
186 | def is_connected(self):
187 | """!
188 | @brief Determine if a device is connected to the system.
189 | This method checks if the device with the specified I2C address is connected to the system.
190 | @return **bool** True if the device is connected, otherwise False.
191 | """
192 | # Another possible comment could be @retval bool True: Device is connected. above
193 | return qwiic_i2c.isDeviceConnected(self.address)
194 |
195 | connected = property(is_connected)
196 |
197 | def begin(self):
198 | """!
199 | Initialize the operation of the SerLCD module
200 |
201 | @return **bool** Returns true if the initialization was successful, otherwise False.
202 | """
203 | # set default settings, as defined in constructor
204 | result0 = self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
205 | time.sleep(1)
206 | result1 = self.specialCommand(LCD_ENTRYMODESET | self._displayMode)
207 | time.sleep(1)
208 | result2 = self.clearScreen()
209 | time.sleep(1)
210 |
211 | return (bool(result0) & bool(result1) & bool(result2))
212 |
213 | def print(self, string):
214 | """!
215 | Print a string of characters to the LCD
216 |
217 | @param string string: The string you would like to print. Aka ASCII characters. example: "Hello"
218 |
219 | @return **bool** Returns True if the I2C writes were successful, otherwise False.
220 | """
221 | for c in string:
222 | if self._i2c.writeCommand(self.address, ord(c)) == False:
223 | return False
224 | time.sleep(0.01)
225 | return True
226 |
227 | def clearScreen(self):
228 | """!
229 | Sends the command to clear the screen
230 |
231 | @return **bool** Returns True if the I2C write was successful, otherwise False.
232 | """
233 | result = self.command(CLEAR_COMMAND)
234 | time.sleep(0.01)
235 | return result
236 |
237 | def home(self):
238 | """!
239 | Send the home command to the display. This returns the cursor
240 | to the beginning of the display, without clearing
241 | the display.
242 |
243 | @return **bool** Returns True if the I2C write was successful, otherwise False.
244 | """
245 | result = self.specialCommand(LCD_RETURNHOME)
246 | time.sleep(0.01)
247 | return result
248 |
249 | def setCursor(self, col, row):
250 | """!
251 | Set the cursor position to a particular column and row.
252 |
253 | @param int col: The column position (0-19)
254 | @param int row: The row position (0-3)
255 |
256 | @return **bool** Returns True if the I2C write was successful, otherwise False.
257 | """
258 | row_offsets = [0x00, 0x40, 0x14, 0x54]
259 |
260 | # keep variables in bounds
261 | row = max(0, row) # row cannot be less than 0
262 | row = min(row, (MAX_ROWS - 1)) # row cannot be greater than max rows
263 |
264 | # construct the cursor "command"
265 | command = LCD_SETDDRAMADDR | (col + row_offsets[row])
266 |
267 | # send the complete bytes (special command + command)
268 | return self._i2c.writeByte(self.address, SPECIAL_COMMAND, command)
269 |
270 | def setContrast(self, contrast):
271 | """!
272 | Set the contrast of the LCD screen (0-255)
273 |
274 | @param int contrast: The new contrast value (0-255)
275 |
276 | @return **bool** Returns True if the I2C write was successful, otherwise False.
277 | """
278 | # To set the contrast we need to send 3 bytes:
279 | # (1) SETTINGS_COMMAND
280 | # (2) CONTRAST_COMMAND
281 | # (3) contrast value
282 | #
283 | # To do this, we are going to use writeBlock(),
284 | # so we need our "block of bytes" to include
285 | # CONTRAST_COMMAND and contrast value
286 |
287 | block = [CONTRAST_COMMAND, contrast]
288 |
289 | # send the complete bytes (address, settings command , contrast command, contrast value)
290 | result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
291 | time.sleep(0.01)
292 | return result
293 |
294 | def setBacklight(self, r, g, b):
295 | """!
296 | Set the brightness of each backlight (red, green, blue)
297 |
298 | @param int red: The new red brightness value (0-255)
299 | @param int green: The new green brightness value (0-255)
300 | @param int blue: The new blue brightness value (0-255)
301 |
302 | @return **bool** Returns True if the I2C write was successful, otherwise False.
303 | """
304 | # To set the backlight values, we are going to send 10 bytes
305 | # They will all live in a list called "block"
306 | # Let's fill up block with what we need to transmit...
307 |
308 | block = [0,1,2,3,4,5,6,7,8,9]
309 |
310 | # map our incoming values (0-255) to the backlight command range (0-29)
311 | red = 128 + map(r, 0, 255, 0, 29)
312 | green = 158 + map(g, 0, 255, 0, 29)
313 | blue = 188 + map(b, 0, 255, 0, 29)
314 |
315 | # Turn display off to hide confirmation messages
316 | self._displayControl &= ~LCD_DISPLAYON
317 | block[0] = SPECIAL_COMMAND
318 | block[1] = (LCD_DISPLAYCONTROL | self._displayControl)
319 |
320 | # Set the red, green and blue values
321 | block[2] = SETTING_COMMAND
322 | block[3] = red
323 | block[4] = SETTING_COMMAND
324 | block[5] = green
325 | block[6] = SETTING_COMMAND
326 | block[7] = blue
327 |
328 | # Turn display back on and end
329 | self._displayControl |= LCD_DISPLAYON
330 | block[8] = SPECIAL_COMMAND
331 | block[9] = (LCD_DISPLAYCONTROL | self._displayControl)
332 |
333 | # send the complete bytes (address, settings command , contrast command, contrast value)
334 | result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
335 | time.sleep(0.05)
336 | return result
337 |
338 | def specialCommand(self, command, count = 1):
339 | """!
340 | Send one (or multiple) special commands to the display.
341 | Used by other functions.
342 |
343 | @param int command: Command to send (a single byte)
344 | @param int count: Number of times to send the command (if omitted, then default is once)
345 |
346 | @return **bool** Returns True if the I2C write was successful, otherwise False.
347 | """
348 | for i in range(0, count):
349 | # send the complete bytes (special command + command)
350 | result = self._i2c.writeByte(self.address, SPECIAL_COMMAND, command)
351 | time.sleep(0.05)
352 | return result
353 |
354 | def command(self, command):
355 | """!
356 | Send one setting command to the display.
357 | Used by other functions.
358 |
359 | @param int command: Command to send (a single byte)
360 |
361 | @return **bool** Returns True if the I2C write was successful, otherwise False.
362 | """
363 | result = self._i2c.writeByte(self.address, SETTING_COMMAND, command)
364 | time.sleep(0.01)
365 | return result
366 |
367 | def moveCursorLeft(self, count = 1):
368 | """!
369 | Move the cursor one or more characters to the left.
370 |
371 | @param int count: Number of character spaces you'd like to move
372 |
373 | @return **bool** Returns True if the I2C write was successful, otherwise False.
374 | """
375 | return self.specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVELEFT, count)
376 |
377 | def moveCursorRight(self, count = 1):
378 | """!
379 | Move the cursor one or more characters to the right.
380 |
381 | @param int count: Number of character spaces you'd like to move
382 |
383 | @return **bool** Returns True if the I2C write was successful, otherwise False.
384 | """
385 | return self.specialCommand(LCD_CURSORSHIFT | LCD_CURSORMOVE | LCD_MOVERIGHT, count)
386 |
387 | def cursor(self):
388 | """!
389 | Turn the underline cursor on.
390 |
391 | @return **bool** Returns True if the I2C write was successful, otherwise False.
392 | """
393 | self._displayControl |= LCD_CURSORON
394 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
395 |
396 | def noCursor(self):
397 | """!
398 | Turn the underline cursor off.
399 |
400 | @return **bool** Returns True if the I2C write was successful, otherwise False.
401 | """
402 | self._displayControl &= ~LCD_CURSORON
403 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
404 |
405 | def blink(self):
406 | """!
407 | Turn the blink cursor on.
408 |
409 | @return **bool** Returns True if the I2C write was successful, otherwise False.
410 | """
411 | self._displayControl |= LCD_BLINKON
412 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
413 |
414 | def noBlink(self):
415 | """!
416 | Turn the blink cursor off.
417 |
418 | @return **bool** Returns True if the I2C write was successful, otherwise False.
419 | """
420 | self._displayControl &= ~LCD_BLINKON
421 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
422 |
423 | def scrollDisplayLeft(self, count = 1):
424 | """!
425 | Scroll the display one or multiple characters to the left, without changing the text.
426 |
427 | @param int count: Number of character spaces you'd like to scroll
428 |
429 | @return **bool** Returns True if the I2C write was successful, otherwise False.
430 | """
431 | return self.specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT, count)
432 |
433 | def scrollDisplayRight(self, count = 1):
434 | """!
435 | Scroll the display one or multiple characters to the right, without changing the text.
436 |
437 | @param int count: Number of character spaces you'd like to scroll
438 |
439 | @return **bool** Returns True if the I2C write was successful, otherwise False.
440 | """
441 | return self.specialCommand(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT, count)
442 |
443 | def autoscroll(self):
444 | """!
445 | Turn autoscrolling on. This will right-justify text from the cursor.
446 |
447 | @return **bool** Returns True if the I2C write was successful, otherwise False.
448 | """
449 | self._displayControl |= LCD_ENTRYSHIFTINCREMENT
450 | return self.specialCommand(LCD_ENTRYMODESET | self._displayControl)
451 |
452 | def noAutoscroll(self):
453 | """!
454 | Turn autoscrolling off.
455 |
456 | @return **bool** Returns True if the I2C write was successful, otherwise False.
457 | """
458 | self._displayControl &= ~LCD_ENTRYSHIFTINCREMENT
459 | return self.specialCommand(LCD_ENTRYMODESET | self._displayControl)
460 |
461 | def leftToRight(self):
462 | """!
463 | Set the text to flow from left to right.
464 |
465 | @return **bool** Returns True if the I2C write was successful, otherwise False.
466 | """
467 | self._displayControl |= LCD_ENTRYLEFT
468 | return self.specialCommand(LCD_ENTRYMODESET | self._displayControl)
469 |
470 | def rightToLeft(self):
471 | """!
472 | Set the text to flow from right to left
473 |
474 | @return **bool** Returns True if the I2C write was successful, otherwise False.
475 | """
476 | self._displayControl &= ~LCD_ENTRYLEFT
477 | return self.specialCommand(LCD_ENTRYMODESET | self._displayControl)
478 |
479 | def createChar(self, location, charmap):
480 | """!
481 | Create a custom character
482 |
483 | @param int location: character number 0 to 7
484 | @param list of int charmap: byte array for character
485 |
486 | @return **bool** Returns True if the I2C write was successful, otherwise False.
487 | """
488 | location &= 0x7 # we only have 8 locations 0-7
489 |
490 | # create a block of data bytes to send to the screen
491 | # This will include the location (with the addition of 27 to let the screen know)
492 | # and the 8 bytes of charmap
493 | block = [0,1,2,3,4,5,6,7,8,9]
494 |
495 | block[0] = (27 + location) # command type/location
496 |
497 | for i in range(1,9):
498 | block[i] = charmap[i-1]
499 |
500 | # send the complete bytes (address, settings command , write char command (includes location), charmap)
501 | result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
502 | time.sleep(0.05)
503 | return result
504 |
505 | def writeChar(self, location):
506 | """!
507 | Write a custom character to the display
508 |
509 | @param int location: character number 0 to 7
510 |
511 | @return **bool** Returns True if the I2C write was successful, otherwise False.
512 | """
513 | location &= 0x7 # we only have 8 locations 0-7
514 |
515 | # send command
516 | result = self.command(35 + location)
517 | time.sleep(0.05)
518 | return result
519 |
520 | def display(self):
521 | """!
522 | Turn the display on quickly.
523 |
524 | @return **bool** Returns True if the I2C write was successful, otherwise False.
525 | """
526 | self._displayControl |= LCD_DISPLAYON
527 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
528 |
529 | def noDisplay(self):
530 | """!
531 | Turn the display off quickly.
532 |
533 | @return **bool** Returns True if the I2C write was successful, otherwise False.
534 | """
535 | self._displayControl &= ~LCD_DISPLAYON
536 | return self.specialCommand(LCD_DISPLAYCONTROL | self._displayControl)
537 |
538 | def setFastBacklight(self, r, g, b):
539 | """!
540 | Set backlight with no LCD messages or delays
541 |
542 | @param int r: red backlight value 0-255
543 | @param int g: green backlight value 0-255
544 | @param int b: blue backlight value 0-255
545 |
546 | @return **bool** Returns True if the I2C write was successful, otherwise False.
547 | """
548 | # create a block of data bytes to send to the screen
549 | # This will include the SET_RGB_COMMAND, and three bytes of backlight values
550 | block = [0,1,2,3]
551 |
552 | block[0] = SET_RGB_COMMAND # command
553 | block[1] = r
554 | block[2] = g
555 | block[3] = b
556 |
557 | # send the complete bytes (address, settings command , rgb command , red byte, green byte, blue byte)
558 | result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
559 | time.sleep(0.01)
560 | return result
561 |
562 | def enableSystemMessages(self):
563 | """!
564 | Enable system messages
565 |
566 | @return **bool** Returns True if the I2C write was successful, otherwise False.
567 | """
568 | # send command
569 | result = self.command(ENABLE_SYSTEM_MESSAGE_DISPLAY)
570 | time.sleep(0.01)
571 | return result
572 |
573 | def disableSystemMessages(self):
574 | """!
575 | Disable system messages
576 |
577 | @return **bool** Returns True if the I2C write was successful, otherwise False.
578 | """
579 | # send command
580 | result = self.command(DISABLE_SYSTEM_MESSAGE_DISPLAY)
581 | time.sleep(0.01)
582 | return result
583 |
584 | def enableSplash(self):
585 | """!
586 | Enable splash screen at power on
587 |
588 | @return **bool** Returns True if the I2C write was successful, otherwise False.
589 | """
590 | # send command
591 | result = self.command(ENABLE_SPLASH_DISPLAY)
592 | time.sleep(0.01)
593 | return result
594 |
595 | def disableSplash(self):
596 | """!
597 | Disable splash screen at power on
598 |
599 | @return **bool** Returns True if the I2C write was successful, otherwise False.
600 | """
601 | # send command
602 | result = self.command(DISABLE_SPLASH_DISPLAY)
603 | time.sleep(0.01)
604 | return result
605 |
606 | def saveSplash(self):
607 | """!
608 | Save the current display as the splash
609 | Saves whatever is currently being displayed into EEPROM
610 | This will be displayed at next power on as the splash screen
611 |
612 | @return **bool** Returns True if the I2C write was successful, otherwise False.
613 | """
614 | # send command
615 | result = self.command(SAVE_CURRENT_DISPLAY_AS_SPLASH)
616 | time.sleep(0.01)
617 | return result
618 |
619 | def setAddress(self, new_addr):
620 | """!
621 | Change the I2C Address. 0x72 is the default.
622 | Note that this change is persistent. If anything
623 | goes wrong you may need to do a hardware reset
624 | to unbrick the display.
625 |
626 | @param int new_addr: new i2c address
627 |
628 | @return **bool** Returns True if the I2C write was successful, otherwise False.
629 | """
630 | # create a block of data bytes to send to the screen
631 | # This will include the ADDRESS_COMMAND, and the new address byte value.
632 | block = [0,1]
633 |
634 | block[0] = ADDRESS_COMMAND # command
635 | block[1] = new_addr
636 |
637 | # send the complete bytes (address, settings command , address command , new_addr byte)
638 | result = self._i2c.writeBlock(self.address, SETTING_COMMAND, block)
639 | time.sleep(0.05)
640 | self.address = new_addr # update our own address, so we can still talk to the display
641 | return result
642 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | qwiic_i2c
--------------------------------------------------------------------------------