def runExample(): print("\nSparkFun Qwiic SerLCD Example 8\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() time.sleep(1) # give a sec for system messages to complete while True: myLCD.setCursor(0, 0) # set the cursor to (0,0) for thisChar in range(10): # print from 0 to 9 myLCD.print(str(thisChar)) time.sleep(0.5) myLCD.autoscroll() # set the display to automatically scroll for thisChar in range(0, 10): # print from 0 to 9 myLCD.setCursor(10 + thisChar, 1) myLCD.print(str(thisChar)) time.sleep(0.5) myLCD.noAutoscroll() # turn off automatic scrolling myLCD.clearScreen() # clear screen for the next loop
def runExample(): print("\nSparkFun Qwiic SerLCD Example 12\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete while True: # promt the user to input some text user_input = input("Please type something to display on the LCD: ") myLCD.clearScreen() # clear the screen myLCD.print(user_input) # print what the user just typed in time.sleep(0.5) # wait a second
def runExample(): print("\nSparkFun Qwiic SerLCD Example 17\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd(address=old_address) print("Attemping to connect to %s..." % hex(myLCD.address)) if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return else: print("Connected!") myLCD.setBacklight(255, 255, 255) # bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete myLCD.clearScreen() myLCD.setAddress( new_address ) # note this updates class member myLCD.address to the new_address if myLCD.connected == True: print("Address changed to %s successfully!" % hex(myLCD.address)) myLCD.clearScreen() myLCD.print("My new add: %s" % hex(myLCD.address)) else: print("Address change failed :(") while True: time.sleep(1) # do nothing
def runExample(): print("\nSparkFun Qwiic SerLCD Example 9\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() time.sleep(1) # give a sec for system messages to complete # make some custom characters: heart = [ 0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000 ] smiley = [ 0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000 ] frownie = [ 0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b00000, 0b01110, 0b10001 ] armsDown = [ 0b00100, 0b01010, 0b00100, 0b00100, 0b01110, 0b10101, 0b00100, 0b01010 ] armsUp = [ 0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010 ] myLCD.createChar(0, heart) myLCD.createChar(1, smiley) myLCD.createChar(2, frownie) myLCD.createChar(3, armsDown) myLCD.createChar(4, armsUp) myLCD.setCursor(0, 0) # set cursor to the top left # Print a message to the LCD. myLCD.print("I ") myLCD.writeChar(0) # Print the heart character, stored in location 0 myLCD.print(" SerLCD! ") myLCD.writeChar(1) # Print smiley while True: myLCD.setCursor(4, 1) # column, row myLCD.writeChar(3) # print little man, arms down time.sleep(0.2) myLCD.setCursor(4, 1) # column, row myLCD.writeChar(4) # print little man, arms up time.sleep(0.2)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 13\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete while True: myLCD.setFastBacklight(255, 0, 0) # bright red myLCD.clearScreen() myLCD.print("Red") time.sleep(1) myLCD.setFastBacklight(0xFF, 0x8C, 0x00) # orange myLCD.clearScreen() myLCD.print("Orange") time.sleep(1)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 6\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.clearScreen() myLCD.cursor() # Turn on the underline cursor time.sleep(1) # give a sec for system messages to complete myLCD.print("Hello World!") while True: # turn off the blinking cursor print("Cursor blinking OFF") myLCD.noBlink() time.sleep(5) # turn on the blinking cursor print("Cursor blinking ON") myLCD.blink() time.sleep(5)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 10\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete # Print a message to the LCD. myLCD.print("Hello World!") while True: myLCD.display() #turn on display time.sleep(1) myLCD.noDisplay() # turn off display time.sleep(1)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 15\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete myLCD.disableSystemMessages( ) # Now whenever you change a system setting like Contrast, # SerLCD will not display the setting. This makes changing the setting faster, and also # invisible to the user. #myLCD.enableSystemMessages() # This will re-enable the printing of system messages myLCD.clearScreen() myLCD.print("Hello World!") counter = 0 while True: # do something that would normally cause a system message # let's change color of backlight values every other count value if (counter % 2) == 0: myLCD.setBacklight(255, 0, 0) else: myLCD.setBacklight(0, 255, 0) time.sleep(0.1) # give it a sec to change backlight print("counter: %d" % counter) myLCD.setCursor(0, 1) myLCD.print(str(counter)) counter = counter + 1 time.sleep(1)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 4\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.clearScreen() myLCD.cursor() # Turn on the underline cursor time.sleep(1) # give a sec for system messages to complete myLCD.print("Watch the cursor!") while True: # move cursor left with three function calls myLCD.moveCursorLeft() time.sleep(0.5) myLCD.moveCursorLeft() time.sleep(0.5) myLCD.moveCursorLeft() time.sleep(0.5) # move curor right three spaces in one function call myLCD.moveCursorRight(3) # notice the optional count argument of "3" time.sleep(0.5) # move cursor left three spaces in one function call myLCD.moveCursorLeft(3) time.sleep(0.5) # move cursor right with three function calls myLCD.moveCursorRight() time.sleep(0.5) myLCD.moveCursorRight() time.sleep(0.5) myLCD.moveCursorRight() time.sleep(0.5)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 16\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete myLCD.clearScreen() myLCD.print("Tea-O-Matic") time.sleep(1) myLCD.saveSplash( ) # save this current text as the splash screen at next power up myLCD.enableSplash( ) # This will cause the splash to be displayed at power on #myLCD.disableSplash() # This will supress the splash from being displayed at power on counter = 0 myLCD.clearScreen() myLCD.print("Cups of tea: ") while True: print("counter: %d" % counter) myLCD.setCursor(0, 1) myLCD.print(str(counter)) counter = counter + 1 time.sleep(1)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 3\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.clearScreen() time.sleep(1) # give a sec for system messages to complete # These constants won't change. But you can change the size of # your LCD using them: numRows = 2 # numRows = 4 numCols = 16 # numCols = 20 thisLetter = "a" while True: randomColumn = random.randint(0, numCols) randomRow = random.randint(0, numRows) # set the cursor position: myLCD.setCursor(randomColumn, randomRow) # print the letter: myLCD.print(thisLetter) # print to screen time.sleep(0.2) thisLetter = chr(ord(thisLetter) + 1) if thisLetter > "z": thisLetter = "a" # Wrap the variable
def runExample(): print("\nSparkFun Qwiic SerLCD Example 7\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.clearScreen() time.sleep(1) # give a sec for system messages to complete myLCD.print("Hello World!") while True: # scroll 13 positions (string length) to the left # to move it offscreen left: for i in range(13): myLCD.scrollDisplayLeft() # scroll one position left time.sleep(0.15) # wait a bit # scroll 29 positions (string length + display length) to the right # to move it offscreen right: for i in range(29): myLCD.scrollDisplayRight() # scroll one position right time.sleep(0.15) # wait a bit # scroll 16 positions (display length + string length) to the left # to move it back to center: for i in range(16): myLCD.scrollDisplayLeft() # scroll one position left time.sleep(0.15) # wait a bit time.sleep(1) # delay at the end of the full loop
def runExample(): print("\nSparkFun Qwiic SerLCD Example 14\n") print("\nType CTRL+C to end.\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.noCursor() time.sleep(1) # give a sec for system messages to complete while True: myLCD.command( ord(',')) # send the comma to display the frimware version time.sleep( 0.5 ) # Firmware will be displayed for 500ms, so keep re-printing it
def runExample(): print("\nSparkFun Qwiic SerLCD Example 11\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. myLCD.begin() # call this for default settings (no myLCD.leftToRight() myLCD.cursor() time.sleep(1) # give a sec for system messages to complete thisChar = 'a' while True: if thisChar == 'j': # reverse directions at 'm' myLCD.rightToLeft() # go right for the next letter if thisChar == 'q': # reverse again at 's' myLCD.leftToRight() # go left for the next letter time.sleep(1) if thisChar > 'z': # reset at 'z' myLCD.home() # go to (0,0) myLCD.clearScreen() # clear screen thisChar = 'a' # start again at 0 myLCD.print(thisChar) # print the character time.sleep(0.5) # wait a second thisChar = chr(ord(thisChar) + 1) # increment the letter
def runExample(): print("\nSparkFun SerLCD and 9DoF ICM-20948 Sensor Example\n") myLCD = qwiic_serlcd.QwiicSerlcd() IMU = qwiic_icm20948.QwiicIcm20948() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return if IMU.connected == False: print("The Qwiic ICM20948 device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # Set contrast. Lower to 0 for higher contrast. myLCD.clearScreen( ) # Clear Screen - this moves the cursor to the home position as well myLCD.print("white") # Write to color name to SerLCD time.sleep(0.5) # give a sec for system messages to complete IMU.begin() while True: #declare ledColor a global variable inside here to access it global ledColor if IMU.dataReady(): IMU.getAgmt( ) # read all axis and temp from sensor, note this also updates all instance variables #the following are the threshold values for each axis is pointing right-side up # anything above IMU.azRaw > 16000 is red # ledColor = 1 aZPos = 16000 # anything below IMU.azRaw < -16000 is blue # ledColor = 2 aZNeg = -16000 # anything above IMU.ayRaw > 16100 is green # ledColor = 3 ayPos = 16100 # anything below IMU.ayRaw < -16000 is green # ledColor = 4 ayNeg = -16000 # anything above IMU.axRaw > 16000 is magenta # ledColor = 5 axPos = 16000 # anything below IMU.axRaw < -16400 is cyan # ledColor = 6 axNeg = -16400 #adjust color of the LED based on the accelerometer's reading if IMU.azRaw > aZPos: # Set LED red myLCD.setBacklight(255, 0, 0) # Set backlight to bright white ledColor = 1 myLCD.clearScreen() myLCD.print("red") elif IMU.azRaw < aZNeg: # Set LED blue myLCD.setBacklight(0, 0, 255) # Set backlight to bright white ledColor = 2 myLCD.clearScreen() myLCD.print("blue") elif IMU.ayRaw > ayPos: # Set LED yellow myLCD.setBacklight(255, 255, 0) # Set backlight to bright white ledColor = 3 myLCD.clearScreen() myLCD.print("yellow") elif IMU.ayRaw < ayNeg: # Set LED green myLCD.setBacklight(0, 255, 0) # Set backlight to bright white ledColor = 4 myLCD.clearScreen() myLCD.print("green") elif IMU.axRaw > axPos: # Set LED magenta myLCD.setBacklight(255, 0, 255) # Set backlight to bright white ledColor = 5 myLCD.clearScreen() myLCD.print("magenta") elif IMU.axRaw < axNeg: # Set LED cyan myLCD.setBacklight(0, 255, 255) # Set backlight to bright white ledColor = 6 myLCD.clearScreen() myLCD.print("cyan") if ledColor == 1: print("ledColor = red", '\n', '\n') elif ledColor == 2: print("ledColor = blue", '\n', '\n') elif ledColor == 3: print("ledColor = yellow", '\n', '\n') elif ledColor == 4: print("ledColor = green", '\n', '\n') elif ledColor == 5: print("ledColor = magenta", '\n', '\n') elif ledColor == 6: print("ledColor = cyan", '\n', '\n') aX = IMU.axRaw aY = IMU.ayRaw aZ = IMU.azRaw gX = IMU.gxRaw gY = IMU.gyRaw gZ = IMU.gzRaw mX = IMU.mxRaw mY = IMU.myRaw mZ = IMU.mzRaw # Remove the `#` for the following lines to # display accelerometer readings on SerLCD #myLCD.setCursor(8,0) #myLCD.print("aX") #myLCD.print(str(aX)) #myLCD.setCursor(0,1) #myLCD.print("aY") #myLCD.print(str(aY)) #myLCD.setCursor(8,1) #myLCD.print("aZ") #myLCD.print(str(aZ)) print(\ ' aX:', '{: 4.1f}'.format(aX)\ , ' \t, aY:', '{: 4.1f}'.format(aY)\ , '\t, aZ:', '{: 4.1f}'.format(aZ)\ , '\n gX:', '{: 4.1f}'.format(gX)\ , '\t, gY:', '{: 4.1f}'.format(gY)\ , '\t, gZ:', '{: 4.1f}'.format(gZ)\ , '\n mX:', '{: 4.1f}'.format(mX)\ , '\t, mY:', '{: 4.1f}'.format(mY)\ , '\t, mZ:', '{: 4.1f}'.format(mZ)\ , '\n'\ ) time.sleep(1) # small delay so that the screen doesn't flicker else: print("Waiting for data") time.sleep(0.5)
def runExample(): print("\nSparkFun Qwiic SerLCD Example 2\n") myLCD = qwiic_serlcd.QwiicSerlcd() if myLCD.connected == False: print("The Qwiic SerLCD device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myLCD.setBacklight(255, 255, 255) # Set backlight to bright white myLCD.setContrast(5) # set contrast. Lower to 0 for higher contrast. time.sleep(1) # give a sec for system messages to complete while True: myLCD.setBacklight(0, 0, 0) # black is off myLCD.clearScreen( ) # Clear the display - this moves the cursor to home position as well myLCD.print("Black (off)") time.sleep(5) myLCD.setBacklight(255, 0, 0) # bright red myLCD.clearScreen() myLCD.print("Red") time.sleep(5) myLCD.setBacklight(0xFF, 0x8C, 0x00) # orange myLCD.clearScreen() myLCD.print("Orange") time.sleep(5) myLCD.setBacklight(255, 255, 0) # bright yellow myLCD.clearScreen() myLCD.print("Yellow") time.sleep(5) myLCD.setBacklight(0, 255, 0) # bright green myLCD.clearScreen() myLCD.print("Green") time.sleep(5) myLCD.setBacklight(0, 0, 255) # bright blue myLCD.clearScreen() myLCD.print("Blue") time.sleep(5) myLCD.setBacklight(0x4B, 0x00, 0x82) # indigo, a kind of dark purplish blue myLCD.clearScreen() myLCD.print("Indigo") time.sleep(5) myLCD.setBacklight(0xA0, 0x20, 0xF0) # violet myLCD.clearScreen() myLCD.print("Violet") time.sleep(5) myLCD.setBacklight(0x80, 0x80, 0x80) # grey myLCD.clearScreen() myLCD.print("Grey") time.sleep(5) myLCD.setBacklight(255, 255, 255) # bright white myLCD.clearScreen() myLCD.print("White") time.sleep(5)