Last active
April 26, 2021 16:37
-
-
Save Neradoc/dbbbf8890f6f9dccf198b8b8127c18f9 to your computer and use it in GitHub Desktop.
I2C tests with the Sparkfun SerLCD qwiic LCD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is a test for an error on the Sparkfun SerLCD | |
> OSError: [Errno 19] Unsupported operation | |
Tested on: | |
- QT PY RP2040 using the STEMMA QT port | |
- SparkFun 16x2 SerLCD - RGB Backlight (Qwiic) | |
The errors seems to happen when many writes are done in fast succession. | |
DELAY = 0 -> Almost always errors at a seemingly random number of characters. | |
DELAY = 0.001 -> Seems to completely remove the error. | |
""" | |
import board | |
import busio | |
import random | |
import time | |
DELAY = 0.001 # 0 | |
STRING_LEN = 1 | |
TEST_STRING = chr(random.randint(ord("A"),ord("z"))) * STRING_LEN | |
NUM_WRITES = 32 | |
i2c = busio.I2C(sda=board.SDA1, scl=board.SCL1) | |
try: | |
while not i2c.try_lock(): i2c.unlock() | |
i2c.writeto(0x72,"|-") # clear | |
for x in range(NUM_WRITES): | |
time.sleep(DELAY) | |
i2c.writeto(0x72,TEST_STRING) | |
i2c.unlock() | |
print("GOOD") | |
except Exception as ex: | |
import sys | |
sys.print_exception(ex) | |
print("BAD",x) | |
finally: | |
i2c.deinit() | |
print("FIN") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment