Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# Simple seesaw test using an LED attached to Pin 15.
#
# See the seesaw Learn Guide for wiring details:
# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test
import time
import board
from adafruit_seesaw.seesaw import Seesaw
i2c_bus = board.I2C()
ss = Seesaw(i2c_bus)
ss.pin_mode(15, ss.OUTPUT)
while True:
ss.digital_write(15, True) # turn the LED on (True is the voltage level)
time.sleep(1) # wait for a second
ss.digital_write(15, False) # turn the LED off by making the voltage LOW
time.sleep(1)
|
Other Examples¶
Here are some other examples using the Seesaw library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import board
from adafruit_motor import servo
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
# from analogio import AnalogOut
# import board
i2c_bus = board.I2C()
ss = Seesaw(i2c_bus)
pwm1 = PWMOut(ss, 17)
pwm2 = PWMOut(ss, 16)
pwm3 = PWMOut(ss, 15)
pwm4 = PWMOut(ss, 14)
pwm1.frequency = 50
pwm2.frequency = 50
pwm3.frequency = 50
pwm4.frequency = 50
S1 = servo.Servo(pwm1)
S2 = servo.Servo(pwm2)
S3 = servo.Servo(pwm3)
S4 = servo.Servo(pwm4)
servos = (S1, S2, S3, S4)
CRCKIT_NUM_ADC = 8
CRCKit_adc = (2, 3, 40, 41, 11, 10, 9, 8)
CRCKIT_NUM_DRIVE = 4
CRCKit_drive = (42, 43, 12, 13)
CAPTOUCH_THRESH = 500
_CRCKIT_M1_A1 = 18
_CRCKIT_M1_A2 = 19
_CRCKIT_M1_B1 = 22
_CRCKIT_M1_B2 = 23
cap_state = [False, False, False, False]
cap_justtouched = [False, False, False, False]
cap_justreleased = [False, False, False, False]
motor1_dir = False
motor2_dir = True
test_servos = False
test_motors = False
test_drives = False
test_speaker = False
counter = 0
# analog_out = AnalogOut(board.A0)
# analog_out.value = 512
while True:
counter = (counter + 1) % 256
if counter % 32 == 0:
print("-------------------- analog -----------------------")
str_out = ""
for i in range(8):
val = ss.analog_read(CRCKit_adc[i]) * 3.3 / 1024
str_out = str_out + str(round(val, 2)) + "\t"
print(str_out + "\n")
for i in range(4):
val = ss.touch_read(i)
cap_justtouched[i] = False
cap_justreleased[i] = False
if val > CAPTOUCH_THRESH:
print("CT" + str(i + 1) + " touched! value: " + str(val))
if not cap_state[i]:
cap_justtouched[i] = True
cap_state[i] = True
else:
if cap_state[i]:
cap_justreleased[i] = True
cap_state[i] = False
if cap_justtouched[0]:
test_servos = not test_servos
if test_servos:
print("Testing servos")
else:
print("Stopping servos")
if cap_justtouched[1]:
test_drives = not test_drives
if test_drives:
print("Testing drives")
else:
print("Stopping drives")
if cap_justtouched[2]:
test_motors = not test_motors
if test_motors:
print("Testing motors")
else:
print("Stopping motors")
if cap_justtouched[3]:
test_speaker = not test_speaker
if test_speaker:
print("Testing speaker")
else:
print("Stopping speaker")
if test_servos:
if counter % 32 == 0:
print("-------------------- servos -----------------------")
servonum = int(counter / 32) % 4
if counter < 128:
print("SER" + str(servonum) + " LEFT")
servos[servonum].angle = 0
else:
print("SER" + str(servonum) + " RIGHT")
servos[servonum].angle = 180
if test_drives:
if counter % 32 == 0:
print("-------------------- drives -----------------------")
drivenum = int(counter / 64) % 4
if counter % 64 == 0:
print("DRIVE" + str(drivenum) + " ON")
ss.analog_write(CRCKit_drive[drivenum], 65535)
else:
print("DRIVE" + str(drivenum) + " OFF")
ss.analog_write(CRCKit_drive[drivenum], 0)
if test_motors:
if counter < 128:
if motor1_dir:
ss.analog_write(_CRCKIT_M1_A1, 0)
ss.analog_write(_CRCKIT_M1_A2, counter * 512)
else:
ss.analog_write(_CRCKIT_M1_A2, 0)
ss.analog_write(_CRCKIT_M1_A1, counter * 512)
else:
if motor1_dir:
ss.analog_write(_CRCKIT_M1_A1, 0)
ss.analog_write(_CRCKIT_M1_A2, (255 - counter) * 512)
else:
ss.analog_write(_CRCKIT_M1_A2, 0)
ss.analog_write(_CRCKIT_M1_A1, (255 - counter) * 512)
if counter == 255:
print("-------------------- motor 1 -----------------------")
motor1_dir = not motor1_dir
if counter < 128:
if motor2_dir:
ss.analog_write(_CRCKIT_M1_B1, 0)
ss.analog_write(_CRCKIT_M1_B2, counter * 512)
else:
ss.analog_write(_CRCKIT_M1_B2, 0)
ss.analog_write(_CRCKIT_M1_B1, counter * 512)
else:
if motor2_dir:
ss.analog_write(_CRCKIT_M1_B1, 0)
ss.analog_write(_CRCKIT_M1_B2, (255 - counter) * 512)
else:
ss.analog_write(_CRCKIT_M1_B2, 0)
ss.analog_write(_CRCKIT_M1_B1, (255 - counter) * 512)
if counter == 255:
print("-------------------- motor 2 -----------------------")
motor2_dir = not motor2_dir
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
from micropython import const
from adafruit_seesaw.seesaw import Seesaw
BUTTON_RIGHT = const(6)
BUTTON_DOWN = const(7)
BUTTON_LEFT = const(9)
BUTTON_UP = const(10)
BUTTON_SEL = const(14)
button_mask = const(
(1 << BUTTON_RIGHT)
| (1 << BUTTON_DOWN)
| (1 << BUTTON_LEFT)
| (1 << BUTTON_UP)
| (1 << BUTTON_SEL)
)
i2c_bus = board.I2C()
ss = Seesaw(i2c_bus)
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
last_x = 0
last_y = 0
while True:
x = ss.analog_read(2)
y = ss.analog_read(3)
if (abs(x - last_x) > 3) or (abs(y - last_y) > 3):
print(x, y)
last_x = x
last_y = y
buttons = ss.digital_read_bulk(button_mask)
if not buttons & (1 << BUTTON_RIGHT):
print("Button A pressed")
if not buttons & (1 << BUTTON_DOWN):
print("Button B pressed")
if not buttons & (1 << BUTTON_LEFT):
print("Button Y pressed")
if not buttons & (1 << BUTTON_UP):
print("Button x pressed")
if not buttons & (1 << BUTTON_SEL):
print("Button SEL pressed")
time.sleep(0.01)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
from adafruit_seesaw.seesaw import Seesaw
i2c_bus = board.I2C()
ss = Seesaw(i2c_bus, addr=0x36)
while True:
# read moisture level through capacitive touch pad
touch = ss.moisture_read()
# read temperature from the temperature sensor
temp = ss.get_temp()
print("temp: " + str(temp) + " moisture: " + str(touch))
time.sleep(1)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
from micropython import const
from adafruit_seesaw.seesaw import Seesaw
BUTTON_RIGHT = const(7)
BUTTON_DOWN = const(4)
BUTTON_LEFT = const(3)
BUTTON_UP = const(2)
BUTTON_SEL = const(11)
BUTTON_A = const(10)
BUTTON_B = const(9)
button_mask = const(
(1 << BUTTON_RIGHT)
| (1 << BUTTON_DOWN)
| (1 << BUTTON_LEFT)
| (1 << BUTTON_UP)
| (1 << BUTTON_SEL)
| (1 << BUTTON_A)
| (1 << BUTTON_B)
)
i2c_bus = board.I2C()
ss = Seesaw(i2c_bus, 0x5E)
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
while True:
buttons = ss.digital_read_bulk(button_mask)
if not buttons & (1 << BUTTON_RIGHT):
print("Button RIGHT pressed")
if not buttons & (1 << BUTTON_DOWN):
print("Button DOWN pressed")
if not buttons & (1 << BUTTON_LEFT):
print("Button LEFT pressed")
if not buttons & (1 << BUTTON_UP):
print("Button UP pressed")
if not buttons & (1 << BUTTON_SEL):
print("Button SEL pressed")
if not buttons & (1 << BUTTON_A):
print("Button A pressed")
if not buttons & (1 << BUTTON_B):
print("Button B pressed")
time.sleep(0.01)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # SPDX-FileCopyrightText: 2021 John Furcean
# SPDX-License-Identifier: MIT
"""I2C rotary encoder simple test example."""
import board
from adafruit_seesaw import seesaw, rotaryio, digitalio
# For use with the STEMMA connector on QT Py RP2040
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)
# seesaw = seesaw.Seesaw(i2c, 0x36)
seesaw = seesaw.Seesaw(board.I2C(), addr=0x36)
seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF
print("Found product {}".format(seesaw_product))
if seesaw_product != 4991:
print("Wrong firmware loaded? Expected 4991")
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
button = digitalio.DigitalIO(seesaw, 24)
button_held = False
encoder = rotaryio.IncrementalEncoder(seesaw)
last_position = None
while True:
# negate the position to make clockwise rotation positive
position = -encoder.position
if position != last_position:
last_position = position
print("Position: {}".format(position))
if not button.value and not button_held:
button_held = True
print("Button pressed")
if button.value and button_held:
button_held = False
print("Button released")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""I2C rotary encoder NeoPixel color picker and brightness setting example."""
import board
from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio
try:
import _pixelbuf
except ImportError:
import adafruit_pypixelbuf as _pixelbuf
# For use with the STEMMA connector on QT Py RP2040
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1)
# seesaw = seesaw.Seesaw(i2c, 0x36)
seesaw = seesaw.Seesaw(board.I2C(), 0x36)
encoder = rotaryio.IncrementalEncoder(seesaw)
seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
switch = digitalio.DigitalIO(seesaw, 24)
pixel = neopixel.NeoPixel(seesaw, 6, 1)
pixel.brightness = 0.5
last_position = -1
color = 0 # start at red
while True:
# negate the position to make clockwise rotation positive
position = -encoder.position
if position != last_position:
print(position)
if switch.value:
# Change the LED color.
if position > last_position: # Advance forward through the colorwheel.
color += 1
else:
color -= 1 # Advance backward through the colorwheel.
color = (color + 256) % 256 # wrap around to 0-256
pixel.fill(_pixelbuf.colorwheel(color))
else: # If the button is pressed...
# ...change the brightness.
if position > last_position: # Increase the brightness.
pixel.brightness = min(1.0, pixel.brightness + 0.1)
else: # Decrease the brightness.
pixel.brightness = max(0, pixel.brightness - 0.1)
last_position = position
|