Compare commits

..

87 commits

Author SHA1 Message Date
Kattni
a9e0c61575
Merge pull request #48 from adafruit/discord-fix
Should fix pylint issue
2020-07-09 15:42:59 -04:00
dherrada
59de0cd62e Formatted with black 2020-07-09 12:47:17 -04:00
dherrada
72338bc8a3 Should fix pylint issue 2020-07-09 12:38:07 -04:00
dherrada
057204ddd4 Fixed discord invite link 2020-07-08 16:49:04 -04:00
Scott Shawcroft
583b9497f8
Merge pull request #47 from adafruit/black-update
Black reformatting with Python 3 target.
2020-04-09 09:43:41 -07:00
Kattni Rembor
ab2b00a8a7 Black reformatting with Python 3 target. 2020-04-08 13:18:56 -04:00
sommersoft
b3e7bd1614 build.yml: add black formatting check
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-04-07 16:06:22 -05:00
Kattni
b1ad905848
Merge pull request #46 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2020-03-17 14:28:08 -04:00
dherrada
8002a009c6 Changed import order to make pylint happy 2020-03-16 15:29:01 -04:00
dherrada
7f6b74cc21 Ran black, updated to pylint 2.x 2020-03-16 15:24:18 -04:00
sommersoft
5cdd68663d update code of coduct: discord moderation contact section
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-15 18:28:14 -05:00
Kattni
61f7106a78
Merge pull request #45 from sommersoft/patch_coc
Update Code of Conduct
2020-03-13 15:45:24 -04:00
sommersoft
645e99ede6 update code of conduct 2020-03-13 13:41:55 -05:00
sommersoft
70ecf3aae1 update pylintrc for black
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-08 19:07:29 -05:00
sommersoft
fa94e88692 build.yml: move pylint, black, and Sphinx installs to each repo; add description to 'actions-ci/install.sh'
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-03-05 10:06:34 -06:00
Jeff Epler
0c034cf0bf
Merge pull request #44 from caternuson/iss38
Add I2C address parameter
2020-01-19 12:16:20 -06:00
caternuson
15bf2a8ddc lint 2020-01-16 17:05:13 -08:00
caternuson
0de54c1c9a add address parameter 2020-01-16 16:56:55 -08:00
sommersoft
14f220d6c6 update pylint examples directive
Signed-off-by: sommersoft <sommersoft@gmail.com>
2020-01-14 17:10:48 -06:00
siddacious
50675cb99f
Merge pull request #43 from adafruit/dherrada-patch-1
Moved repository from Travis to GitHub Actions
2020-01-01 12:38:18 -08:00
dherrada
e43daf89c0 Moved repository from Travis to GitHub Actions 2020-01-01 14:59:35 -05:00
siddacious
1ba1d23434
Merge pull request #42 from adafruit/dherrada-patch-1
Removed building locally section from README, replaced with documenta…
2019-10-20 12:46:08 -07:00
dherrada
c17d80acf0
Removed building locally section from README, replaced with documentation section 2019-10-17 18:25:04 -04:00
brentrubell
2b1dbc2cc2
Merge pull request #39 from caternuson/iss36
Updates for new MCP230xx
2019-05-31 16:23:22 -04:00
caternuson
e786afa832 update README.rst 2019-05-31 13:20:49 -07:00
caternuson
dcf1613db5 put back the pullups 2019-05-16 18:28:06 -07:00
caternuson
bab1686fc4 updates for new MCP230xx 2019-05-16 17:36:56 -07:00
Melissa LeBlanc-Williams
d0fc75617c
Merge pull request #37 from profbrady/profbrady-patch-1
Update character_lcd.py
2019-04-11 20:32:55 -07:00
profbrady
f9d662e107
Update character_lcd.py 2019-04-11 23:23:07 -04:00
profbrady
ff1df52a0b
Update character_lcd.py 2019-04-11 22:44:17 -04:00
profbrady
eb8612e0c3
Update charlcd_mono_simpletest.py 2019-04-11 22:36:30 -04:00
profbrady
4ffe6dedf2
Update character_lcd.py 2019-04-11 21:44:25 -04:00
profbrady
3d4340cef0
Update charlcd_mono_simpletest.py 2019-04-11 07:20:12 -04:00
profbrady
7ef2cc6c23
Update character_lcd.py 2019-04-10 10:43:57 -04:00
profbrady
5bc8ec558a
Update character_lcd.py 2019-04-10 10:22:20 -04:00
profbrady
2c1a7a4a9d
Update charlcd_mono_simpletest.py 2019-04-10 10:18:09 -04:00
profbrady
25161293a6
Update charlcd_mono_simpletest.py 2019-04-10 09:45:18 -04:00
profbrady
a6eb4efdf3
Update character_lcd.py 2019-04-10 09:38:40 -04:00
profbrady
d6338ab7e7
Update README.rst 2019-04-09 15:23:48 -04:00
profbrady
c7d02b5654
Update character_lcd.py
Update so `self.message` respects the `cursor_position()` settings. If `'\n'` is in a message string, the new line will be use the same column setting as the first line.
2019-04-06 11:52:07 -04:00
Limor "Ladyada" Fried
fe5da67239
Merge pull request #31 from khavik/patch-1
Update charled_customcharacter.py
2019-02-04 22:22:29 -05:00
Kristoffer Håvik
30522773fc
Update charled_customcharacter.py
Added create_char() to actually send the custom character to the LCD.
2019-02-05 04:00:04 +01:00
Melissa LeBlanc-Williams
e4ccef3b4e
Merge pull request #28 from Tim-Jackins/master
Fixed link
2019-02-02 10:39:04 -08:00
Kattni
bb36c4ef19
Merge pull request #30 from adafruit/ladyada-patch-1
Update .pylintrc
2019-02-02 13:31:37 -05:00
Limor "Ladyada" Fried
06bac0c938
Update .pylintrc
try to fix travis linux complaint
2019-02-02 13:28:15 -05:00
Jack Timmins
891a9e6b1f
Fixed link 2019-02-01 20:22:51 -05:00
Limor "Ladyada" Fried
2714510ce3
Merge pull request #27 from kattni/add-buttons
Adding keypad support and example
2019-01-14 12:33:46 -05:00
Kattni Rembor
be794b8c34 Update example. 2019-01-13 19:49:25 -05:00
Kattni Rembor
cd3dde487c Revert version line 2019-01-13 17:56:43 -05:00
Kattni Rembor
352d7c6626 Adding keypad support and example 2019-01-13 17:55:03 -05:00
Kattni
281bd43e42
Merge pull request #25 from sommersoft/readme_fix_travis
Update README Travis Badge
2018-12-21 13:45:19 -06:00
sommersoft
3d28d7a282 change 'travis-ci.org' to 'travis-ci.com' 2018-12-21 13:23:49 -06:00
Brennen Bearnes
636dbe80c9
Merge pull request #23 from adafruit/pypi-readme
Added PyPI instructions to README
2018-11-29 10:34:33 -07:00
Kattni
587e801d6a
Added PyPI instructions to README 2018-11-29 12:14:45 -05:00
Kattni
5f5680ba95
Merge pull request #22 from adafruit/mcp230xx-74hc595-install-requires
add missing mcp230xx and 74hc595 requirements to setup.py
2018-11-28 13:08:50 -05:00
Brennen Bearnes
c613a107cf add missing mcp230xx and 74hc595 requirements to setup.py 2018-11-28 11:02:10 -07:00
Limor "Ladyada" Fried
706a097d8b
Merge pull request #20 from kattni/cursor-position-fix
cursor_position fix, add column check
2018-11-21 12:03:33 -08:00
Kattni Rembor
6b34402f93 cursor_position fix, add column check 2018-11-21 14:59:17 -05:00
Kattni
32570d2853
Merge pull request #19 from kattni/mcp230xx-support
Refactor complete!
2018-11-21 12:46:17 -05:00
Kattni Rembor
af6e0231e8 Remove self.backlight_inverted, use property 2018-11-21 12:35:13 -05:00
Kattni Rembor
1258c470b8 Refactored, updated examples, appeased Sphinx. 2018-11-20 21:16:26 -05:00
Kattni Rembor
8fe9cf2046 Removing superfluous rgb.py file 2018-11-20 17:44:28 -05:00
Kattni Rembor
95a9f14c8d SPI working, I2C not. 2018-11-20 17:42:08 -05:00
Kattni Rembor
6e064f91a0 I2C not currently functional. 2018-11-20 16:32:26 -05:00
Kattni Rembor
ee9544a36a RGB subclass currently functional. 2018-11-20 15:48:04 -05:00
Kattni Rembor
e490b7fd1c Removed __init__.py, updated import method to resolve M0 mem issue 2018-11-20 12:24:51 -05:00
Kattni Rembor
70f673e47d Moved imports to speed up on M0 2018-11-19 18:02:35 -05:00
Kattni Rembor
645da5fa3e Update package init 2018-11-19 17:12:47 -05:00
Kattni Rembor
97a57fe983 Updated example named, added RGB I2C 2018-11-19 16:30:02 -05:00
Kattni Rembor
80f8222907 Example rename for rpi 2018-11-19 16:23:26 -05:00
Kattni Rembor
b5adf5e594 Needs test: RPi, M0, standalone LCDs 2018-11-19 15:36:40 -05:00
Kattni Rembor
de93de2187 Backlight now a property. 2018-11-16 20:55:01 -05:00
Kattni Rembor
287864b9fa Current status: functional. 2018-11-16 20:47:10 -05:00
Kattni Rembor
7fa1519e70 Add I2C to RGB, get_pin() to 74HC595
Added functionality from monochrome LCD to RGB.
2018-11-14 12:39:22 -05:00
Kattni Rembor
9027f16d2d SPI pin change. 2018-11-13 16:13:17 -05:00
Kattni Rembor
3e6a1a64d1 I2C working, SPI needs testing 2018-11-13 16:01:18 -05:00
Kattni
3775cd7a03
Merge pull request #17 from adafruit/rgb_simpletest_pins
align rgb simpletest pins with learn guide fritzing
2018-10-29 15:36:48 -04:00
Brennen Bearnes
d766bb95d4 align rgb simpletest pins with learn guide fritzing
Also adds a .clear() to the test loop.
2018-10-29 11:10:18 -06:00
Kattni
375ce69fdf
Merge pull request #16 from adafruit/pi_rgb_toggle
enable non-PWM pins for backlight color, add kattni's pi-specific simpletest
2018-10-26 14:25:24 -04:00
Brennen Bearnes
8750a95034 fix indentation in elif block 2018-10-26 12:11:47 -06:00
Brennen Bearnes
a90e624bd7 else: if -> elif 2018-10-26 12:08:14 -06:00
Brennen Bearnes
2719125e75 make pylint happy about indentation and inheriting from object 2018-10-25 23:20:02 -06:00
Brennen Bearnes
238dbf0c58 remove enable_pwm, check attrs of pin objects instead 2018-10-25 23:11:39 -06:00
Brennen Bearnes
f050d53987 enable non-PWM pins for backlight color, add pi-specific simpletest
Rationale: pulseio isn't available on CPython Linux systems (i.e.
the Pi), this mimics the design of the original
Adafruit_Python_CharLCD.

Adds `enable_pwm` parameter to Character_LCD_RGB constructor, and
conditionalizes handling of the color pins on this value.

It's entirely possible I've messed something up here, so close
review is appreciated.
2018-10-25 16:49:10 -06:00
Brennen Bearnes
ee2a9ad49b
Merge pull request #15 from kattni/rpi-example
Add RPi example, cleanup M0 example
2018-10-25 12:05:50 -06:00
Kattni Rembor
d9679a64d5 Add RPi example, cleanup M0 example 2018-10-25 12:55:52 -04:00
Kattni
3fd33567a4
Merge pull request #14 from adafruit/kattni-patch-1
added python version to readthedocs.yml
2018-10-23 15:37:23 -04:00
33 changed files with 1832 additions and 1285 deletions

