Simple test

Ensure your device works with this simple test.

examples/qwiictwist_simpletest.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Twist RGB Rotary Encoder.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Simple Test - qwiictwist_simpletest.py
12 Written by Gaston Williams, June 19th, 2019
13 The Qwiic Twist is a I2C controlled RGB Rotary Encoder
14
15 Simple Test:
16 This program uses the Qwiic Twist CircuitPython Library to change
17 that status of the Qwiic Twist Rotary Encoder.
18"""
19import sys
20from time import sleep
21import board
22import sparkfun_qwiictwist
23
24# Create bus object using our board's I2C port
25i2c = board.I2C()
26
27# Create joystick object
28twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
29
30# Check if connected
31if twist.connected:
32    print("Twist connected.")
33else:
34    print("Twist does not appear to be connected. Please check wiring.")
35    sys.exit()
36
37# Print firmware version and current status
38print("Firmware version " + twist.version)
39
40# Turn the relay on and off
41print("Press Ctrl-C to exit program")
42
43try:
44    while True:
45        print("Count: " + str(twist.count))
46        if twist.pressed:
47            print("Pressed!")
48        sleep(0.5)
49
50except KeyboardInterrupt:
51    pass

Examples

  1. Basic Readings - Print number of steps knob has been twisted.

examples/example1_basic_readings.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 1 - example1_basic_readings.py
12 Written by Gaston Williams, June 19th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 1 - Basic Readings:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C and print
20 the number of steps the encoder has been twisted.
21"""
22import sys
23from time import sleep
24import board
25import sparkfun_qwiictwist
26
27# Create bus object using our board's I2C port
28i2c = board.I2C()
29
30# Create twist object
31twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
32
33print("Qwicc Twist Example 1 Basic Readings")
34
35# Check if connected
36if twist.connected:
37    print("Twist connected.")
38else:
39    print("Twist does not appear to be connected. Please check wiring.")
40    sys.exit()
41
42print("Type Ctrl-C to exit program.")
43
44try:
45    while True:
46        print("Count: " + str(twist.count))
47        if twist.pressed:
48            print("Pressed!")
49        sleep(0.5)
50
51except KeyboardInterrupt:
52    pass
  1. Set Color - Set the knob color.

examples/example2_set_color.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 2 - example2_set_color.py
12 Written by Gaston Williams, June 20th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 2 - Set Color:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to set
20 the knob color to pink.  This value is stored in the Qwiic Twist
21 and will be loaded after each power-on.
22"""
23import sys
24from time import sleep
25import board
26import sparkfun_qwiictwist
27
28# Create bus object using our board's I2C port
29i2c = board.I2C()
30
31# Create twist object
32twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
33
34print("Qwicc Twist Example 2 Set Color")
35
36# Check if connected
37if twist.connected:
38    print("Twist connected.")
39else:
40    print("Twist does not appear to be connected. Please check wiring.")
41    sys.exit()
42
43print("Type Ctrl-C to exit program.")
44
45# Turn off any color connections
46twist.connect_color(0, 0, 0)
47
48# Set the knob color to pink (r =100, g=10, b=50)
49twist.set_color(100, 10, 50)
50
51# Set a flag to toggle color
52is_pink = True
53
54try:
55    while True:
56        print("Count: " + str(twist.count))
57        if twist.pressed:
58            print("Pressed!")
59            if is_pink:
60                # Set the knob color to blue (r =10, g=10, b=100)
61                print("Change color to blue.")
62                twist.set_color(10, 10, 100)
63                is_pink = False
64            else:
65                # Set the knob color to pink (r =100, g=10, b=50)
66                print("Change color to pink.")
67                twist.set_color(100, 10, 50)
68                is_pink = True
69
70        sleep(0.2)
71
72except KeyboardInterrupt:
73    pass
  1. Crazy Color - Set the knob to random colors.

examples/example3_crazy_color.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 3 - example3_crazy_color.py
12 Written by Gaston Williams, June 20th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 3 - Crazy Color:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to set
20 the knob color to an endless number of random colors.
21"""
22import sys
23from time import sleep
24import random
25
26import board
27import sparkfun_qwiictwist
28
29# Create bus object using our board's I2C port
30i2c = board.I2C()
31
32# Create twist object
33twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
34
35print("Qwicc Twist Example 3 Crazy Color")
36
37# Check if connected
38if twist.connected:
39    print("Twist connected.")
40else:
41    print("Twist does not appear to be connected. Please check wiring.")
42    sys.exit()
43
44print("Type Ctrl-C to exit program.")
45
46# Turn off any color connections
47twist.connect_color(0, 0, 0)
48
49try:
50    while True:
51        print("Count: " + str(twist.count))
52        if twist.pressed:
53            print("Pressed!")
54
55        # Generate a random rgb value
56        red = random.randint(0, 256)
57        green = random.randint(0, 256)
58        blue = random.randint(0, 256)
59        twist.set_color(red, green, blue)
60
61        sleep(0.1)
62
63except KeyboardInterrupt:
64    pass
  1. Connect Color - Change the knob color as it is twisted.

