|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2019 Gaston Williams |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in |
| 13 | +# all copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | +# THE SOFTWARE. |
| 22 | +""" |
| 23 | +`sparkfun_serlcd` |
| 24 | +================================================================================ |
| 25 | +
|
| 26 | +CircuitPython driver library for the Sparkfun Serial LCD displays |
| 27 | +
|
| 28 | +
|
| 29 | +* Author(s): Gaston Williams |
| 30 | +
|
| 31 | +* Based on the Arduino library for the Sparkfun SerLCD displays |
| 32 | + Written by Gaston Williams, August 22, 2018 |
| 33 | +* Based on sample code provided with the SparkFun Serial OpenLCD display. |
| 34 | + The original LiquidCrystal library was written by David A. Mellis and |
| 35 | + modified by Limor Fried @ Adafruit and the OpenLCD code was written by |
| 36 | + Nathan Seidle @ SparkFun. |
| 37 | +
|
| 38 | +
|
| 39 | +Implementation Notes |
| 40 | +-------------------- |
| 41 | +
|
| 42 | +**Hardware:** |
| 43 | +
|
| 44 | +* This is library is for the SparkFun Serial LCD displays |
| 45 | +* SparkFun sells these at its website: www.sparkfun.com |
| 46 | +* Do you like this library? Help support SparkFun. Buy a board! |
| 47 | +* 16x2 SerLCD Black on RGB https://www.sparkfun.com/products/14072 |
| 48 | +* 16x2 SerLCD RGB on Black https://www.sparkfun.com/products/14073 |
| 49 | +* 20x4 SerLCD Black on RGB https://www.sparkfun.com/products/14074 |
| 50 | +
|
| 51 | +**Software and Dependencies:** |
| 52 | +
|
| 53 | +* Adafruit CircuitPython firmware for the supported boards: |
| 54 | + https://github.com/adafruit/circuitpython/releases |
| 55 | +
|
| 56 | +* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice |
| 57 | +""" |
| 58 | + |
| 59 | +__version__ = "0.0.0-auto.0" |
| 60 | +__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git" |
| 61 | + |
| 62 | +# imports |
| 63 | +// from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3 |
| 64 | +from time import sleep |
| 65 | +from micropython import const |
| 66 | +from sparkfun_serlcd.py import Sparkfun_SerLCD: |
| 67 | + |
| 68 | + |
| 69 | +# public constants |
| 70 | +DEFAULT_I2C_ADDR = const(0x72) |
| 71 | +"""Default I2C address for SerLCD""" |
| 72 | + |
| 73 | +# sparkfun_serlcd_i2c.py |
| 74 | +class Sparkfun_SerLCD_i2c(Sparkfun_SerLCD): |
| 75 | +"""Sparkfun SerLCD connected to I2C |
| 76 | +This is a subclass of 'Sparkfun_SerLCD' and implements |
| 77 | +all of the same functions. |
| 78 | +
|
| 79 | +""" |
| 80 | + |
| 81 | +def __init__(self, i2c, columns, lines, address=None): |
| 82 | + |
| 83 | + |
| 84 | +def set_i2c_address(self, new_address): |
| 85 | + """Change the I2C Address. 0x72 is the default. |
| 86 | + Note that this change is persistent. If anything goes wrong |
| 87 | + you may need to do a hardware reset to unbrick the display. |
| 88 | +
|
| 89 | + byte new_addr - new i2c address""" |
| 90 | + # Mask new address to byte |
| 91 | + new_address &= 0x00FF |
| 92 | + # Transmit to device on old address |
| 93 | + data = bytearray() |
| 94 | + # Send contrast command |
| 95 | + data.append(_SETTING_COMMAND) |
| 96 | + data.append(_ADDRESS_COMMAND) # 0x19 |
| 97 | + data.append(new_address) |
| 98 | + self._write_bytes(data) |
| 99 | + # Update our own address so we can still talk to the display |
| 100 | + self._change_i2c_address(new_address) |
| 101 | + |
| 102 | + # This may take awhile |
| 103 | + sleep(0.050) |
0 commit comments