57
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,57 @@
name: Build CI
on: [pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install dependencies
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
run: |
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: Check formatting
run: |
black --check --target-version=py35 .
- name: PyLint
run: |
pylint $( find . -path './adafruit*.py' )
([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" ))
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Build docs
working-directory: docs
run: sphinx-build -E -W -b html . _build/html

81
.github/workflows/release.yml vendored Normal file
View file

@ -0,0 +1,81 @@
name: Release Actions
on:
release:
types: [published]
jobs:
upload-release-assets:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Translate Repo Name For Build Tools filename_prefix
id: repo-name
run: |
echo ::set-output name=repo-name::$(
echo ${{ github.repository }} |
awk -F '\/' '{ print tolower($2) }' |
tr '_' '-'
)
- name: Set up Python 3.6
uses: actions/setup-python@v1
with:
python-version: 3.6
- name: Versions
run: |
python3 --version
- name: Checkout Current Repo
uses: actions/checkout@v1
with:
submodules: true
- name: Checkout tools repo
uses: actions/checkout@v2
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install deps
run: |
source actions-ci/install.sh
- name: Build assets
run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location .
- name: Upload Release Assets
# the 'official' actions version does not yet support dynamically
# supplying asset names to upload. @csexton's version chosen based on
# discussion in the issue below, as its the simplest to implement and
# allows for selecting files with a pattern.
# https://github.com/actions/upload-release-asset/issues/4
#uses: actions/upload-release-asset@v1.0.1
uses: csexton/release-asset-action@master
with:
pattern: "bundles/*"
github-token: ${{ secrets.GITHUB_TOKEN }}
upload-pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Check For setup.py
id: need-pypi
run: |
echo ::set-output name=setup-py::$( find . -wholename './setup.py' )
- name: Set up Python
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
if: contains(steps.need-pypi.outputs.setup-py, 'setup.py')
env:
TWINE_USERNAME: ${{ secrets.pypi_username }}
TWINE_PASSWORD: ${{ secrets.pypi_password }}
run: |
python setup.py sdist
twine upload dist/*

1
.gitignore vendored
View file

@ -4,7 +4,6 @@ __pycache__
_build _build
*.pyc *.pyc
.env .env
build*
bundles bundles
*.DS_Store *.DS_Store
.eggs .eggs

View file

@ -52,7 +52,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes # no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W" # --disable=W"
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
# Enable the message, report, category or checker with the given id(s). You can # Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option # either give multiple identifier separated by comma (,) or put this option
@ -119,7 +119,8 @@ spelling-store-unknown-words=no
[MISCELLANEOUS] [MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma. # List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO # notes=FIXME,XXX,TODO
notes=FIXME,XXX
[TYPECHECK] [TYPECHECK]
@ -300,7 +301,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$
# Good variable names which should always be accepted, separated by a comma # Good variable names which should always be accepted, separated by a comma
# good-names=i,j,k,ex,Run,_ # good-names=i,j,k,ex,Run,_
good-names=r,g,b,i,j,k,n,ex,Run,_ good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_
# Include a hint for the correct naming format with invalid-name # Include a hint for the correct naming format with invalid-name
include-naming-hint=no include-naming-hint=no
@ -422,7 +423,7 @@ max-returns=6
max-statements=50 max-statements=50
# Minimum number of public methods for a class (see R0903). # Minimum number of public methods for a class (see R0903).
min-public-methods=2 min-public-methods=1
[EXCEPTIONS] [EXCEPTIONS]

View file

@ -1,32 +0,0 @@
dist: trusty
sudo: false
language: python
python:
- '3.6'
cache:
pip: true
deploy:
- provider: releases
api_key: "$GITHUB_TOKEN"
file_glob: true
file: "$TRAVIS_BUILD_DIR/bundles/*"
skip_cleanup: true
overwrite: true
on:
tags: true
- provider: pypi
user: adafruit-travis
on:
tags: true
password:
secure: oFtv5bdkv05CtHQWGsGErePA41nC81eH9rBtTmvLV8eBU6+KMLwP5mn6u9bRryAiK7xXvdn9YWQfB1w+OTgdZjCMxITGXoPGBxsQ5Fg7k8Jft127e2zJFdFfpa5oSEnP4fEm+C5GzlH3a8WRa8NbGY44zetSxK6HhbSpaItVYyQ7rPcz+sPxfyyBIKVsAzj9DD7tLlDsNJw6Gsp9pL//yvdEzv7/hr7tjwyEmEPHAczbmrXu/824zJjHIB9Dkbv9etXLvhGwtLToP/pbwsTNDRSdI8n3yr4zDmGSqFGJa+awOlohWFPjmitmQodoXr9XKqZO7GtKocQ1z1MLopueYcQiVs9hIqYlMWNg8dVlSrCALGnNeF3NwMQq30DNC1gUXhhGPY6cxcBruJtXVJ65MyD3pEkHio5ET+ct5MUJi0nmikQSh3jPZolzCecZSC0gI9xO4Yqy6vVKWD7GzhNYo4plhWtu0CZW/ixmjUCTVN9CNV2JXbRNV985axDunrx3gu3In2hihC2XGtkxSJomkSsXexvtEeKstjlmhA5LSHauIbnAIM4hOPUpyWk5IqTZQblmzBigiZ5JRZzAzuNN80H1WWlaEEynV2nHO6pFVphu3bWpEyzhhLByWi3fk27w3Y0sroJ6yx5YcAJuq/PNEUyeA3JATXkd55OFzujH+2A=
install:
- pip install -r requirements.txt
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
- pip install --force-reinstall pylint==1.9.2
script:
- pylint adafruit_character_lcd/*.py
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py)
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-charlcd --library_location
.
- cd docs && sphinx-build -E -W -b html . _build/html && cd ..

View file

@ -34,13 +34,15 @@ Examples of unacceptable behavior by participants include:
* Excessive or unwelcome helping; answering outside the scope of the question * Excessive or unwelcome helping; answering outside the scope of the question
asked asked
* Trolling, insulting/derogatory comments, and personal or political attacks * Trolling, insulting/derogatory comments, and personal or political attacks
* Promoting or spreading disinformation, lies, or conspiracy theories against
a person, group, organisation, project, or community
* Public or private harassment * Public or private harassment
* Publishing others' private information, such as a physical or electronic * Publishing others' private information, such as a physical or electronic
address, without explicit permission address, without explicit permission
* Other conduct which could reasonably be considered inappropriate * Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self. "technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and We value many things beyond technical expertise, including collaboration and
@ -72,10 +74,10 @@ You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>. In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an to all Community Moderators by tagging @community moderators. You may
open message from any channel, or a direct message to @kattni#1507, also send an open message from any channel, or a direct message to
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or @kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442,
@Andon#8175. @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175.
Email and direct message reports will be kept confidential. Email and direct message reports will be kept confidential.
@ -83,7 +85,7 @@ In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service, illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord. you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct. These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the 1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and Adafruit Community Code of Conduct. All reports will be reviewed and
@ -124,4 +126,4 @@ For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement. Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion. own moderation policy so as to avoid confusion.

View file

@ -7,11 +7,11 @@ Introduction
:alt: Documentation Status :alt: Documentation Status
.. image :: https://img.shields.io/discord/327254708534116352.svg .. image :: https://img.shields.io/discord/327254708534116352.svg
:target: https://discord.gg/nBQh6qu :target: https://adafru.it/discord
:alt: Discord :alt: Discord
.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_CharLCD.svg?branch=master .. image:: https://github.com/adafruit/Adafruit_CircuitPython_CharLCD/workflows/Build%20CI/badge.svg
:target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_CharLCD :target: https://github.com/adafruit/Adafruit_CircuitPython_CharLCD/actions/
:alt: Build Status :alt: Build Status
This library is compatible with standard Character LCDs such as: This library is compatible with standard Character LCDs such as:
@ -19,13 +19,39 @@ This library is compatible with standard Character LCDs such as:
* `Adafruit RGB backlight negative LCD 16x2 <https://www.adafruit.com/product/399>`_ * `Adafruit RGB backlight negative LCD 16x2 <https://www.adafruit.com/product/399>`_
* `Adafruit RGB backlight negative LCD 20x4 <https://www.adafruit.com/product/498>`_ * `Adafruit RGB backlight negative LCD 20x4 <https://www.adafruit.com/product/498>`_
Compatible with CircuitPython Versions: 2.x Installing from PyPI
--------------------
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI <https://pypi.org/project/adafruit-circuitpython-charlcd/>`_. To install for current user:
.. code-block:: shell
pip3 install adafruit-circuitpython-charlcd
To install system-wide (this may be required in some cases):
.. code-block:: shell
sudo pip3 install adafruit-circuitpython-charlcd
To install in a virtual environment in your current project:
.. code-block:: shell
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-charlcd
Dependencies Dependencies
============= =============
This driver depends on: This driver depends on:
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_ * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
* `Adafruit CircuitPython BusDevice <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
* `Adafruit CircuitPython MCP230xx <https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx>`_
* `Adafruit CircuitPython 74HC595 <https://github.com/adafruit/Adafruit_CircuitPython_74HC595>`_
I2C & SPI displays also depend on: I2C & SPI displays also depend on:
@ -42,20 +68,23 @@ The ``Character_LCD`` class interfaces a predefined Character LCD display with C
.. code-block:: python .. code-block:: python
import adafruit_character_lcd import board
import digitalio
import adafruit_character_lcd.character_lcd as character_lcd
You must define the data pins (``RS``, ``EN``, ``D4``, ``D5``, ``D6``, ``D7``) in your code before using the ``Character_LCD`` class. You must define the data pins (``RS``, ``EN``, ``D4``, ``D5``, ``D6``, ``D7``) in your code before using the ``Character_LCD`` class.
If you want to have on/off ``backlight`` functionality, you can also define your backlight as ``lcd_backlight``. Otherwise, the backlight will always remain on. An example of this is below If you want to have on/off ``backlight`` functionality, you can also define your backlight as ``lcd_backlight``. Otherwise, the backlight
will always remain on. The following is an example setup.
.. code-block:: python .. code-block:: python
lcd_rs = digitalio.DigitalInOut(D7) lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(D8) lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(D12) lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(D11) lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(D10) lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(D9) lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_backlight = digitalio.DigitalInOut(D13) lcd_backlight = digitalio.DigitalInOut(board.D13)
You must also define the size of the CharLCD by specifying its ``lcd_columns`` and ``lcd_rows``: You must also define the size of the CharLCD by specifying its ``lcd_columns`` and ``lcd_rows``:
@ -68,79 +97,27 @@ After you have set up your LCD, we can make the device by calling it
.. code-block:: python .. code-block:: python
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd = character_lcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
To verify that your pins are correct, print a hello message to the CharLCD: To verify that your pins are correct, print a hello message to the CharLCD:
.. code-block:: python .. code-block:: python
lcd.message('hello\ncircuitpython') lcd.message = "Hello\nCircuitPython"
Custom character example with create_char() is provided within /examples/ Custom character example with ``create_char()`` is provided within /examples/
Contributing Contributing
============ ============
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit_CircuitPython_CircuitPython_CharLCD/blob/master/CODE_OF_CONDUCT.md) Contributions are welcome! Please read our `Code of Conduct
before contributing to help this project stay welcoming. <https://github.com/adafruit/Adafruit_CircuitPython_CharLCD/blob/master/CODE_OF_CONDUCT.md>`_ before contributing to help this project stay welcoming.
Installation
============
This library is **NOT** built into CircuitPython to make it easy to update. To Documentation
install it either follow the directions below or :ref:`install the library bundle <bundle_installation>`. =============
To install: For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
#. Download and unzip the `latest release zip <https://github.com/adafruit/Adafruit_CircuitPython_CharLCD/releases>`_.
#. Copy the unzipped ``adafruit_character_lcd`` to the ``lib`` directory on the ``CIRCUITPY`` or ``MICROPYTHON`` drive.
Building locally
================
To build this library locally you'll need to install the
`circuitpython-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.
.. code-block:: shell
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
.. code-block:: shell
source .env/bin/activate
Then run the build:
.. code-block:: shell
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-charlcd --library_location .
Sphinx documentation
-----------------------
Sphinx is used to build the documentation based on rST files and comments in the code. First,
install dependencies (feel free to reuse the virtual environment from above):
.. code-block:: shell
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
.. code-block:: shell
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.

View file

@ -1,3 +0,0 @@
"""include all classes"""
from adafruit_character_lcd.character_lcd import Character_LCD, Character_LCD_I2C, Character_LCD_SPI
from adafruit_character_lcd.character_lcd_rgb import Character_LCD_RGB

839
adafruit_character_lcd/character_lcd.py Normal file → Executable file
View file

@ -1,6 +1,7 @@
# The MIT License (MIT) # The MIT License (MIT)
# #
# Copyright (c) 2017 Brent Rubell for Adafruit Industries # Copyright (c) 2017 Brent Rubell for Adafruit Industries
# Copyright (c) 2018 Kattni Rembor for Adafruit Industries
# #
# Permission is hereby granted, free of charge, to any person obtaining a copy # Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal # of this software and associated documentation files (the "Software"), to deal
@ -25,19 +26,19 @@
Module for interfacing with monochromatic character LCDs Module for interfacing with monochromatic character LCDs
* Author(s): Brent Rubell, Asher Lieber, Tony DiCola (original python charLCD library) * Author(s): Kattni Rembor, Brent Rubell, Asher Lieber,
Tony DiCola (original python charLCD library)
Implementation Notes Implementation Notes
-------------------- --------------------
**Hardware:** **Hardware:**
* Adafruit `Character LCDs "* `Adafruit Character LCDs <http://www.adafruit.com/category/63_96>`_"
<http://www.adafruit.com/category/63_96>`_
**Software and Dependencies:** **Software and Dependencies:**
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards: * Adafruit CircuitPython firmware:
https://github.com/adafruit/circuitpython/releases https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library (when using I2C/SPI): * Adafruit's Bus Device library (when using I2C/SPI):
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
@ -51,67 +52,44 @@ from micropython import const
__version__ = "0.0.0-auto.0" __version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
#pylint: disable-msg=bad-whitespace # pylint: disable-msg=bad-whitespace
# Commands # Commands
LCD_CLEARDISPLAY = const(0x01) _LCD_CLEARDISPLAY = const(0x01)
LCD_RETURNHOME = const(0x02) _LCD_RETURNHOME = const(0x02)
LCD_ENTRYMODESET = const(0x04) _LCD_ENTRYMODESET = const(0x04)
LCD_DISPLAYCONTROL = const(0x08) _LCD_DISPLAYCONTROL = const(0x08)
LCD_CURSORSHIFT = const(0x10) _LCD_CURSORSHIFT = const(0x10)
LCD_FUNCTIONSET = const(0x20) _LCD_FUNCTIONSET = const(0x20)
LCD_SETCGRAMADDR = const(0x40) _LCD_SETCGRAMADDR = const(0x40)
LCD_SETDDRAMADDR = const(0x80) _LCD_SETDDRAMADDR = const(0x80)
# Entry flags # Entry flags
LCD_ENTRYRIGHT = const(0x00) _LCD_ENTRYLEFT = const(0x02)
LCD_ENTRYLEFT = const(0x02) _LCD_ENTRYSHIFTDECREMENT = const(0x00)
LCD_ENTRYSHIFTINCREMENT = const(0x01)
LCD_ENTRYSHIFTDECREMENT = const(0x00)
# Control flags # Control flags
LCD_DISPLAYON = const(0x04) _LCD_DISPLAYON = const(0x04)
LCD_DISPLAYOFF = const(0x00) _LCD_CURSORON = const(0x02)
LCD_CURSORON = const(0x02) _LCD_CURSOROFF = const(0x00)
LCD_CURSOROFF = const(0x00) _LCD_BLINKON = const(0x01)
LCD_BLINKON = const(0x01) _LCD_BLINKOFF = const(0x00)
LCD_BLINKOFF = const(0x00)
# Move flags # Move flags
LCD_DISPLAYMOVE = const(0x08) _LCD_DISPLAYMOVE = const(0x08)
LCD_CURSORMOVE = const(0x00) _LCD_MOVERIGHT = const(0x04)
LCD_MOVERIGHT = const(0x04) _LCD_MOVELEFT = const(0x00)
LCD_MOVELEFT = const(0x00)
# Function set flags # Function set flags
LCD_8BITMODE = const(0x10) _LCD_4BITMODE = const(0x00)
LCD_4BITMODE = const(0x00) _LCD_2LINE = const(0x08)
LCD_2LINE = const(0x08) _LCD_1LINE = const(0x00)
LCD_1LINE = const(0x00) _LCD_5X8DOTS = const(0x00)
LCD_5X10DOTS = const(0x04)
LCD_5X8DOTS = const(0x00)
# Offset for up to 4 rows. # Offset for up to 4 rows.
LCD_ROW_OFFSETS = (0x00, 0x40, 0x14, 0x54) _LCD_ROW_OFFSETS = (0x00, 0x40, 0x14, 0x54)
# MCP23008 I2C backpack pin mapping from LCD logical pin to MCP23008 pin. # pylint: enable-msg=bad-whitespace
_MCP23008_LCD_RS = const(1)
_MCP23008_LCD_EN = const(2)
_MCP23008_LCD_D4 = const(3)
_MCP23008_LCD_D5 = const(4)
_MCP23008_LCD_D6 = const(5)
_MCP23008_LCD_D7 = const(6)
_MCP23008_LCD_BACKLIGHT = const(7)
# 74HC595 SPI backpack pin mapping from LCD logical pin to 74HC595 pin.
_74HC595_LCD_RS = const(1)
_74HC595_LCD_EN = const(2)
_74HC595_LCD_D4 = const(6)
_74HC595_LCD_D5 = const(5)
_74HC595_LCD_D6 = const(4)
_74HC595_LCD_D7 = const(3)
_74HC595_LCD_BACKLIGHT = const(7)
#pylint: enable-msg=bad-whitespace
def _set_bit(byte_value, position, val): def _set_bit(byte_value, position, val):
# Given the specified byte_value set the bit at position to the provided # Given the specified byte_value set the bit at position to the provided
@ -121,33 +99,43 @@ def _set_bit(byte_value, position, val):
ret = byte_value | (1 << position) ret = byte_value | (1 << position)
else: else:
ret = byte_value & ~(1 << position) ret = byte_value & ~(1 << position)
return ret return ret
#pylint: disable-msg=too-many-instance-attributes
class Character_LCD(object): def _map(xval, in_min, in_max, out_min, out_max):
""" # Affine transfer/map with constrained output.
Interfaces with a character LCD outrange = float(out_max - out_min)
inrange = float(in_max - in_min)
ret = (xval - in_min) * (outrange / inrange) + out_min
if out_max > out_min:
ret = max(min(ret, out_max), out_min)
else:
ret = max(min(ret, out_min), out_max)
return ret
# pylint: disable-msg=too-many-instance-attributes
class Character_LCD:
"""Base class for character LCD.
:param ~digitalio.DigitalInOut rs: The reset data line :param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line :param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut d4: The data line 4 :param ~digitalio.DigitalInOut d4: The data line 4
:param ~digitalio.DigitalInOut d5: The data line 5 :param ~digitalio.DigitalInOut d5: The data line 5
:param ~digitalio.DigitalInOut d6: The data line 6 :param ~digitalio.DigitalInOut d6: The data line 6
:param ~digitalio.DigitalInOut d7: The data line 7 :param ~digitalio.DigitalInOut d7: The data line 7
:param cols: The columns on the charLCD :param columns: The columns on the charLCD
:param lines: The lines on the charLCD :param lines: The lines on the charLCD
:param ~digitalio.DigitalInOut backlight: The backlight pin, usually
the last pin. Check with your datasheet
""" """
#pylint: disable-msg=too-many-arguments
def __init__(self, rs, en, d4, d5, d6, d7, cols, lines,
backlight=None #,
#enable_pwm = False,
#initial_backlight = 1.0
):
self.cols = cols LEFT_TO_RIGHT = const(0)
RIGHT_TO_LEFT = const(1)
# pylint: disable-msg=too-many-arguments
def __init__(self, rs, en, d4, d5, d6, d7, columns, lines):
self.columns = columns
self.lines = lines self.lines = lines
# save pin numbers # save pin numbers
self.reset = rs self.reset = rs
@ -156,114 +144,370 @@ class Character_LCD(object):
self.dl5 = d5 self.dl5 = d5
self.dl6 = d6 self.dl6 = d6
self.dl7 = d7 self.dl7 = d7
# backlight pin
self.backlight = backlight
# self.pwn_enabled = enable_pwm
# set all pins as outputs # set all pins as outputs
for pin in(rs, en, d4, d5, d6, d7): for pin in (rs, en, d4, d5, d6, d7):
pin.direction = digitalio.Direction.OUTPUT pin.direction = digitalio.Direction.OUTPUT
# Setup backlight
if backlight is not None: # Initialise the display
self.backlight.direction = digitalio.Direction.OUTPUT
self.backlight.value = 0 # turn backlight on
# initialize the display
self._write8(0x33) self._write8(0x33)
self._write8(0x32) self._write8(0x32)
# init. display control # Initialise display control
self.displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF self.displaycontrol = _LCD_DISPLAYON | _LCD_CURSOROFF | _LCD_BLINKOFF
# init display function # Initialise display function
self.displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5X8DOTS self.displayfunction = _LCD_4BITMODE | _LCD_1LINE | _LCD_2LINE | _LCD_5X8DOTS
# init display mode # Initialise display mode
self.displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT self.displaymode = _LCD_ENTRYLEFT | _LCD_ENTRYSHIFTDECREMENT
# write to display control # Write to displaycontrol
self._write8(LCD_DISPLAYCONTROL | self.displaycontrol) self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
# write displayfunction # Write to displayfunction
self._write8(LCD_FUNCTIONSET | self.displayfunction) self._write8(_LCD_FUNCTIONSET | self.displayfunction)
# set the entry mode # Set entry mode
self._write8(LCD_ENTRYMODESET | self.displaymode) self._write8(_LCD_ENTRYMODESET | self.displaymode)
self.clear() self.clear()
#pylint: enable-msg=too-many-arguments
self._message = None
self._enable = None
self._direction = None
# track row and column used in cursor_position
# initialize to 0,0
self.row = 0
self.column = 0
self._column_align = False
# pylint: enable-msg=too-many-arguments
def home(self): def home(self):
"""Moves the cursor back home pos(1,1)""" """Moves the cursor "home" to position (1, 1)."""
self._write8(LCD_RETURNHOME) self._write8(_LCD_RETURNHOME)
time.sleep(0.003) time.sleep(0.003)
def clear(self): def clear(self):
"""Clears the LCD""" """Clears everything displayed on the LCD.
self._write8(LCD_CLEARDISPLAY)
The following example displays, "Hello, world!", then clears the LCD.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.message = "Hello, world!"
time.sleep(5)
lcd.clear()
"""
self._write8(_LCD_CLEARDISPLAY)
time.sleep(0.003) time.sleep(0.003)
def show_cursor(self, show): @property
def column_align(self):
"""If True, message text after '\\n' starts directly below start of first
character in message. If False, text after '\\n' starts at column zero.
""" """
Show or hide the cursor return self._column_align
:param show: True to show cursor, False to hide @column_align.setter
def column_align(self, enable):
""" if isinstance(enable, bool):
if show: self._column_align = enable
self.displaycontrol |= LCD_CURSORON
else: else:
self.displaycontrol &= ~LCD_DISPLAYON raise ValueError("The column_align value must be either True or False")
self._write8(LCD_DISPLAYCONTROL | self.displaycontrol)
@property
def cursor(self):
"""True if cursor is visible. False to stop displaying the cursor.
The following example shows the cursor after a displayed message:
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.cursor = True
lcd.message = "Cursor! "
time.sleep(5)
def set_cursor(self, col, row):
""" """
Sets the cursor to ``row`` and ``col`` return self.displaycontrol & _LCD_CURSORON == _LCD_CURSORON
:param col: column location @cursor.setter
:param row: row location def cursor(self, show):
if show:
self.displaycontrol |= _LCD_CURSORON
else:
self.displaycontrol &= ~_LCD_CURSORON
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
def cursor_position(self, column, row):
"""Move the cursor to position ``column``, ``row`` for the next
message only. Displaying a message resets the cursor position to (0, 0).
:param column: column location
:param row: row location
""" """
# Clamp row to the last row of the display # Clamp row to the last row of the display
if row > self.lines: if row >= self.lines:
row = self.lines - 1 row = self.lines - 1
# Clamp to last column of display
if column >= self.columns:
column = self.columns - 1
# Set location # Set location
self._write8(LCD_SETDDRAMADDR | (col + LCD_ROW_OFFSETS[row])) self._write8(_LCD_SETDDRAMADDR | (column + _LCD_ROW_OFFSETS[row]))
# Update self.row and self.column to match setter
self.row = row
self.column = column
@property
def blink(self):
"""
Blink the cursor. True to blink the cursor. False to stop blinking.
The following example shows a message followed by a blinking cursor for five seconds.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.blink = True
lcd.message = "Blinky cursor!"
time.sleep(5)
lcd.blink = False
"""
return self.displaycontrol & _LCD_BLINKON == _LCD_BLINKON
@blink.setter
def blink(self, blink): def blink(self, blink):
""" if blink:
Blinks the cursor if blink = true. self.displaycontrol |= _LCD_BLINKON
:param blink: True to blink, False no blink
"""
if blink is True:
self.displaycontrol |= LCD_BLINKON
else: else:
self.displaycontrol &= ~LCD_BLINKON self.displaycontrol &= ~_LCD_BLINKON
self._write8(LCD_DISPLAYCONTROL | self.displaycontrol) self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
@property
def display(self):
"""
Enable or disable the display. True to enable the display. False to disable the display.
The following example displays, "Hello, world!" on the LCD and then turns the display off.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.message = "Hello, world!"
time.sleep(5)
lcd.display = False
"""
return self.displaycontrol & _LCD_DISPLAYON == _LCD_DISPLAYON
@display.setter
def display(self, enable):
if enable:
self.displaycontrol |= _LCD_DISPLAYON
else:
self.displaycontrol &= ~_LCD_DISPLAYON
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
@property
def message(self):
"""Display a string of text on the character LCD.
Start position is (0,0) if cursor_position is not set.
If cursor_position is set, message starts at the set
position from the left for left to right text and from
the right for right to left text. Resets cursor column
and row to (0,0) after displaying the message.
The following example displays, "Hello, world!" on the LCD.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.message = "Hello, world!"
time.sleep(5)
"""
return self._message
@message.setter
def message(self, message):
self._message = message
# Set line to match self.row from cursor_position()
line = self.row
# Track times through iteration, to act on the initial character of the message
initial_character = 0
# iterate through each character
for character in message:
# If this is the first character in the string:
if initial_character == 0:
# Start at (0, 0) unless direction is set right to left, in which case start
# on the opposite side of the display if cursor_position not set or (0,0)
# If cursor_position is set then starts at the specified location for
# LEFT_TO_RIGHT. If RIGHT_TO_LEFT cursor_position is determined from right.
# allows for cursor_position to work in RIGHT_TO_LEFT mode
if self.displaymode & _LCD_ENTRYLEFT > 0:
col = self.column
else:
col = self.columns - 1 - self.column
self.cursor_position(col, line)
initial_character += 1
# If character is \n, go to next line
if character == "\n":
line += 1
# Start the second line at (0, 1) unless direction is set right to left in
# which case start on the opposite side of the display if cursor_position
# is (0,0) or not set. Start second line at same column as first line when
# cursor_position is set
if self.displaymode & _LCD_ENTRYLEFT > 0:
col = self.column * self._column_align
else:
if self._column_align:
col = self.column
else:
col = self.columns - 1
self.cursor_position(col, line)
# Write string to display
else:
self._write8(ord(character), True)
# reset column and row to (0,0) after message is displayed
self.column, self.row = 0, 0
def move_left(self): def move_left(self):
"""Moves display left one position""" """Moves displayed text left one column.
self._write8(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT)
The following example scrolls a message to the left off the screen.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
scroll_message = "<-- Scroll"
lcd.message = scroll_message
time.sleep(2)
for i in range(len(scroll_message)):
lcd.move_left()
time.sleep(0.5)
"""
self._write8(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT)
def move_right(self): def move_right(self):
"""Moves display right one position""" """Moves displayed text right one column.
self._write8(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT)
def set_left_to_right(self): The following example scrolls a message to the right off the screen.
"""Set direction of text to read from left to right"""
self.displaymode |= LCD_ENTRYLEFT
self._write8(LCD_ENTRYMODESET | self.displaymode)
def set_right_to_left(self): .. code-block:: python
"""Set direction of text to read from right to left"""
self.displaymode |= LCD_ENTRYLEFT
self._write8(LCD_ENTRYMODESET | self.displaymode)
def enable_display(self, enable): import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
scroll_message = "Scroll -->"
lcd.message = scroll_message
time.sleep(2)
for i in range(len(scroll_message) + 16):
lcd.move_right()
time.sleep(0.5)
""" """
Enable or disable the display. self._write8(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVERIGHT)
:param enable: True to enable display, False to disable @property
def text_direction(self):
"""The direction the text is displayed. To display the text left to right beginning on the
left side of the LCD, set ``text_direction = LEFT_TO_RIGHT``. To display the text right
to left beginning on the right size of the LCD, set ``text_direction = RIGHT_TO_LEFT``.
Text defaults to displaying from left to right.
The following example displays "Hello, world!" from right to left.
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello, world!"
time.sleep(5)
"""
return self._direction
@text_direction.setter
def text_direction(self, direction):
self._direction = direction
if direction == self.LEFT_TO_RIGHT:
self._left_to_right()
elif direction == self.RIGHT_TO_LEFT:
self._right_to_left()
def _left_to_right(self):
# Displays text from left to right on the LCD.
self.displaymode |= _LCD_ENTRYLEFT
self._write8(_LCD_ENTRYMODESET | self.displaymode)
def _right_to_left(self):
# Displays text from right to left on the LCD.
self.displaymode &= ~_LCD_ENTRYLEFT
self._write8(_LCD_ENTRYMODESET | self.displaymode)
def create_char(self, location, pattern):
"""
Fill one of the first 8 CGRAM locations with custom characters.
The location parameter should be between 0 and 7 and pattern should
provide an array of 8 bytes containing the pattern. E.g. you can easily
design your custom character at http://www.quinapalus.com/hd44780udg.html
To show your custom character use, for example, ``lcd.message = "\x01"``
:param location: integer in range(8) to store the created character
:param ~bytes pattern: len(8) describes created character
""" """
if enable: # only position 0..7 are allowed
self.displaycontrol |= LCD_DISPLAYON location &= 0x7
else: self._write8(_LCD_SETCGRAMADDR | (location << 3))
self.displaycontrol &= ~LCD_DISPLAYON for i in range(8):
self._write8(LCD_DISPLAYCONTROL | self.displaycontrol) self._write8(pattern[i], char_mode=True)
def _write8(self, value, char_mode=False): def _write8(self, value, char_mode=False):
# Sends 8b ``value`` in ``char_mode``. # Sends 8b ``value`` in ``char_mode``.
@ -298,169 +542,190 @@ class Character_LCD(object):
self.enable.value = False self.enable.value = False
time.sleep(0.0000001) time.sleep(0.0000001)
def set_backlight(self, lighton):
"""
Set lighton to turn the charLCD backlight on.
:param lighton: True to turn backlight on, False to turn off # pylint: enable-msg=too-many-instance-attributes
# pylint: disable-msg=too-many-instance-attributes
class Character_LCD_Mono(Character_LCD):
"""Interfaces with monochromatic character LCDs.
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut d4: The data line 4
:param ~digitalio.DigitalInOut d5: The data line 5
:param ~digitalio.DigitalInOut d6: The data line 6
:param ~digitalio.DigitalInOut d7: The data line 7
:param columns: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~digitalio.DigitalInOut backlight_pin: The backlight pin
:param bool backlight_inverted: ``False`` if LCD is not inverted, i.e. backlight pin is
connected to common anode. ``True`` if LCD is inverted i.e. backlight pin is connected
to common cathode.
"""
# pylint: disable-msg=too-many-arguments
def __init__(
self,
rs,
en,
db4,
db5,
db6,
db7,
columns,
lines,
backlight_pin=None,
backlight_inverted=False,
):
# Backlight pin and inversion
self.backlight_pin = backlight_pin
self.backlight_inverted = backlight_inverted
# Setup backlight
if backlight_pin is not None:
self.backlight_pin.direction = digitalio.Direction.OUTPUT
self.backlight = True
super().__init__(rs, en, db4, db5, db6, db7, columns, lines)
# pylint: enable-msg=too-many-arguments
@property
def backlight(self):
"""Enable or disable backlight. True if backlight is on. False if backlight is off.
The following example turns the backlight off, then displays, "Hello, world?", then turns
the backlight on and displays, "Hello, world!"
.. code-block:: python
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_I2C(i2c, 16, 2)
lcd.backlight = False
lcd.message = "Hello, world?"
time.sleep(5)
lcd.backlight = True
lcd.message = "Hello, world!"
time.sleep(5)
""" """
if lighton: return self._enable
self.backlight.value = 0
@backlight.setter
def backlight(self, enable):
self._enable = enable
if enable:
self.backlight_pin.value = not self.backlight_inverted
else: else:
self.backlight.value = 1 self.backlight_pin.value = self.backlight_inverted
def message(self, text): class Character_LCD_RGB(Character_LCD):
""" """Interfaces with RGB character LCDs.
Write text to display. Can include ``\\n`` for newline.
:param text: text string to display :param ~digitalio.DigitalInOut rs: The reset data line
""" :param ~digitalio.DigitalInOut en: The enable data line
line = 0 :param ~digitalio.DigitalInOut db4: The data line 4
# iterate thru each char :param ~digitalio.DigitalInOut db5: The data line 5
for char in text: :param ~digitalio.DigitalInOut db6: The data line 6
# if character is \n, go to next line :param ~digitalio.DigitalInOut db7: The data line 7
if char == '\n': :param columns: The columns on the charLCD
line += 1 :param lines: The lines on the charLCD
# move to left/right depending on text direction :param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
col = 0 if self.displaymode & LCD_ENTRYLEFT > 0 else self.cols-1 :param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
self.set_cursor(col, line) :param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
# Write character to display :param ~digitalio.DigitalInOut read_write: The rw pin. Determines whether to read to or
else: write from the display. Not necessary if only writing to the display. Used on shield.
self._write8(ord(char), True)
def create_char(self, location, pattern):
"""
Fill one of the first 8 CGRAM locations with custom characters.
The location parameter should be between 0 and 7 and pattern should
provide an array of 8 bytes containing the pattern. E.g. you can easyly
design your custom character at http://www.quinapalus.com/hd44780udg.html
To show your custom character use eg. lcd.message('\x01')
:param location: integer in range(8) to store the created character
:param ~bytes pattern: len(8) describes created character
"""
# only position 0..7 are allowed
location &= 0x7
self._write8(LCD_SETCGRAMADDR | (location << 3))
for i in range(8):
self._write8(pattern[i], char_mode=True)
#pylint: enable-msg=too-many-instance-attributes
class Character_LCD_I2C(Character_LCD):
"""Character LCD connected to I2C/SPI backpack using its I2C connection.
This is a subclass of Character_LCD and implements all of the same
functions and functionality.
""" """
def __init__(self, i2c, cols, lines): # pylint: disable-msg=too-many-arguments
"""Initialize character LCD connectedto backpack using I2C connection def __init__(
on the specified I2C bus and of the specified number of columns and self,
lines on the display. rs,
en,
db4,
db5,
db6,
db7,
columns,
lines,
red,
green,
blue,
read_write=None,
):
# Define read_write (rw) pin
self.read_write = read_write
# Setup rw pin if used
if read_write is not None:
self.read_write.direction = digitalio.Direction.OUTPUT
# define color params
self.rgb_led = [red, green, blue]
for pin in self.rgb_led:
if hasattr(pin, "direction"):
# Assume a digitalio.DigitalInOut or compatible interface:
pin.direction = digitalio.Direction.OUTPUT
elif not hasattr(pin, "duty_cycle"):
raise TypeError(
"RGB LED objects must be instances of digitalio.DigitalInOut"
" or pulseio.PWMOut, or provide a compatible interface."
)
self._color = [0, 0, 0]
super().__init__(rs, en, db4, db5, db6, db7, columns, lines)
@property
def color(self):
""" """
# Import the MCP23008 module here when the class is used The color of the display. Provide a list of three integers ranging 0 - 100, ``[R, G, B]``.
# to keep memory usage low. If you attempt to import globally at the ``0`` is no color, or "off". ``100`` is maximum color. For example, the brightest red would
# top of this file you WILL run out of memory on the M0, even with be ``[100, 0, 0]``, and a half-bright purple would be, ``[50, 0, 50]``.
# MPY files. The amount of code and classes implicitly imported
# by all the SPI and I2C code is too high. Thus import on demand.
import adafruit_character_lcd.mcp23008 as mcp23008
self._mcp = mcp23008.MCP23008(i2c)
# Setup pins for I2C backpack, see diagram:
# https://learn.adafruit.com/assets/35681
reset = self._mcp.DigitalInOut(_MCP23008_LCD_RS, self._mcp)
enable = self._mcp.DigitalInOut(_MCP23008_LCD_EN, self._mcp)
dl4 = self._mcp.DigitalInOut(_MCP23008_LCD_D4, self._mcp)
dl5 = self._mcp.DigitalInOut(_MCP23008_LCD_D5, self._mcp)
dl6 = self._mcp.DigitalInOut(_MCP23008_LCD_D6, self._mcp)
dl7 = self._mcp.DigitalInOut(_MCP23008_LCD_D7, self._mcp)
backlight = self._mcp.DigitalInOut(_MCP23008_LCD_BACKLIGHT, self._mcp)
# Call superclass initializer with MCP23008 pins.
super().__init__(reset, enable, dl4, dl5, dl6, dl7, cols, lines,
backlight=backlight)
def _write8(self, value, char_mode=False): If PWM is unavailable, ``0`` is off, and non-zero is on. For example, ``[1, 0, 0]`` would
# Optimize a command write by changing all GPIO pins at once instead be red.
# of letting the super class try to set each one invidually (far too
# slow with overhead of I2C communication).
gpio = self._mcp.gpio
# Make sure enable is low.
gpio = _set_bit(gpio, _MCP23008_LCD_EN, False)
# Set character/data bit. (charmode = False).
gpio = _set_bit(gpio, _MCP23008_LCD_RS, char_mode)
# Set upper 4 bits.
gpio = _set_bit(gpio, _MCP23008_LCD_D4, ((value >> 4) & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D5, ((value >> 5) & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D6, ((value >> 6) & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D7, ((value >> 7) & 1) > 0)
self._mcp.gpio = gpio
# Send command.
self._pulse_enable()
# Now repeat for lower 4 bits.
gpio = self._mcp.gpio
gpio = _set_bit(gpio, _MCP23008_LCD_EN, False)
gpio = _set_bit(gpio, _MCP23008_LCD_RS, char_mode)
gpio = _set_bit(gpio, _MCP23008_LCD_D4, (value & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D5, ((value >> 1) & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D6, ((value >> 2) & 1) > 0)
gpio = _set_bit(gpio, _MCP23008_LCD_D7, ((value >> 3) & 1) > 0)
self._mcp.gpio = gpio
self._pulse_enable()
The following example turns the LCD red and displays, "Hello, world!".
class Character_LCD_SPI(Character_LCD): .. code-block:: python
"""Character LCD connected to I2C/SPI backpack using its SPI connection.
This is a subclass of Character_LCD and implements all of the same
functions and functionality.
"""
def __init__(self, spi, latch, cols, lines): import time
"""Initialize character LCD connectedto backpack using SPI connection import board
on the specified SPI bus and latch line with the specified number of import busio
columns and lines on the display. import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
i2c = busio.I2C(board.SCL, board.SDA)
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, 16, 2)
lcd.color = [100, 0, 0]
lcd.message = "Hello, world!"
time.sleep(5)
""" """
# See comment above on I2C class for why this is imported here: return self._color
import adafruit_character_lcd.shift_reg_74hc595 as shift_reg_74hc595
self._sr = shift_reg_74hc595.ShiftReg74HC595(spi, latch)
# Setup pins for SPI backpack, see diagram:
# https://learn.adafruit.com/assets/35681
reset = self._sr.DigitalInOut(_74HC595_LCD_RS, self._sr)
enable = self._sr.DigitalInOut(_74HC595_LCD_EN, self._sr)
dl4 = self._sr.DigitalInOut(_74HC595_LCD_D4, self._sr)
dl5 = self._sr.DigitalInOut(_74HC595_LCD_D5, self._sr)
dl6 = self._sr.DigitalInOut(_74HC595_LCD_D6, self._sr)
dl7 = self._sr.DigitalInOut(_74HC595_LCD_D7, self._sr)
backlight = self._sr.DigitalInOut(_74HC595_LCD_BACKLIGHT, self._sr)
# Call superclass initializer with shift register pins.
super().__init__(reset, enable, dl4, dl5, dl6, dl7, cols, lines,
backlight=backlight)
def _write8(self, value, char_mode=False): @color.setter
# Optimize a command write by changing all GPIO pins at once instead def color(self, color):
# of letting the super class try to set each one invidually (far too self._color = color
# slow with overhead of SPI communication). for number, pin in enumerate(self.rgb_led):
gpio = self._sr.gpio if hasattr(pin, "duty_cycle"):
# Make sure enable is low. # Assume a pulseio.PWMOut or compatible interface and set duty cycle:
gpio = _set_bit(gpio, _74HC595_LCD_EN, False) pin.duty_cycle = int(_map(color[number], 0, 100, 65535, 0))
# Set character/data bit. (charmode = False). elif hasattr(pin, "value"):
gpio = _set_bit(gpio, _74HC595_LCD_RS, char_mode) # If we don't have a PWM interface, all we can do is turn each color
# Set upper 4 bits. # on / off. Assume a DigitalInOut (or compatible interface) and write
gpio = _set_bit(gpio, _74HC595_LCD_D4, ((value >> 4) & 1) > 0) # 0 (on) to pin for any value greater than 0, or 1 (off) for 0:
gpio = _set_bit(gpio, _74HC595_LCD_D5, ((value >> 5) & 1) > 0) pin.value = not color[number] > 1
gpio = _set_bit(gpio, _74HC595_LCD_D6, ((value >> 6) & 1) > 0)
gpio = _set_bit(gpio, _74HC595_LCD_D7, ((value >> 7) & 1) > 0)
self._sr.gpio = gpio
# Send command.
self._pulse_enable()
# Now repeat for lower 4 bits.
gpio = self._sr.gpio
gpio = _set_bit(gpio, _74HC595_LCD_EN, False)
gpio = _set_bit(gpio, _74HC595_LCD_RS, char_mode)
gpio = _set_bit(gpio, _74HC595_LCD_D4, (value & 1) > 0)
gpio = _set_bit(gpio, _74HC595_LCD_D5, ((value >> 1) & 1) > 0)
gpio = _set_bit(gpio, _74HC595_LCD_D6, ((value >> 2) & 1) > 0)
gpio = _set_bit(gpio, _74HC595_LCD_D7, ((value >> 3) & 1) > 0)
self._sr.gpio = gpio
self._pulse_enable()

View file

@ -0,0 +1,92 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Kattni Rembor for Adafruit Industries
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# 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.
"""
`adafruit_character_lcd.character_lcd_i2c`
====================================================
Module for using I2C with I2C/SPI character LCD backpack
* Author(s): Kattni Rembor
Implementation Notes
--------------------
**Hardware:**
"* `I2C / SPI character LCD backpack <https://www.adafruit.com/product/292>`_"
**Software and Dependencies:**
* Adafruit CircuitPython firmware:
https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library (when using I2C/SPI):
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
from adafruit_mcp230xx.mcp23008 import MCP23008
from adafruit_character_lcd.character_lcd import Character_LCD_Mono
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
class Character_LCD_I2C(Character_LCD_Mono):
# pylint: disable=too-few-public-methods, too-many-arguments
"""Character LCD connected to I2C/SPI backpack using its I2C connection.
This is a subclass of Character_LCD and implements all of the same
functions and functionality.
To use, import and initialise as follows:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_i2c import Character_LCD_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_I2C(i2c, 16, 2)
"""
def __init__(self, i2c, columns, lines, address=None, backlight_inverted=False):
"""Initialize character LCD connected to backpack using I2C connection
on the specified I2C bus with the specified number of columns and
lines on the display. Optionally specify if backlight is inverted.
"""
if address:
mcp = MCP23008(i2c, address=address)
else:
mcp = MCP23008(i2c)
super().__init__(
mcp.get_pin(1),
mcp.get_pin(2),
mcp.get_pin(3),
mcp.get_pin(4),
mcp.get_pin(5),
mcp.get_pin(6),
columns,
lines,
backlight_pin=mcp.get_pin(7),
backlight_inverted=backlight_inverted,
)

View file

@ -1,287 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Brent Rubell for Adafruit Industries
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# 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.
"""
`adafruit_character_lcd.character_lcd_rgb`
====================================================
Character_LCD - module for interfacing with RGB character LCDs
* Author(s):
-Brent Rubell
-Asher Lieber
-Tony DiCola for the original python charLCD library
Implementation Notes
--------------------
**Hardware:**
* Adafruit `Character LCDs
<http://www.adafruit.com/category/63_96>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library (when using I2C/SPI):
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import time
import digitalio
from micropython import const
#pylint: disable-msg=bad-whitespace
# Commands
_LCD_CLEARDISPLAY = const(0x01)
_LCD_RETURNHOME = const(0x02)
_LCD_ENTRYMODESET = const(0x04)
_LCD_DISPLAYCONTROL = const(0x08)
_LCD_CURSORSHIFT = const(0x10)
_LCD_FUNCTIONSET = const(0x20)
_LCD_SETCGRAMADDR = const(0x40)
_LCD_SETDDRAMADDR = const(0x80)
# Entry flags
_LCD_ENTRYRIGHT = const(0x00)
_LCD_ENTRYLEFT = const(0x02)
_LCD_ENTRYSHIFTINCREMENT = const(0x01)
_LCD_ENTRYSHIFTDECREMENT = const(0x00)
# Control flags
_LCD_DISPLAYON = const(0x04)
_LCD_DISPLAYOFF = const(0x00)
LCD_CURSORON = const(0x02)
_LCD_CURSOROFF = const(0x00)
_LCD_BLINKON = const(0x01)
_LCD_BLINKOFF = const(0x00)
# Move flags
_LCD_DISPLAYMOVE = const(0x08)
_LCD_CURSORMOVE = const(0x00)
_LCD_MOVERIGHT = const(0x04)
_LCD_MOVELEFT = const(0x00)
# Function set flags
_LCD_8BITMODE = const(0x10)
_LCD_4BITMODE = const(0x00)
_LCD_2LINE = const(0x08)
_LCD_1LINE = const(0x00)
_LCD_5X10DOTS = const(0x04)
_LCD_5X8DOTS = const(0x00)
# Offset for up to 4 rows.
LCD_ROW_OFFSETS = (0x00, 0x40, 0x14, 0x54)
#pylint: enable-msg=bad-whitespace
def _map(xval, in_min, in_max, out_min, out_max):
# Affine transfer/map with constrained output.
outrange = float(out_max - out_min)
inrange = float(in_max - in_min)
ret = (xval - in_min) * (outrange / inrange) + out_min
if out_max > out_min:
ret = max(min(ret, out_max), out_min)
else:
ret = max(min(ret, out_min), out_max)
return ret
#pylint: disable-msg=too-many-instance-attributes
class Character_LCD_RGB(object):
""" Interfaces with a character LCD
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut d4: The data line 4
:param ~digitalio.DigitalInOut d5: The data line 5
:param ~digitalio.DigitalInOut d6: The data line 6
:param ~digitalio.DigitalInOut d7: The data line 7
:param cols: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~pulseio.PWMOut red: Red RGB Anode
:param ~pulseio.PWMOut green: Green RGB Anode
:param ~pulseio.PWMOut blue: Blue RGB Anode
:param ~digitalio.DigitalInOut backlight: The backlight pin, usually the last pin.
Consult the datasheet. Note that Pin value 0 means backlight is lit.
"""
#pylint: disable-msg=too-many-arguments
def __init__(self, rs, en, d4, d5, d6, d7, cols, lines,
red,
green,
blue,
backlight=None #,
#enable_pwm = False,
#initial_backlight = 1.0
):
# define columns and lines
self.cols = cols
self.lines = lines
# define pin params
self.reset = rs
self.enable = en
self.dl4 = d4
self.dl5 = d5
self.dl6 = d6
self.dl7 = d7
# define color params
self.red = red
self.green = green
self.blue = blue
# define rgb led
self.rgb_led = [red, green, blue]
# define backlight pin
self.backlight = backlight
# self.pwn_enabled = enable_pwm
# set all pins as outputs
for pin in(rs, en, d4, d5, d6, d7):
pin.direction = digitalio.Direction.OUTPUT
# setup backlight
if backlight is not None:
self.backlight.direction = digitalio.Direction.OUTPUT
self.backlight.value = 0 # turn backlight on
# initialize the display
self._write8(0x33)
self._write8(0x32)
# init. display control
self.displaycontrol = _LCD_DISPLAYON | _LCD_CURSOROFF | _LCD_BLINKOFF
# init display function
self.displayfunction = _LCD_4BITMODE | _LCD_1LINE | _LCD_2LINE | _LCD_5X8DOTS
# init display mode
self.displaymode = _LCD_ENTRYLEFT | _LCD_ENTRYSHIFTDECREMENT
# write to display control
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
# write displayfunction
self._write8(_LCD_FUNCTIONSET | self.displayfunction)
# set the entry mode
self._write8(_LCD_ENTRYMODESET | self.displaymode)
self.clear()
#pylint: enable-msg=too-many-arguments
def home(self):
"""Moves the cursor back home pos(1,1)"""
self._write8(_LCD_RETURNHOME)
time.sleep(0.003)
def clear(self):
"""Clears the LCD"""
self._write8(_LCD_CLEARDISPLAY)
time.sleep(0.003)
def show_cursor(self, show):
"""Show or hide the cursor"""
if show:
self.displaycontrol |= LCD_CURSORON
else:
self.displaycontrol &= ~_LCD_DISPLAYON
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
def set_cursor(self, col, row):
"""Sets the cursor to ``row`` and ``col``
:param col: column location
:param row: row location
"""
# Clamp row to the last row of the display
if row > self.lines:
row = self.lines - 1
# Set location
self._write8(_LCD_SETDDRAMADDR | (col + LCD_ROW_OFFSETS[row]))
def enable_display(self, enable):
"""Enable or disable the display.
:param enable: True to enable display, False to disable
"""
if enable:
self.displaycontrol |= _LCD_DISPLAYON
else:
self.displaycontrol &= ~_LCD_DISPLAYON
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)
def _write8(self, value, char_mode=False):
# Sends 8b ``value`` in ``char_mode``.
# :param value: bytes
# :param char_mode: character/data mode selector. False (default) for
# data only, True for character bits.
# one ms delay to prevent writing too quickly.
time.sleep(0.001)
# set character/data bit. (charmode = False)
self.reset.value = char_mode
# WRITE upper 4 bits
self.dl4.value = ((value >> 4) & 1) > 0
self.dl5.value = ((value >> 5) & 1) > 0
self.dl6.value = ((value >> 6) & 1) > 0
self.dl7.value = ((value >> 7) & 1) > 0
# send command
self._pulse_enable()
# WRITE lower 4 bits
self.dl4.value = (value & 1) > 0
self.dl5.value = ((value >> 1) & 1) > 0
self.dl6.value = ((value >> 2) & 1) > 0
self.dl7.value = ((value >> 3) & 1) > 0
self._pulse_enable()
def _pulse_enable(self):
# Pulses (lo->hi->lo) to send commands.
self.enable.value = False
# 1microsec pause
time.sleep(0.0000001)
self.enable.value = True
time.sleep(0.0000001)
self.enable.value = False
time.sleep(0.0000001)
def set_backlight(self, lighton):
""" Set lighton to turn the charLCD backlight on.
:param lighton: True to turn backlight on, False to turn off
"""
if lighton:
self.backlight.value = 0
else:
self.backlight.value = 1
def set_color(self, color):
""" Method to set the duty cycle of the RGB LED
:param color: list of 3 integers in range(100). ``[R,G,B]`` 0 is no
color, 100 it maximum color
"""
self.rgb_led[0].duty_cycle = int(_map(color[0], 0, 100, 65535, 0))
self.rgb_led[1].duty_cycle = int(_map(color[1], 0, 100, 65535, 0))
self.rgb_led[2].duty_cycle = int(_map(color[2], 0, 100, 65535, 0))
def message(self, text):
"""Write text to display, can include \n for newline
:param text: string to display
"""
line = 0
# iterate thru each char
for char in text:
# if character is \n, go to next line
if char == '\n':
line += 1
# move to left/right depending on text direction
col = 0 if self.displaymode & _LCD_ENTRYLEFT > 0 else self.cols-1
self.set_cursor(col, line)
# Write character to display
else:
self._write8(ord(char), True)
#pylint: enable-msg=too-many-instance-attributes

View file

@ -0,0 +1,234 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Kattni Rembor for Adafruit Industries
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# 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.
"""
`adafruit_character_lcd.character_lcd_i2c`
====================================================
Module for using I2C with I2C RGB LCD Shield or I2C RGB LCD Pi Plate
* Author(s): Kattni Rembor
Implementation Notes
--------------------
**Hardware:**
"* `RGB LCD Shield Kit w/ 16x2 Character Display - Negative Display
<https://www.adafruit.com/product/714>`_"
"* `RGB LCD Shield Kit w/ 16x2 Character Display - Positive Display
<https://www.adafruit.com/product/716>`_"
"* `Adafruit RGB Negative 16x2 LCD+Keypad Kit for Raspberry Pi
<https://www.adafruit.com/product/1110>`_"
"* `Adafruit RGB Positive 16x2 LCD+Keypad Kit for Raspberry Pi
<https://www.adafruit.com/product/1109>`_"
**Software and Dependencies:**
* Adafruit CircuitPython firmware:
https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library (when using I2C/SPI):
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import digitalio
from adafruit_mcp230xx.mcp23017 import MCP23017
from adafruit_character_lcd.character_lcd import Character_LCD_RGB
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
class Character_LCD_RGB_I2C(Character_LCD_RGB):
"""RGB Character LCD connected to I2C shield or Pi plate using I2C connection.
This is a subclass of Character_LCD_RGB and implements all of the same
functions and functionality.
To use, import and initialise as follows:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
"""
def __init__(self, i2c, columns, lines, address=None):
# pylint: disable=too-many-locals
"""Initialize RGB character LCD connected to shield using I2C connection
on the specified I2C bus with the specified number of columns and lines
on the display.
"""
if address:
mcp = MCP23017(i2c, address=address)
else:
mcp = MCP23017(i2c)
self._left_button = mcp.get_pin(4)
self._up_button = mcp.get_pin(3)
self._down_button = mcp.get_pin(2)
self._right_button = mcp.get_pin(1)
self._select_button = mcp.get_pin(0)
self._buttons = [
self._left_button,
self._up_button,
self._down_button,
self._right_button,
self._select_button,
]
for pin in self._buttons:
pin.switch_to_input(pull=digitalio.Pull.UP)
super().__init__(
mcp.get_pin(15),
mcp.get_pin(13),
mcp.get_pin(12),
mcp.get_pin(11),
mcp.get_pin(10),
mcp.get_pin(9),
columns,
lines,
mcp.get_pin(6),
mcp.get_pin(7),
mcp.get_pin(8),
mcp.get_pin(14),
)
@property
def left_button(self):
"""The left button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Left!" to the LCD when the left button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.left_button:
lcd.message = "Left!"
"""
return not self._left_button.value
@property
def up_button(self):
"""The up button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Up!" to the LCD when the up button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.up_button:
lcd.message = "Up!"
"""
return not self._up_button.value
@property
def down_button(self):
"""The down button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Down!" to the LCD when the down button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.down_button:
lcd.message = "Down!"
"""
return not self._down_button.value
@property
def right_button(self):
"""The right button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Right!" to the LCD when the right button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.right_button:
lcd.message = "Right!"
"""
return not self._right_button.value
@property
def select_button(self):
"""The select button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Select!" to the LCD when the select button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.select_button:
lcd.message = "Select!"
"""
return not self._select_button.value

View file

@ -0,0 +1,100 @@
# The MIT License (MIT)
#
# Copyright (c) 2018 Kattni Rembor for Adafruit Industries
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# 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.
"""
`adafruit_character_lcd.character_lcd_spi`
====================================================
Module for using SPI with I2C/SPI character LCD backpack
* Author(s): Kattni Rembor
Implementation Notes
--------------------
**Hardware:**
"* `I2C / SPI character LCD backpack <https://www.adafruit.com/product/292>`_"
**Software and Dependencies:**
* Adafruit CircuitPython firmware:
https://github.com/adafruit/circuitpython/releases
* Adafruit's Bus Device library (when using I2C/SPI):
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
import adafruit_74hc595
from adafruit_character_lcd.character_lcd import Character_LCD_Mono
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
class Character_LCD_SPI(Character_LCD_Mono): # pylint: disable=too-few-public-methods
"""Character LCD connected to I2C/SPI backpack using its SPI connection.
This is a subclass of Character_LCD and implements all of the same
functions and functionality.
To use, import and initialise as follows:
.. code-block:: python
import board
import busio
import digitalio
import adafruit_character_lcd.character_lcd_mono as character_lcd
spi = busio.SPI(board.SCK, MOSI=board.MOSI)
latch = digitalio.DigitalInOut(board.D5)
lcd = character_lcd.Character_LCD_SPI(spi, latch, 16, 2)
"""
def __init__(self, spi, latch, columns, lines, backlight_inverted=False):
# pylint: disable=too-many-arguments
"""Initialize character LCD connected to backpack using SPI connection
on the specified SPI bus and latch line with the specified number of
columns and lines on the display. Optionally specify if backlight is
inverted.
"""
# pylint: enable=too-many-arguments
self._shift_register = adafruit_74hc595.ShiftRegister74HC595(spi, latch)
reset = self._shift_register.get_pin(1)
enable = self._shift_register.get_pin(2)
db4 = self._shift_register.get_pin(6)
db5 = self._shift_register.get_pin(5)
db6 = self._shift_register.get_pin(4)
db7 = self._shift_register.get_pin(3)
backlight_pin = self._shift_register.get_pin(7)
super().__init__(
reset,
enable,
db4,
db5,
db6,
db7,
columns,
lines,
backlight_pin=backlight_pin,
backlight_inverted=backlight_inverted,
)

View file

@ -1,169 +0,0 @@
"""
`adafruit_character_lcd.mcp23008`
=========================================
MCP23008 I2C GPIO Extender Driver
Bare-bones driver for the MCP23008 driver, as used by the character LCD
backpack. This exposes the MCP2308 and its pins as standard CircuitPython
digitalio pins. Currently this is integrated in the character LCD class for
simplicity and reduction in dependent imports, but it could be broken out
into a standalone library later.
* Author: Tony DiCola
"""
import digitalio
import adafruit_bus_device.i2c_device as i2c_device
from micropython import const
#pylint: disable-msg=bad-whitespace
# Registers and other constants:
_MCP23008_ADDRESS = const(0x20)
_MCP23008_IODIR = const(0x00)
_MCP23008_IPOL = const(0x01)
_MCP23008_GPINTEN = const(0x02)
_MCP23008_DEFVAL = const(0x03)
_MCP23008_INTCON = const(0x04)
_MCP23008_IOCON = const(0x05)
_MCP23008_GPPU = const(0x06)
_MCP23008_INTF = const(0x07)
_MCP23008_INTCAP = const(0x08)
_MCP23008_GPIO = const(0x09)
_MCP23008_OLAT = const(0x0A)
#pylint: enable-msg=bad-whitespace
class MCP23008:
"""Class-level buffer for reading and writing registers with the device.
This reduces memory allocations but makes the code non-reentrant/thread-
safe!"""
_BUFFER = bytearray(2)
class DigitalInOut:
"""Digital input/output of the MCP23008. The interface is exactly the
same as the digitalio.DigitalInOut class (however the MCP23008 does not
support pull-down resistors and an exception will be thrown
attempting to set one).
"""
def __init__(self, pin_number, mcp23008):
"""Specify the pin number of the MCP23008 (0...7) and MCP23008
instance.
"""
self._pin = pin_number
self._mcp = mcp23008
# kwargs in switch functions below are _necessary_ for compatibility
# with DigitalInout class (which allows specifying pull, etc. which
# is unused by this class). Do not remove them, instead turn off pylint
# in this case.
#pylint: disable=unused-argument
def switch_to_output(self, value=False, **kwargs):
"""DigitalInOut switch_to_output"""
self.direction = digitalio.Direction.OUTPUT
self.value = value
def switch_to_input(self, pull=None, **kwargs):
"""DigitalInOut switch_to_input"""
self.direction = digitalio.Direction.INPUT
self.pull = pull
#pylint: enable=unused-argument
@property
def value(self):
"""Get ot Set pin value: True or False"""
gpio = self._mcp.gpio
return bool(gpio & (1 << self._pin))
@value.setter
def value(self, val):
gpio = self._mcp.gpio
if val:
gpio |= (1 << self._pin)
else:
gpio &= ~(1 << self._pin)
self._mcp.gpio = gpio
@property
def direction(self):
"""Set or Get pin Directtion INPUT or OUTPUT"""
iodir = self._mcp.read_u8(_MCP23008_IODIR)
if iodir & (1 << self._pin) > 0:
return digitalio.Direction.INPUT
return digitalio.Direction.OUTPUT
@direction.setter
def direction(self, val):
iodir = self._mcp.read_u8(_MCP23008_IODIR)
if val == digitalio.Direction.INPUT:
iodir |= (1 << self._pin)
elif val == digitalio.Direction.OUTPUT:
iodir &= ~(1 << self._pin)
else:
raise ValueError('Expected INPUT or OUTPUT direction!')
self._mcp.write_u8(_MCP23008_IODIR, iodir)
@property
def pull(self):
"""Set or Get Pull UP state: only digitalio.Pull.UP is supported"""
gppu = self._mcp.read_u8(_MCP23008_GPPU)
if gppu & (1 << self._pin) > 0:
return digitalio.Pull.UP
return None
@pull.setter
def pull(self, val):
gppu = self._mcp.read_u8(_MCP23008_GPPU)
if val is None:
gppu &= ~(1 << self._pin) # Disable pull-up
elif val == digitalio.Pull.UP:
gppu |= (1 << self._pin)
elif val == digitalio.Pull.DOWN:
raise ValueError('Pull-down resistors are not supported!')
else:
raise ValueError('Expected UP, DOWN, or None for pull state!')
self._mcp.write_u8(_MCP23008_GPPU, gppu)
def __init__(self, i2c, address=_MCP23008_ADDRESS):
"""Initialize MCP23008 instance on specified I2C bus and optionally
at the specified I2C address.
"""
self._device = i2c_device.I2CDevice(i2c, address)
# Reset device state to all pins as inputs (safest option).
with self._device as device:
# Write to MCP23008_IODIR register 0xFF followed by 9 zeros
# for defaults of other registers.
device.write('\x00\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00')
def read_u8(self, register):
"""Read an unsigned 8 bit value from the specified 8-bit register."""
with self._device as i2c:
self._BUFFER[0] = register & 0xFF
i2c.write(self._BUFFER, end=1, stop=False)
i2c.readinto(self._BUFFER, end=1)
return self._BUFFER[0]
def write_u8(self, register, val):
"""Write an 8 bit value to the specified 8-bit register."""
with self._device as i2c:
self._BUFFER[0] = register & 0xFF
self._BUFFER[1] = val & 0xFF
i2c.write(self._BUFFER)
@property
def gpio(self):
"""Get and set the raw GPIO output register. Each bit represents the
output value of the associated pin (0 = low, 1 = high), assuming that
pin has been configured as an output previously.
"""
return self.read_u8(_MCP23008_GPIO)
@gpio.setter
def gpio(self, val):
self.write_u8(_MCP23008_GPIO, val)

View file

@ -1,110 +0,0 @@
"""
`adafruit_character_led.shift_reg_74hc595`
===============================================
74HC595 Serial to Paralllel Shift Register Driver
Bare-bones driver for the 74HC595, as used by the character LCD
backpack. This exposes the 74HC595 and its pins as standard CircuitPython
digitalio pins. Currently this is integrated in the character LCD class for
simplicity and reduction in dependent imports, but it could be broken out
into a standalone library later.
* Author: Tony DiCola
"""
import digitalio
import adafruit_bus_device.spi_device as spi_device
#pylint: disable-msg=too-few-public-methods
#pylint: disable-msg=no-self-use
class ShiftReg74HC595:
"""Shift Register 74LS95 driver class"""
class DigitalInOut:
"""Digital input/output of the 74HC595. The interface is exactly the
same as the digitalio.DigitalInOut class, however note that by design
this device is OUTPUT ONLY! Attempting to read inputs or set
direction as input will raise an exception.
"""
def __init__(self, pin_number, shift_reg_74ls595):
"""Specify the pin number of the shift register (0...7) and
ShiftReg74HC595 instance.
"""
self._pin = pin_number
self._sr = shift_reg_74ls595
# kwargs in switch functions below are _necessary_ for compatibility
# with DigitalInout class (which allows specifying pull, etc. which
# is unused by this class). Do not remove them, instead turn off pylint
# in this case.
#pylint: disable=unused-argument
def switch_to_output(self, value=False, **kwargs):
"""DigitalInOut switch_to_output"""
self.direction = digitalio.Direction.OUTPUT
self.value = value
def switch_to_input(self, **kwargs):
"""do not call switch_to_input"""
raise RuntimeError('Unable to use 74HC595 as digital input!')
#pylint: enable=unused-argument
@property
def value(self):
"""do not call value"""
raise RuntimeError('Unable to use 74HC595 as digital input!')
@value.setter
def value(self, val):
# Only supported operation, writing a digital output.
gpio = self._sr.gpio
if val:
gpio |= (1 << self._pin)
else:
gpio &= ~(1 << self._pin)
self._sr.gpio = gpio
@property
def direction(self):
"""ALWAYS an output!"""
return digitalio.Direction.OUTPUT
@direction.setter
def direction(self, val):
"""Can only be set as OUTPUT!"""
if val != digitalio.Direction.OUTPUT:
raise RuntimeError('Unable to use 74HC595 as digital input!')
@property
def pull(self):
"""Pull-up/down not supported, return NonLiberty e for no pull-up/down."""
return None
@pull.setter
def pull(self, val):
"""Only supports null/no pull state."""
if val is not None:
raise RuntimeError('Unable to set 74HC595 pull!')
def __init__(self, spi, latch):
self._device = spi_device.SPIDevice(spi, latch, baudrate=1000000)
self._gpio = bytearray(1)
self._gpio[0] = 0x00
@property
def gpio(self):
"""Get and set the raw GPIO output register. Each bit represents the
output value of the associated pin (0 = low, 1 = high).
"""
return self._gpio[0]
@gpio.setter
def gpio(self, val):
self._gpio[0] = val & 0xFF
with self._device as spi:
# pylint: disable=no-member
spi.write(self._gpio)
#pylint: enable-msg=no-self-use
#pylint: enable-msg=too-few-public-methods

View file

@ -2,4 +2,13 @@
.. If you created a package, create one automodule per module in the package. .. If you created a package, create one automodule per module in the package.
.. automodule:: adafruit_character_lcd.character_lcd .. automodule:: adafruit_character_lcd.character_lcd
:members: :members:
.. automodule:: adafruit_character_lcd.character_lcd_i2c
:members:
.. automodule:: adafruit_character_lcd.character_lcd_spi
:members:
.. automodule:: adafruit_character_lcd.character_lcd_rgb_i2c
:members:

View file

@ -2,7 +2,8 @@
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
@ -10,9 +11,9 @@ sys.path.insert(0, os.path.abspath('..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.intersphinx', "sphinx.ext.intersphinx",
'sphinx.ext.viewcode', "sphinx.ext.viewcode",
] ]
# Uncomment the below if you use native CircuitPython modules such as # Uncomment the below if you use native CircuitPython modules such as
@ -20,29 +21,36 @@ extensions = [
# autodoc module docs will fail to generate with a warning. # autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["micropython", "digitalio", "addfruit_bus_device"] # autodoc_mock_imports = ["micropython", "digitalio", "addfruit_bus_device"]
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
None,
),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
source_suffix = '.rst' source_suffix = ".rst"
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = "index"
# General information about the project. # General information about the project.
project = u'Adafruit CIRCUITPYTHON_CHARLCD Library' project = "Adafruit CIRCUITPYTHON_CHARLCD Library"
copyright = u'2017 Brent Rubell' copyright = "2017 Brent Rubell"
author = u'Brent Rubell' author = "Brent Rubell"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'1.0' version = "1.0"
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'1.0' release = "1.0"
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -54,7 +62,7 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path # This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
# The reST default role (used for this markup: `text`) to use for all # The reST default role (used for this markup: `text`) to use for all
# documents. # documents.
@ -66,7 +74,7 @@ default_role = "any"
add_function_parentheses = True add_function_parentheses = True
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing. # If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False todo_include_todos = False
@ -80,59 +88,62 @@ todo_emit_warnings = True
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
# #
on_rtd = os.environ.get('READTHEDOCS', None) == 'True' on_rtd = os.environ.get("READTHEDOCS", None) == "True"
if not on_rtd: # only import and set the theme if we're building docs locally if not on_rtd: # only import and set the theme if we're building docs locally
try: try:
import sphinx_rtd_theme import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
except: except:
html_theme = 'default' html_theme = "default"
html_theme_path = ['.'] html_theme_path = ["."]
else: else:
html_theme_path = ['.'] html_theme_path = ["."]
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ["_static"]
# The name of an image file (relative to this directory) to use as a favicon of # The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large. # pixels large.
# #
html_favicon = '_static/favicon.ico' html_favicon = "_static/favicon.ico"
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitCIRCUITPYTHON_CHARLCDLibrarydoc' htmlhelp_basename = "AdafruitCIRCUITPYTHON_CHARLCDLibrarydoc"
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
latex_elements = { latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
# #
# 'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# The font size ('10pt', '11pt' or '12pt'). #
# # 'pointsize': '10pt',
# 'pointsize': '10pt', # Additional stuff for the LaTeX preamble.
#
# Additional stuff for the LaTeX preamble. # 'preamble': '',
# # Latex figure (float) alignment
# 'preamble': '', #
# 'figure_align': 'htbp',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
} }
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, 'AdafruitCIRCUITPYTHON_CHARLCDLibrary.tex', u'Adafruit CIRCUITPYTHON_CHARLCD Library Documentation', (
author, 'manual'), master_doc,
"AdafruitCIRCUITPYTHON_CHARLCDLibrary.tex",
"Adafruit CIRCUITPYTHON_CHARLCD Library Documentation",
author,
"manual",
),
] ]
# -- Options for manual page output --------------------------------------- # -- Options for manual page output ---------------------------------------
@ -140,8 +151,13 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
(master_doc, 'adafruitCIRCUITPYTHON_CHARLCDlibrary', u'Adafruit CIRCUITPYTHON_CHARLCD Library Documentation', (
[author], 1) master_doc,
"adafruitCIRCUITPYTHON_CHARLCDlibrary",
"Adafruit CIRCUITPYTHON_CHARLCD Library Documentation",
[author],
1,
)
] ]
# -- Options for Texinfo output ------------------------------------------- # -- Options for Texinfo output -------------------------------------------
@ -150,7 +166,13 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'AdafruitCIRCUITPYTHON_CHARLCDLibrary', u'Adafruit CIRCUITPYTHON_CHARLCD Library Documentation', (
author, 'AdafruitCIRCUITPYTHON_CHARLCDLibrary', 'One line description of project.', master_doc,
'Miscellaneous'), "AdafruitCIRCUITPYTHON_CHARLCDLibrary",
"Adafruit CIRCUITPYTHON_CHARLCD Library Documentation",
author,
"AdafruitCIRCUITPYTHON_CHARLCDLibrary",
"One line description of project.",
"Miscellaneous",
),
] ]

View file

@ -11,10 +11,14 @@ Ensure your device works with this simple test.
:caption: examples/charlcd_rgb_simpletest.py :caption: examples/charlcd_rgb_simpletest.py
:linenos: :linenos:
.. literalinclude:: ../examples/charlcd_I2C_simpletest.py .. literalinclude:: ../examples/charlcd_i2c_mono_simpletest.py
:caption: examples/charlcd_I2C_simpletest.py :caption: examples/charlcd_i2c_mono_simpletest.py
:linenos: :linenos:
.. literalinclude:: ../examples/charlcd_SPI_simpletest.py .. literalinclude:: ../examples/charlcd_spi_mono_simpletest.py
:caption: examples/charlcd_SPI_simpletest.py :caption: examples/charlcd_spi_mono_simpletest.py
:linenos: :linenos:
.. literalinclude:: ../examples/charlcd_keypad_simpletest.py
:caption: examples/charlcd_keypad_simpletest.py
:linenos:

View file

@ -1,50 +0,0 @@
# Hello World using 16x2 character lcd and an MCP23008 I2C LCD backpack.
import time
import board
import busio
import adafruit_character_lcd
# Character LCD Config:
# modify this if you have a different sized charlcd
lcd_columns = 16
lcd_rows = 2
# Initialize I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Init the lcd class
lcd = adafruit_character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
# Print a 2x line message
lcd.message('hello\ncircuitpython')
# Wait 5s
time.sleep(5)
# Demo showing cursor
lcd.clear()
lcd.show_cursor(True)
lcd.message('showing cursor ')
# Wait 5s
time.sleep(5)
# Demo showing the blinking cursor
lcd.clear()
lcd.blink(True)
lcd.message('Blinky Cursor!')
# Wait 5s
time.sleep(5)
lcd.blink(False)
# Demo scrolling message LEFT
lcd.clear()
scroll_msg = 'Scroll'
lcd.message(scroll_msg)
# Scroll to the left
for i in range(lcd_columns - len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
# Demo turning backlight off
lcd.clear()
lcd.message("going to sleep\ncya later!")
lcd.set_backlight(False)
time.sleep(2)

View file

@ -1,57 +0,0 @@
# Hello World using 16x2 character lcd and an 74LS595 SPI LCD backpack.
import time
import board
import busio
import digitalio
import adafruit_character_lcd
# Character LCD Config:
# modify this if you have a different sized charlcd
lcd_columns = 16
lcd_rows = 2
# Backpack connection configuration:
clk = board.SCK # Pin connected to backpack CLK.
data = board.MOSI # Pin connected to backpack DAT/data.
latch = board.D5 # Pin connected to backpack LAT/latch.
# Initialize SPI bus.
spi = busio.SPI(clk, MOSI=data)
# Init the lcd class
latch = digitalio.DigitalInOut(latch)
lcd = adafruit_character_lcd.Character_LCD_SPI(spi, latch, lcd_columns, lcd_rows)
# Print a 2x line message
lcd.message('hello\ncircuitpython')
# Wait 5s
time.sleep(5)
# Demo showing cursor
lcd.clear()
lcd.show_cursor(True)
lcd.message('showing cursor ')
# Wait 5s
time.sleep(5)
# Demo showing the blinking cursor
lcd.clear()
lcd.blink(True)
lcd.message('Blinky Cursor!')
# Wait 5s
time.sleep(5)
lcd.blink(False)
# Demo scrolling message LEFT
lcd.clear()
scroll_msg = 'Scroll'
lcd.message(scroll_msg)
# Scroll to the left
for i in range(lcd_columns - len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
# Demo turning backlight off
lcd.clear()
lcd.message("going to sleep\ncya later!")
lcd.set_backlight(False)
time.sleep(2)

View file

@ -1,19 +1,26 @@
"""Use custom characters to display Nyan cat"""
import time import time
from board import D7, D8, D9, D10, D11, D12, D13 import board
import digitalio import digitalio
import adafruit_character_lcd import adafruit_character_lcd.character_lcd as characterlcd
# Modify this if you have a different sized character LCD
lcd_columns = 16 lcd_columns = 16
lcd_rows = 2 lcd_rows = 2
lcd_rs = digitalio.DigitalInOut(D7)
lcd_en = digitalio.DigitalInOut(D8) # Metro M0/M4 Pin Config:
lcd_d7 = digitalio.DigitalInOut(D12) lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_d6 = digitalio.DigitalInOut(D11) lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d5 = digitalio.DigitalInOut(D10) lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d4 = digitalio.DigitalInOut(D9) lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_backlight = digitalio.DigitalInOut(D13) lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd_backlight = digitalio.DigitalInOut(board.D13)
# Initialise the LCD class
lcd = characterlcd.Character_LCD_Mono(
lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
)
head = [31, 17, 27, 17, 17, 21, 17, 31] head = [31, 17, 27, 17, 17, 21, 17, 31]
@ -65,30 +72,21 @@ lcd.create_char(7, tail_neutral)
lcd.clear() lcd.clear()
body_width = 3
lcd.move_right() lcd.move_right()
for i in range(4): lcd.message = (
lcd.message('\x02') "\x02\x02\x02\x02\x01\x00\x00\x00\x06\n\x02\x02\x02\x07\x03\x04\x04\x04\x05"
lcd.message('\x01') )
for i in range(body_width):
lcd.message('\x00') lcd.backlight = True
lcd.message('\x06')
lcd.message('\n')
lcd.message('\x02\x02\x02')
lcd.message('\x07')
lcd.message('\x03')
for i in range(body_width):
lcd.message('\x04')
lcd.message('\x05')
while True: while True:
lcd.create_char(4, bot_body2) lcd.create_char(4, bot_body2)
lcd.create_char(7, tail_up) lcd.create_char(7, tail_up)
lcd.create_char(2, rainbow2) lcd.create_char(2, rainbow2)
lcd.move_right() lcd.move_right()
time.sleep(.4) time.sleep(0.4)
lcd.create_char(4, bot_body) lcd.create_char(4, bot_body)
lcd.create_char(7, tail_neutral) lcd.create_char(7, tail_neutral)
lcd.create_char(2, rainbow) lcd.create_char(2, rainbow)
lcd.move_left() lcd.move_left()
time.sleep(.4) time.sleep(0.4)

View file

@ -0,0 +1,30 @@
"""Display a custom character"""
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2
# Metro M0/M4 Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_backlight = digitalio.DigitalInOut(board.D13)
# Initialise the LCD class
lcd = characterlcd.Character_LCD_Mono(
lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
)
checkmark = bytes([0x0, 0x0, 0x1, 0x3, 0x16, 0x1C, 0x8, 0x0])
# Store in LCD character memory 0
lcd.create_char(0, checkmark)
lcd.clear()
lcd.message = "\x00"

View file

@ -0,0 +1,57 @@
"""Simple test for 16x2 character lcd connected to an MCP23008 I2C LCD backpack."""
import time
import board
import busio
import adafruit_character_lcd.character_lcd_i2c as character_lcd
# Modify this if you have a different sized Character LCD
lcd_columns = 16
lcd_rows = 2
# Initialise I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Initialise the lcd class
lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
# Turn backlight on
lcd.backlight = True
# Print a two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll message to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()
lcd.message = "Going to sleep\nCya later!"
time.sleep(5)
# Turn backlight off
lcd.backlight = False
time.sleep(2)

View file

@ -0,0 +1,69 @@
"""Simple test for I2C RGB character LCD shield kit"""
import time
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
# Modify this if you have a different sized Character LCD
lcd_columns = 16
lcd_rows = 2
# Initialise I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Initialise the LCD class
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
lcd.clear()
# Set LCD color to red
lcd.color = [100, 0, 0]
time.sleep(1)
# Print two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Set LCD color to blue
lcd.color = [0, 100, 0]
time.sleep(1)
# Set LCD color to green
lcd.color = [0, 0, 100]
time.sleep(1)
# Set LCD color to purple
lcd.color = [50, 0, 50]
time.sleep(1)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()
time.sleep(1)
lcd.message = "Going to sleep\nCya later!"
time.sleep(5)
# Turn off LCD backlights and clear text
lcd.color = [0, 0, 0]
lcd.clear()

View file

@ -0,0 +1,42 @@
"""Simple test for keypad on I2C RGB character LCD Shield or Pi Plate kits"""
import time
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
# Modify this if you have a different sized Character LCD
lcd_columns = 16
lcd_rows = 2
# Initialise I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Initialise the LCD class
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
lcd.clear()
lcd.color = [100, 0, 0]
while True:
if lcd.left_button:
print("Left!")
lcd.message = "Left!"
elif lcd.up_button:
print("Up!")
lcd.message = "Up!"
elif lcd.down_button:
print("Down!")
lcd.message = "Down!"
elif lcd.right_button:
print("Right!")
lcd.message = "Right!"
elif lcd.select_button:
print("Select!")
lcd.message = "Select!"
else:
time.sleep(0.1)
lcd.clear()

View file

@ -1,61 +1,65 @@
""" """Simple test for monochromatic character LCD"""
'hello_CircuitPython.py'
=================================================
hello world using 16x2 character lcd
requires:
- CircuitPython_CharLCD Module
"""
import time import time
from board import D7, D8, D9, D10, D11, D12, D13 import board
import digitalio import digitalio
import adafruit_character_lcd import adafruit_character_lcd.character_lcd as characterlcd
# Character LCD Config: # Modify this if you have a different sized character LCD
# modify this if you have a different sized charlcd
lcd_columns = 16 lcd_columns = 16
lcd_rows = 2 lcd_rows = 2
# Metro m0 Pin Config: # Metro M0/M4 Pin Config:
lcd_rs = digitalio.DigitalInOut(D7) lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(D8) lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(D12) lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(D11) lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(D10) lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(D9) lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_backlight = digitalio.DigitalInOut(D13) lcd_backlight = digitalio.DigitalInOut(board.D13)
# Init the lcd class # Initialise the LCD class
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd = characterlcd.Character_LCD_Mono(
lcd_d7, lcd_columns, lcd_rows, lcd_backlight) lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
)
# Print a 2x line message # Turn backlight on
lcd.message('hello\ncircuitpython') lcd.backlight = True
# Print a two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s # Wait 5s
time.sleep(5) time.sleep(5)
# Demo showing cursor
lcd.clear() lcd.clear()
lcd.show_cursor(True) # Print two line message right to left
lcd.message('showing cursor ') lcd.text_direction = lcd.RIGHT_TO_LEFT
# Wait 5s lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5) time.sleep(5)
# Demo showing the blinking cursor # Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear() lcd.clear()
lcd.blink(True) lcd.cursor = True
lcd.message('Blinky Cursor!') lcd.message = "Cursor! "
# Wait 5s # Wait 5s
time.sleep(5) time.sleep(5)
lcd.blink(False) # Display blinking cursor
# Demo scrolling message LEFT
lcd.clear() lcd.clear()
scroll_msg = 'Scroll' lcd.blink = True
lcd.message(scroll_msg) lcd.message = "Blinky Cursor!"
# Scroll to the left # Wait 5s
for i in range(lcd_columns - len(scroll_msg)): time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll message to the left
for i in range(len(scroll_msg)):
time.sleep(0.5) time.sleep(0.5)
lcd.move_left() lcd.move_left()
# Demo turning backlight off
lcd.clear() lcd.clear()
lcd.message("going to sleep\ncya later!") lcd.message = "Going to sleep\nCya later!"
lcd.set_backlight(False) time.sleep(3)
# Turn backlight off
lcd.backlight = False
time.sleep(2) time.sleep(2)

View file

@ -1,43 +1,90 @@
"""Simple test for RGB character LCD"""
import time import time
from board import D3, D4, D5, D7, D8, D9, D10, D11, D12, D13 import board
import digitalio import digitalio
import adafruit_character_lcd
import pulseio import pulseio
import adafruit_character_lcd.character_lcd as characterlcd
# Character LCD Config: # Modify this if you have a different sized character LCD
# modify this if you have a different sized charlcd
lcd_columns = 16 lcd_columns = 16
lcd_rows = 2 lcd_rows = 2
# Metro m0 Pin Config: # Metro M0/M4 Pin Config:
lcd_rs = digitalio.DigitalInOut(D7) lcd_rs = digitalio.DigitalInOut(board.D7)
lcd_en = digitalio.DigitalInOut(D8) lcd_en = digitalio.DigitalInOut(board.D8)
lcd_d7 = digitalio.DigitalInOut(D12) lcd_d7 = digitalio.DigitalInOut(board.D12)
lcd_d6 = digitalio.DigitalInOut(D11) lcd_d6 = digitalio.DigitalInOut(board.D11)
lcd_d5 = digitalio.DigitalInOut(D10) lcd_d5 = digitalio.DigitalInOut(board.D10)
lcd_d4 = digitalio.DigitalInOut(D9) lcd_d4 = digitalio.DigitalInOut(board.D9)
lcd_backlight = digitalio.DigitalInOut(D13) red = pulseio.PWMOut(board.D3)
red = pulseio.PWMOut(D3) green = pulseio.PWMOut(board.D5)
green = pulseio.PWMOut(D4) blue = pulseio.PWMOut(board.D6)
blue = pulseio.PWMOut(D5)
# Init the lcd class # Initialise the LCD class
lcd = adafruit_character_lcd.Character_LCD_RGB(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd = characterlcd.Character_LCD_RGB(
lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_rs,
red, green, blue, lcd_backlight) lcd_en,
lcd_d4,
lcd_d5,
lcd_d6,
lcd_d7,
lcd_columns,
lcd_rows,
red,
green,
blue,
)
#pylint: disable-msg=bad-whitespace lcd.clear()
# only red # Set LCD color to red
RED = [100, 0, 0] lcd.color = [100, 0, 0]
GREEN = [0, 100, 0] time.sleep(1)
BLUE = [0, 0, 100] # Print two line message
#pylint: enable-msg=bad-whitespace lcd.message = "Hello\nCircuitPython"
# Wait 5s
while True: time.sleep(5)
lcd.message('CircuitPython\nRGB Test') # Set LCD color to blue
lcd.set_color(RED) lcd.color = [0, 100, 0]
time.sleep(1) time.sleep(1)
lcd.set_color(GREEN) # Set LCD color to green
time.sleep(1) lcd.color = [0, 0, 100]
lcd.set_color(BLUE) time.sleep(1)
time.sleep(1) # Set LCD color to purple
lcd.color = [50, 0, 50]
time.sleep(1)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()
time.sleep(1)
lcd.message = "Going to sleep\nCya later!"
time.sleep(5)
# Turn off LCD backlights and clear text
lcd.color = [0, 0, 0]
lcd.clear()

View file

@ -0,0 +1,64 @@
"""Simple test for monochromatic character LCD on Raspberry Pi"""
import time
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2
# Raspberry Pi Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D26)
lcd_en = digitalio.DigitalInOut(board.D19)
lcd_d7 = digitalio.DigitalInOut(board.D27)
lcd_d6 = digitalio.DigitalInOut(board.D22)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_backlight = digitalio.DigitalInOut(board.D4)
# Initialise the lcd class
lcd = characterlcd.Character_LCD_Mono(
lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight
)
# Turn backlight on
lcd.backlight = True
# Print a two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll message to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()
lcd.message = "Going to sleep\nCya later!"
# Turn backlight off
lcd.backlight = False
time.sleep(2)

View file

@ -0,0 +1,58 @@
"""Simple test for RGB character LCD on Raspberry Pi"""
import time
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2
# Raspberry Pi Pin Config:
lcd_rs = digitalio.DigitalInOut(board.D26) # pin 4
lcd_en = digitalio.DigitalInOut(board.D19) # pin 6
lcd_d7 = digitalio.DigitalInOut(board.D27) # pin 14
lcd_d6 = digitalio.DigitalInOut(board.D22) # pin 13
lcd_d5 = digitalio.DigitalInOut(board.D24) # pin 12
lcd_d4 = digitalio.DigitalInOut(board.D25) # pin 11
lcd_backlight = digitalio.DigitalInOut(board.D4)
red = digitalio.DigitalInOut(board.D21)
green = digitalio.DigitalInOut(board.D12)
blue = digitalio.DigitalInOut(board.D18)
# Initialise the LCD class
lcd = characterlcd.Character_LCD_RGB(
lcd_rs,
lcd_en,
lcd_d4,
lcd_d5,
lcd_d6,
lcd_d7,
lcd_columns,
lcd_rows,
red,
green,
blue,
lcd_backlight,
)
RED = [1, 0, 0]
GREEN = [0, 1, 0]
BLUE = [0, 0, 1]
while True:
lcd.clear()
lcd.message = "CircuitPython\nRGB Test: RED"
lcd.color = RED
time.sleep(1)
lcd.clear()
lcd.message = "CircuitPython\nRGB Test: GREEN"
lcd.color = GREEN
time.sleep(1)
lcd.clear()
lcd.message = "CircuitPython\nRGB Test: BLUE"
lcd.color = BLUE
time.sleep(1)

View file

@ -0,0 +1,63 @@
"""Simple test for 16x2 character LCD connected to 74HC595 SPI LCD backpack."""
import time
import board
import busio
import digitalio
import adafruit_character_lcd.character_lcd_spi as character_lcd
# Modify this if you have a different sized character LCD
lcd_columns = 16
lcd_rows = 2
# Backpack connection configuration:
clk = board.SCK # Pin connected to backpack CLK.
data = board.MOSI # Pin connected to backpack DAT/data.
latch = board.D5 # Pin connected to backpack LAT/latch.
# Initialise SPI bus.
spi = busio.SPI(clk, MOSI=data)
# Initialise the LCD class
latch = digitalio.DigitalInOut(latch)
lcd = character_lcd.Character_LCD_SPI(spi, latch, lcd_columns, lcd_rows)
# Turn backlight on
lcd.backlight = True
# Print a two line message
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
lcd.clear()
# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT
# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)
# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()
# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll message to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()
lcd.message = "Going to sleep\nCya later!"
# Turn backlight off
lcd.backlight = False
time.sleep(2)

View file

@ -1,19 +0,0 @@
import digitalio
from board import D7, D8, D9, D10, D11, D12, D13
import adafruit_character_lcd
lcd_columns = 16
lcd_rows = 2
lcd_rs = digitalio.DigitalInOut(D7)
lcd_en = digitalio.DigitalInOut(D8)
lcd_d7 = digitalio.DigitalInOut(D12)
lcd_d6 = digitalio.DigitalInOut(D11)
lcd_d5 = digitalio.DigitalInOut(D10)
lcd_d4 = digitalio.DigitalInOut(D9)
lcd_backlight = digitalio.DigitalInOut(D13)
lcd = adafruit_character_lcd.Character_LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6,
lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
checkmark = bytes([0x0, 0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0])
lcd.clear()
lcd.message('\x00')

View file

@ -1,2 +1,4 @@
Adafruit-Blinka
adafruit-circuitpython-74hc595
adafruit-circuitpython-busdevice adafruit-circuitpython-busdevice
Adafruit-Blinka adafruit-circuitpython-mcp230xx

View file

@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
# Always prefer setuptools over distutils # Always prefer setuptools over distutils
from setuptools import setup, find_packages from setuptools import setup, find_packages
# To use a consistent encoding # To use a consistent encoding
from codecs import open from codecs import open
from os import path from os import path
@ -14,47 +15,43 @@ from os import path
here = path.abspath(path.dirname(__file__)) here = path.abspath(path.dirname(__file__))
# Get the long description from the README file # Get the long description from the README file
with open(path.join(here, 'README.rst'), encoding='utf-8') as f: with open(path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read() long_description = f.read()
setup( setup(
name='adafruit-circuitpython-charlcd', name="adafruit-circuitpython-charlcd",
use_scm_version=True, use_scm_version=True,
setup_requires=['setuptools_scm'], setup_requires=["setuptools_scm"],
description="CircuitPython library for standard character LCDs.",
description='CircuitPython library for standard character LCDs.',
long_description=long_description, long_description=long_description,
long_description_content_type='text/x-rst', long_description_content_type="text/x-rst",
# The project's main homepage. # The project's main homepage.
url='https://github.com/adafruit/Adafruit_CircuitPython_CharLCD', url="https://github.com/adafruit/Adafruit_CircuitPython_CharLCD",
# Author details # Author details
author='Adafruit Industries', author="Adafruit Industries",
author_email='circuitpython@adafruit.com', author_email="circuitpython@adafruit.com",
install_requires=[
install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'], "Adafruit-Blinka",
"adafruit-circuitpython-74hc595",
"adafruit-circuitpython-busdevice",
"adafruit-circuitpython-mcp230xx",
],
# Choose your license # Choose your license
license='MIT', license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[ classifiers=[
'Development Status :: 3 - Alpha', "Development Status :: 3 - Alpha",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'Topic :: Software Development :: Libraries', "Topic :: Software Development :: Libraries",
'Topic :: System :: Hardware', "Topic :: System :: Hardware",
'License :: OSI Approved :: MIT License', "License :: OSI Approved :: MIT License",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.4', "Programming Language :: Python :: 3.4",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
], ],
# What does your project relate to? # What does your project relate to?
keywords='adafruit character lcd rgb 16x2 20x4 hardware micropython circuitpython', keywords="adafruit character lcd rgb 16x2 20x4 hardware micropython circuitpython",
# You can just specify the packages manually here if your project is # You can just specify the packages manually here if your project is
# simple. Or you can use find_packages(). # simple. Or you can use find_packages().
packages=['adafruit_character_lcd'], packages=["adafruit_character_lcd"],
) )