examples/example4_connect_colors.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 4 - example4_connect_colors.py
12 Written by Gaston Williams, June 19th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 4 - Connect Colors:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to make
20 the knob change color as the user turns the device.
21 We don't have to send a setColor() or setRed() command each time,
22 Qwiic Twist can  change its color independently of the master.
23 By connecting a -10 value to red, the red LED will go down 10 in
24 brightness with each encoder tick. Connecting 10 to blue will
25 increase the blue value with each tick.  These values are stored
26 in the Qwiic Twist and will be loaded after each power-on.
27"""
28import sys
29from time import sleep
30import board
31import sparkfun_qwiictwist
32
33# Create bus object using our board's I2C port
34i2c = board.I2C()
35
36# Create twist object
37twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
38
39print("Qwicc Twist Example 4 Connect Colors")
40
41# Check if connected
42if twist.connected:
43    print("Twist connected.")
44else:
45    print("Twist does not appear to be connected. Please check wiring.")
46    sys.exit()
47
48print("Type Ctrl-C to exit program.")
49
50# Set Red and Blue LED brightnesses to half of max.
51twist.set_color(128, 0, 128)
52
53# Set the individual color connections
54
55# Red LED will go down 10 in brightness with each encoder tick
56twist.red_connection = -10
57# Blue LED will go up 10 in brightness with each encoder tick
58twist.blue_connection = 10
59
60# Or use the function below to set all color connections at once
61# twist.connect_color(-10, 0, 10)
62
63try:
64    while True:
65        print("Count: " + str(twist.count))
66        if twist.pressed:
67            print("Pressed!")
68        sleep(0.5)
69
70except KeyboardInterrupt:
71    pass
  1. Timestamps - Show timestamps for when knob is twisted or pressed.

examples/example5_timestamps.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 5 - example5_timestamps.py
12 Written by Gaston Williams, June 21st, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 5 - Timestamps:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to display
20 the time between when the user did an action (such as twist
21 knob or press button) and when we queried the device. You don't
22 need to constantly poll the Qwiic Twist to see if the user has
23 twisted the knob or pressed the button. Instead, check every so
24 often and when the isMoved or isClick goes true, then read the
25 timestamp and you'll know when the user did their thing.
26"""
27import sys
28from time import sleep
29import board
30import sparkfun_qwiictwist
31
32# Create bus object using our board's I2C port
33i2c = board.I2C()
34
35# Create twist object
36twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
37
38print("Qwicc Twist Example 5 Timestamps")
39
40# Check if connected
41if twist.connected:
42    print("Twist connected.")
43else:
44    print("Twist does not appear to be connected. Please check wiring.")
45    sys.exit()
46
47print("Type Ctrl-C to exit program.")
48
49try:
50    while True:
51        print("Count: " + str(twist.count))
52        if twist.moved:
53            print("Last Twist time: " + str(twist.time_since_last_movement))
54        if twist.clicked:
55            print("Last Button time: " + str(twist.time_since_last_press))
56        if twist.pressed:
57            print("Pressed!")
58        sleep(1)
59
60except KeyboardInterrupt:
61    pass
  1. Difference - Show the diffence between encoder counts when knob is twisted.

