Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Usage Example¶
See examples/seesaw_simpletest.py for usage example.
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Building locally¶
To build this library locally you’ll need to install the circuitpython-build-tools package.
python3 -m venv .env
source .env/bin/activate
pip install circuitpython-build-tools
Once installed, make sure you are in the virtual environment:
source .env/bin/activate
Then run the build:
circuitpython-build-bundles --filename_prefix adafruit-circuitpython-seesaw --library_location .
Sphinx documentation¶
Sphinx is used to build the documentation based on rST files and comments in the code. First, install dependencies (feel free to reuse the virtual environment from above):
python3 -m venv .env
source .env/bin/activate
pip install Sphinx sphinx-rtd-theme
Now, once you have the virtual environment activated:
cd docs
sphinx-build -E -W -b html . _build/html
This will output the documentation to docs/_build/html
. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.
Table of Contents¶
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 | # 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
from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw
i2c_bus = busio.I2C(SCL, SDA)
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 181 | from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo
#from analogio import AnalogOut
#import board
i2c_bus = busio.I2C(SCL, SDA)
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 | import time
from board import SCL, SDA
import busio
from micropython import const
from adafruit_seesaw.seesaw import Seesaw
# pylint: disable=bad-whitespace
BUTTON_RIGHT = const(6)
BUTTON_DOWN = const(7)
BUTTON_LEFT = const(9)
BUTTON_UP = const(10)
BUTTON_SEL = const(14)
# pylint: enable=bad-whitespace
button_mask = const((1 << BUTTON_RIGHT) |
(1 << BUTTON_DOWN) |
(1 << BUTTON_LEFT) |
(1 << BUTTON_UP) |
(1 << BUTTON_SEL))
i2c_bus = busio.I2C(SCL, SDA)
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(.01)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import time
from board import SCL, SDA
import busio
from adafruit_seesaw.seesaw import Seesaw
i2c_bus = busio.I2C(SCL, SDA)
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 | import time
import board
from micropython import const
from adafruit_seesaw.seesaw import Seesaw
# pylint: disable=bad-whitespace
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)
# pylint: enable=bad-whitespace
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(.01)
|
seesaw
¶
An I2C to whatever helper chip.
- Author(s): Dean Miller
Implementation Notes¶
Hardware:
- Adafruit ATSAMD09 Breakout with seesaw (Product ID: 3657)
Software and Dependencies:
- Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice