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
11from adafruit_seesaw.seesaw import Seesaw
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
15
16ss = Seesaw(i2c_bus)
17
18ss.pin_mode(15, ss.OUTPUT)
19
20while True:
21    ss.digital_write(15, True)  # turn the LED on (True is the voltage level)
22    time.sleep(1)  # wait for a second
23    ss.digital_write(15, False)  # turn the LED off by making the voltage LOW
24    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
  6from adafruit_seesaw.seesaw import Seesaw
  7from adafruit_seesaw.pwmout import PWMOut
  8
  9# from analogio import AnalogOut
 10# import board
 11
 12i2c_bus = board.I2C()  # uses board.SCL and board.SDA
 13# i2c_bus = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
 14ss = Seesaw(i2c_bus)
 15pwm1 = PWMOut(ss, 17)
 16pwm2 = PWMOut(ss, 16)
 17pwm3 = PWMOut(ss, 15)
 18pwm4 = PWMOut(ss, 14)
 19
 20pwm1.frequency = 50
 21pwm2.frequency = 50
 22pwm3.frequency = 50
 23pwm4.frequency = 50
 24
 25S1 = servo.Servo(pwm1)
 26S2 = servo.Servo(pwm2)
 27S3 = servo.Servo(pwm3)
 28S4 = servo.Servo(pwm4)
 29
 30servos = (S1, S2, S3, S4)
 31
 32CRCKIT_NUM_ADC = 8
 33CRCKit_adc = (2, 3, 40, 41, 11, 10, 9, 8)
 34
 35CRCKIT_NUM_DRIVE = 4
 36CRCKit_drive = (42, 43, 12, 13)
 37
 38CAPTOUCH_THRESH = 500
 39
 40_CRCKIT_M1_A1 = 18
 41_CRCKIT_M1_A2 = 19
 42_CRCKIT_M1_B1 = 22
 43_CRCKIT_M1_B2 = 23
 44
 45cap_state = [False, False, False, False]
 46cap_justtouched = [False, False, False, False]
 47cap_justreleased = [False, False, False, False]
 48
 49motor1_dir = False
 50motor2_dir = True
 51
 52test_servos = False
 53test_motors = False
 54test_drives = False
 55test_speaker = False
 56
 57counter = 0
 58
 59# analog_out = AnalogOut(board.A0)
 60# analog_out.value = 512
 61
 62while True:
 63    counter = (counter + 1) % 256
 64
 65    if counter % 32 == 0:
 66        print("-------------------- analog -----------------------")
 67        str_out = ""
 68        for i in range(8):
 69            val = ss.analog_read(CRCKit_adc[i]) * 3.3 / 1024
 70            str_out = str_out + str(round(val, 2)) + "\t"
 71
 72        print(str_out + "\n")
 73
 74    for i in range(4):
 75        val = ss.touch_read(i)
 76        cap_justtouched[i] = False
 77        cap_justreleased[i] = False
 78
 79        if val > CAPTOUCH_THRESH:
 80            print("CT" + str(i + 1) + " touched! value: " + str(val))
 81
 82            if not cap_state[i]:
 83                cap_justtouched[i] = True
 84
 85            cap_state[i] = True
 86
 87        else:
 88            if cap_state[i]:
 89                cap_justreleased[i] = True
 90
 91            cap_state[i] = False
 92
 93    if cap_justtouched[0]:
 94        test_servos = not test_servos
 95        if test_servos:
 96            print("Testing servos")
 97        else:
 98            print("Stopping servos")
 99
100    if cap_justtouched[1]:
101        test_drives = not test_drives
102        if test_drives:
103            print("Testing drives")
104        else:
105            print("Stopping drives")
106
107    if cap_justtouched[2]:
108        test_motors = not test_motors
109        if test_motors:
110            print("Testing motors")
111        else:
112            print("Stopping motors")
113
114    if cap_justtouched[3]:
115        test_speaker = not test_speaker
116        if test_speaker:
117            print("Testing speaker")
118        else:
119            print("Stopping speaker")
120
121    if test_servos:
122        if counter % 32 == 0:
123            print("-------------------- servos -----------------------")
124            servonum = int(counter / 32) % 4
125
126            if counter < 128:
127                print("SER" + str(servonum) + " LEFT")
128                servos[servonum].angle = 0
129            else:
130                print("SER" + str(servonum) + " RIGHT")
131                servos[servonum].angle = 180
132
133    if test_drives:
134        if counter % 32 == 0:
135            print("-------------------- drives -----------------------")
136            drivenum = int(counter / 64) % 4
137
138            if counter % 64 == 0:
139                print("DRIVE" + str(drivenum) + " ON")
140                ss.analog_write(CRCKit_drive[drivenum], 65535)
141
142            else:
143                print("DRIVE" + str(drivenum) + " OFF")
144                ss.analog_write(CRCKit_drive[drivenum], 0)
145
146    if test_motors:
147        if counter < 128:
148            if motor1_dir:
149                ss.analog_write(_CRCKIT_M1_A1, 0)
150                ss.analog_write(_CRCKIT_M1_A2, counter * 512)
151            else:
152                ss.analog_write(_CRCKIT_M1_A2, 0)
153                ss.analog_write(_CRCKIT_M1_A1, counter * 512)
154        else:
155            if 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        else:
173            if motor2_dir:
174                ss.analog_write(_CRCKIT_M1_B1, 0)
175                ss.analog_write(_CRCKIT_M1_B2, (255 - counter) * 512)
176            else:
177                ss.analog_write(_CRCKIT_M1_B2, 0)
178                ss.analog_write(_CRCKIT_M1_B1, (255 - counter) * 512)
179        if counter == 255:
180            print("-------------------- motor 2 -----------------------")
181            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
 7from adafruit_seesaw import seesaw, rotaryio, digitalio
 8
 9# For use with the STEMMA connector on QT Py RP2040
10# import busio
11# i2c = busio.I2C(board.SCL1, board.SDA1)
12# seesaw = seesaw.Seesaw(i2c, 0x36)
13
14i2c = board.I2C()  # uses board.SCL and board.SDA
15# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
16seesaw = seesaw.Seesaw(i2c, addr=0x36)
17
18seesaw_product = (seesaw.get_version() >> 16) & 0xFFFF
19print("Found product {}".format(seesaw_product))
20if seesaw_product != 4991:
21    print("Wrong firmware loaded?  Expected 4991")
22
23# Configure seesaw pin used to read knob button presses
24# The internal pull up is enabled to prevent floating input
25seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
26button = digitalio.DigitalIO(seesaw, 24)
27
28button_held = False
29
30encoder = rotaryio.IncrementalEncoder(seesaw)
31last_position = None
32
33while True:
34    # negate the position to make clockwise rotation positive
35    position = -encoder.position
36
37    if position != last_position:
38        last_position = position
39        print("Position: {}".format(position))
40
41    if not button.value and not button_held:
42        button_held = True
43        print("Button pressed")
44
45    if button.value and button_held:
46        button_held = False
47        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."""
 5import board
 6from rainbowio import colorwheel
 7from adafruit_seesaw import seesaw, neopixel, rotaryio, digitalio
 8
 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, 0x36)
18
19encoder = rotaryio.IncrementalEncoder(seesaw)
20seesaw.pin_mode(24, seesaw.INPUT_PULLUP)
21switch = digitalio.DigitalIO(seesaw, 24)
22
23pixel = neopixel.NeoPixel(seesaw, 6, 1)
24pixel.brightness = 0.5
25
26last_position = -1
27color = 0  # start at red
28
29while True:
30    # negate the position to make clockwise rotation positive
31    position = -encoder.position
32
33    if position != last_position:
34        print(position)
35
36        if switch.value:
37            # Change the LED color.
38            if position > last_position:  # Advance forward through the colorwheel.
39                color += 1
40            else:
41                color -= 1  # Advance backward through the colorwheel.
42            color = (color + 256) % 256  # wrap around to 0-256
43            pixel.fill(colorwheel(color))
44
45        else:  # If the button is pressed...
46            # ...change the brightness.
47            if position > last_position:  # Increase the brightness.
48                pixel.brightness = min(1.0, pixel.brightness + 0.1)
49            else:  # Decrease the brightness.
50                pixel.brightness = max(0, pixel.brightness - 0.1)
51
52    last_position = position