examples/example6_difference.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 6 - example6_difference.py
12 Written by Gaston Williams, June 19th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 6 - Difference:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to display
20 the difference since the last reading. This is helpful if you
21 don't care what the cumulative value is, just difference.
22
23 Things like volume control, brightness, etc. your system may
24 not need to know an absolute value like 417, but instead that
25 the user has  moved the encoder 4 ticks since the last reading.
26"""
27import sys
28from time import sleep
29import board
30import sparkfun_qwiictwist
31
32# Create bus object using our board's I2C port
33i2c = board.I2C()
34
35# Create twist object
36twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
37
38print("Qwicc Twist Example 6 Difference")
39
40# Check if connected
41if twist.connected:
42    print("Twist connected.")
43else:
44    print("Twist does not appear to be connected. Please check wiring.")
45    sys.exit()
46
47print("Type Ctrl-C to exit program.")
48
49try:
50    while True:
51        print("Count: " + str(twist.count))
52        print("Difference: " + str(twist.difference))
53        sleep(0.250)
54
55except KeyboardInterrupt:
56    pass
  1. Set Count - Change the encoder count reported when knob is twisted.

examples/example7_set_count.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 7 - example7_set_count.py
12 Written by Gaston Williams, June 21st, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 7 - Set Count:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C to set
20 the encoder count. There are times when it's necessary encoder
21 count to a specific value. Useful when the encoder value is mapped directly
22 onto a volume setting, FM freq, etc.
23"""
24import sys
25from time import sleep
26import board
27import sparkfun_qwiictwist
28
29# Create bus object using our board's I2C port
30i2c = board.I2C()
31
32# Create twist object
33twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
34
35print("Qwicc Twist Example 7 Set Count")
36
37# Check if connected
38if twist.connected:
39    print("Twist connected.")
40else:
41    print("Twist does not appear to be connected. Please check wiring.")
42    sys.exit()
43
44# Set initial value to 1000. Not stored to non-volatile memory.
45twist.count = 1000
46
47print("Type Ctrl-C to exit program.")
48
49try:
50    while True:
51        print("Count: " + str(twist.count))
52        print("Difference: " + str(twist.difference))
53        sleep(0.250)
54
55except KeyboardInterrupt:
56    pass
  1. Interrupts - Enable button and twist interrupts.

examples/example8_interruptst.py
 1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 2#
 3# SPDX-License-Identifier: MIT
 4
 5#  This is example is for the SparkFun Qwiic Single Twist.
 6#  SparkFun sells these at its website: www.sparkfun.com
 7#  Do you like this library? Help support SparkFun. Buy a board!
 8#  https://www.sparkfun.com/products/15083
 9
10"""
11 Qwiic Twist Example 8 - example8_interrupts.py
12 Written by Gaston Williams, June 19th, 2019
13 Based on Arduino code written by
14 Nathan Seidle @ Sparkfun, December 3rd, 2018
15 The Qwiic Twist is an I2C controlled RGB Rotary Encoder produced by sparkfun
16
17 Example 8 - Interrupts:
18 This program uses the Qwiic Twist CircuitPython Library to
19 control the Qwiic Twist RGB Rotrary Encoder over I2C  to enable
20 the button and twist interrupts. Once an interrupt is read,
21 it is cleared by the library. For this example you will need to
22 connect the INT pin on Qwiic to GPIO D6 on the Raspberry Pi.
23
24 The interrupt will not fire until 250ms after the user has stopped
25 turning the encoder. This is so the master is not overwhelmed with
26  interrupts while the user is still turning the dial.
27"""
28import sys
29import board
30import digitalio
31import sparkfun_qwiictwist
32
33# Create bus object using our board's I2C port
34i2c = board.I2C()
35
36# Set up Interrupt pin on GPIO D6 with a pull-up resistor
37twist_interrupt_pin = digitalio.DigitalInOut(board.D6)
38twist_interrupt_pin.direction = digitalio.Direction.INPUT
39twist_interrupt_pin.pull = digitalio.Pull.UP
40
41# Create twist object
42twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c)
43
44print("Qwicc Twist Example 8 Interrupts")
45
46# Check if connected
47if twist.connected:
48    print("Twist connected.")
49else:
50    print("Twist does not appear to be connected. Please check wiring.")
51    sys.exit()
52
53# Optional: You can modify the time between when the user has stopped turning
54# and when interrupt is raised
55
56# Set twist timeout to 500ms before interrupt assertion
57# twist.int_timeout = 500
58
59print("Type Ctrl-C to exit program.")
60
61try:
62    while True:
63        # When the interrupt goes low
64        if not twist_interrupt_pin.value:
65            print("Interrupt:")
66            if twist.moved:
67                print("Count: " + str(twist.count))
68            if twist.pressed:
69                print("Pressed!")
70            if twist.clicked:
71                print("Clicked!")
72            twist.clear_interrupts()
73
74except KeyboardInterrupt:
75    pass
  1. Change I2C Address - Change the device I2C address.

