Skip to content

Commit 3dab6e6

Browse files
committed
add support for different chip detection + quad rotary demo
1 parent d99b564 commit 3dab6e6

File tree

2 files changed

+70
-8
lines changed

2 files changed

+70
-8
lines changed

adafruit_seesaw/seesaw.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ def const(x):
105105
_TOUCH_CHANNEL_OFFSET = const(0x10)
106106

107107
_SAMD09_HW_ID_CODE = const(0x55)
108-
_ATTINY8X7_HW_ID_CODE = const(0x87)
108+
_ATTINY806_HW_ID_CODE = const(0x84)
109+
_ATTINY807_HW_ID_CODE = const(0x85)
110+
_ATTINY816_HW_ID_CODE = const(0x86)
111+
_ATTINY817_HW_ID_CODE = const(0x87)
112+
_ATTINY1616_HW_ID_CODE = const(0x88)
113+
_ATTINY1617_HW_ID_CODE = const(0x89)
109114
_EEPROM_I2C_ADDR = const(0x3F)
110115

111116
_ENCODER_STATUS = const(0x00)
@@ -145,13 +150,13 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True):
145150
self.sw_reset()
146151

147152
self.chip_id = self.read8(_STATUS_BASE, _STATUS_HW_ID)
148-
149-
if self.chip_id not in (_ATTINY8X7_HW_ID_CODE, _SAMD09_HW_ID_CODE):
153+
if self.chip_id not in (_ATTINY806_HW_ID_CODE,_ATTINY807_HW_ID_CODE,
154+
_ATTINY816_HW_ID_CODE,_ATTINY817_HW_ID_CODE,
155+
_ATTINY1616_HW_ID_CODE,_ATTINY1617_HW_ID_CODE,
156+
_SAMD09_HW_ID_CODE):
150157
raise RuntimeError(
151158
"Seesaw hardware ID returned (0x{:x}) is not "
152-
"correct! Expected 0x{:x} or 0x{:x}. Please check your wiring.".format(
153-
self.chip_id, _SAMD09_HW_ID_CODE, _ATTINY8X7_HW_ID_CODE
154-
)
159+
"correct! Please check your wiring.".format(self.chip_id,)
155160
)
156161

157162
pid = self.get_version() >> 16
@@ -164,15 +169,17 @@ def __init__(self, i2c_bus, addr=0x49, drdy=None, reset=True):
164169
from adafruit_seesaw.robohat import MM1_Pinmap
165170

166171
self.pin_mapping = MM1_Pinmap
167-
elif pid in (_5690_PID, _5681_PID, _5743_PID):
172+
elif (pid in (_5690_PID, _5681_PID, _5743_PID)) or (self.chip_id in (_ATTINY817_HW_ID_CODE, _ATTINY807_HW_ID_CODE, _ATTINY1617_HW_ID_CODE)):
168173
from adafruit_seesaw.attinyx16 import ATtinyx16_Pinmap
169174

170175
self.pin_mapping = ATtinyx16_Pinmap
171176
elif self.chip_id == _SAMD09_HW_ID_CODE:
172177
from adafruit_seesaw.samd09 import SAMD09_Pinmap
173178

174179
self.pin_mapping = SAMD09_Pinmap
175-
elif self.chip_id == _ATTINY8X7_HW_ID_CODE:
180+
elif self.chip_id in (_ATTINY817_HW_ID_CODE,
181+
_ATTINY807_HW_ID_CODE,
182+
_ATTINY1617_HW_ID_CODE):
176183
from adafruit_seesaw.attiny8x7 import ATtiny8x7_Pinmap
177184

178185
self.pin_mapping = ATtiny8x7_Pinmap

examples/seesaw_quadrotary.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2023 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
"""I2C rotary encoder NeoPixel color picker and brightness setting example."""
5+
import board
6+
from rainbowio import colorwheel
7+
import digitalio
8+
import adafruit_seesaw.seesaw
9+
import adafruit_seesaw.neopixel
10+
import adafruit_seesaw.rotaryio
11+
import adafruit_seesaw.digitalio
12+
import time
13+
14+
# For use with the STEMMA connector on QT Py RP2040
15+
# import busio
16+
# i2c = busio.I2C(board.SCL1, board.SDA1)
17+
# seesaw = seesaw.Seesaw(i2c, 0x49)
18+
19+
i2c = board.I2C() # uses board.SCL and board.SDA
20+
# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
21+
seesaw = adafruit_seesaw.seesaw.Seesaw(i2c, 0x49)
22+
23+
encoders = [adafruit_seesaw.rotaryio.IncrementalEncoder(seesaw, n) for n in range(4)]
24+
switches = [adafruit_seesaw.digitalio.DigitalIO(seesaw, pin) for pin in (12, 14, 17, 9)]
25+
for switch in switches:
26+
switch.switch_to_input(digitalio.Pull.UP) # input & pullup!
27+
28+
# four neopixels per 'stick'
29+
pixels = adafruit_seesaw.neopixel.NeoPixel(seesaw, 18, 4)
30+
pixels.brightness = 0.5
31+
32+
last_positions = [-1, -1, -1, -1]
33+
colors = [0, 0, 0, 0] # start at red
34+
35+
while True:
36+
# negate the position to make clockwise rotation positive
37+
positions = [encoder.position for encoder in encoders]
38+
39+
for n, rotary_pos in enumerate(positions):
40+
if rotary_pos != last_positions[n]:
41+
print("Rotary #%d: %d" % (n, rotary_pos))
42+
last_positions[n] = rotary_pos
43+
44+
if switches[n].value: # Change the LED color if switch is not pressed
45+
if rotary_pos > last_positions[n]: # Advance forward through the colorwheel.
46+
colors[n] += 8
47+
else:
48+
colors[n] -= 8 # Advance backward through the colorwheel.
49+
colors[n] = (colors[n] + 256) % 256 # wrap around to 0-256
50+
51+
# if switch is pressed, light up white, otherwise use the stored color
52+
if not switches[n].value:
53+
pixels[n] = 0xFFFFFF
54+
else:
55+
pixels[n] = colorwheel(colors[n])

0 commit comments

Comments
 (0)