Simple test

Ensure your device works with this simple test.

examples/seesaw_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple seesaw test using an LED attached to Pin 15.
 5#
 6# See the seesaw Learn Guide for wiring details:
 7# https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test
 8import time
 9
10import board
11
12from adafruit_seesaw.seesaw import Seesaw
13
14i2c_bus = board.I2C()  # uses board.SCL and board.SDA
15# i2c_bus = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16
17ss = Seesaw(i2c_bus)
18
19ss.pin_mode(15, ss.OUTPUT)
20
21while True:
22    ss.digital_write(15, True)  # turn the LED on (True is the voltage level)
23    time.sleep(1)  # wait for a second
24    ss.digital_write(15, False)  # turn the LED off by making the voltage LOW
25    time.sleep(1)

Other Examples

Here are some other examples using the Seesaw library

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