examples/example9_change_i2c_address.py
  1# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
  2#
  3# SPDX-License-Identifier: MIT
  4
  5#  This is example is for the SparkFun Qwiic Twist.
  6#  SparkFun sells these at its website: www.sparkfun.com
  7#  Do you like this library? Help support SparkFun. Buy a board!
  8#  https://www.sparkfun.com/products/15083
  9
 10"""
 11  Qwiic Twist Example 9 - example9_change_i2c_address.py
 12  Written by Gaston Williams, June 13th, 2019
 13  Based on Arduino code written by
 14  Nathan Seidle @ SparkFun Electronics, December 3rd
 15, 2019
 16  The Qwiic Twist is an I2C controlled RGB Rotary Encoder
 17
 18  Example 9 - Change I2C Address and Read Firmware Version:
 19  This program uses the Qwiic Twist CircuitPython Library to change
 20  the I2C address for the device. You enter in the DEC value (8-119) or
 21
 22  HEX value (0x08-0x77) for the new Twist address.  The address is
 23  changed and the firmware version is printed out to validate the connection.
 24  You can run example10+i2c_scanner.py to validate the address after the change.
 25
 26  Syntax: python3 change_i2c_address.py [address]
 27    where address is an optional address value in decimal or hex
 28    The default value for the address is 63 [0x3F]
 29"""
 30
 31import sys
 32import board
 33import sparkfun_qwiictwist
 34
 35# The default QwiicTwist i2c address is 0x3F (63)
 36i2c_address = 0x3F
 37
 38# print('Arguement count: ' , len(sys.argv))
 39# print('List: ' + str(sys.argv))
 40
 41# If we were passed an arguement, then use it as the address
 42if len(sys.argv) > 1:
 43    try:
 44        # check to see if hex or decimal arguement
 45        if "0x" in sys.argv[1]:
 46            i2c_address = int(sys.argv[1], 16)
 47        else:
 48            i2c_address = int(sys.argv[1])
 49    except ValueError:
 50        print("Ignoring invalid arguement: " + str(sys.argv[1]))
 51
 52# Show the initial address
 53print("Current i2c address = " + str(i2c_address) + " [" + hex(i2c_address) + "]")
 54
 55# Create bus object using our Board I2C port
 56i2c = board.I2C()
 57twist = sparkfun_qwiictwist.Sparkfun_QwiicTwist(i2c, i2c_address)
 58
 59if twist.connected:
 60    print("Qwiic Twist Example.")
 61else:
 62    # if we can't connecct, something is wrong so just quit
 63    print("Twist does not appear to be connected. Please check wiring.")
 64    sys.exit()
 65
 66print(
 67    "Address: "
 68    + str(i2c_address)
 69    + " ["
 70    + hex(i2c_address)
 71    + "]"
 72    + " Version: "
 73    + twist.version
 74)
 75
 76text = input(
 77    "Enter a new I2C address (as a decimal from 8 to 119 or hex 0x08 to 0x77):"
 78)
 79
 80# check to see if hex or decimal value
 81if "0x" in text:
 82    new_address = int(text, 16)
 83else:
 84    new_address = int(text)
 85
 86print("Changing address to " + str(new_address) + " [" + hex(new_address) + "]")
 87
 88result = twist.change_address(new_address)
 89
 90if result:
 91    print("Address changed to " + str(new_address) + " [" + hex(new_address) + "]")
 92    # After the change check the new connection and show firmware version
 93    if twist.connected:
 94        print("Connected to Twist after address change.")
 95        print("Firmware Version: " + twist.version)
 96    else:
 97        print("Error after address change. Cannot connect to Twist.")
 98
 99else:
100    print("Address change failed.")
101
102# good advice whether the address changed worked or not
103print("Run example10_i2c_scanner.py to verify the Qwiic Twist address.")
  1. I2C Scanner - Scan the IC2 bus for devices.

examples/example10_i2c_scanner.py
 1# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
 2# SPDX-FileCopyrightText: Copyright (c) 2019-2021 Gaston Williams
 3#
 4# SPDX-License-Identifier: MIT
 5
 6#  This is example is for the SparkFun Qwiic Twist.
 7#  SparkFun sells these at its website: www.sparkfun.com
 8#  Do you like this library? Help support SparkFun. Buy a board!
 9#  https://www.sparkfun.com/products/15083
10
11"""
12  Qwiic Twist Example 10 - example10_i2c_Scanner.py
13  Written by Gaston Williams, June 13th, 2019
14  The Qwiic Twist is an I2C controlled RGB Rotary Encoder
15
16  Example 10 - I2C Scanner
17  This progam uses CircuitPython BusIO library to find the current
18  address of the Qwiic Twist. It uses the I2C Scanner Example from
19  https://learn.adafruit.com/circuitpython-basics-i2c-and-spi/i2c-devices
20
21  The factory default address is 0x3F.
22"""
23
24import time
25
26import board
27
28i2c = board.I2C()
29
30while not i2c.try_lock():
31    pass
32
33print("Press Ctrl-C to exit program")
34
35try:
36    while True:
37        print(
38            "I2C addresses found:",
39            [hex(device_address) for device_address in i2c.scan()],
40        )
41        time.sleep(5)
42except KeyboardInterrupt:
43    pass
44
45finally:
46    i2c.unlock()