def __init__(self): self.stepsPerRev = 200 self.clk = 17 self.dt = 18 self.hef = 22 self.q = Queue(0) self.saw = seesaw.Seesaw (board.I2C(), 0x36) self.encoder = rotaryio.IncrementalEncoder(self.saw) GPIO.setmode(GPIO.BCM) GPIO.setup(self.clk, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(self.dt, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) GPIO.setup(self.hef, GPIO.IN, pull_up_down=GPIO.PUD_UP) self.counter = 0 self.clkLastState = GPIO.input(self.clk) pump_thread = Thread(target=self.run) pump_thread.start() pump_thread2 = Thread(target=self.flush_queue) pump_thread2.start()
def __init__(self, _disp_sck = board.SCK, _disp_mosi = board.MOSI, _disp_miso = board.MISO, _disp_cs = board.D5, _disp_dc = board.D6, adress = 94): # Only create the joywing module member when we're aren't being imported by Sphinx if ("__module__" in dir(digitalio.DigitalInOut) and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"): return #SPI self._disp_sck = _disp_sck self._disp_mosi = _disp_mosi self._disp_miso = _disp_miso # DS and CS pins self._disp_cs = _disp_cs self._disp_dc = _disp_dc #I2C self._i2c = busio.I2C(board.SCL, board.SDA) self._seesaw = ss.Seesaw(self._i2c, adress) self._backlight_pin = pwm.PWMOut(self._seesaw, 5) self._disp_rst = dio.DigitalIO(self._seesaw, 8) self._disp_spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) # pylint: disable=bad-whitespace self._BUTTON_RIGHT = const(7) self._BUTTON_DOWN = const(4) self._BUTTON_UP = const(2) self._BUTTON_LEFT = const(3) self._BUTTON_B = const(9) self._BUTTON_A = const(10) self._BUTTON_SEL = const(11) # pylint: enable=bad-whitespace self._button_mask = const((1 << self._BUTTON_RIGHT) | (1 << self._BUTTON_DOWN) | (1 << self._BUTTON_UP) | (1 << self._BUTTON_LEFT) | (1 << self._BUTTON_B) | (1 << self._BUTTON_A) | (1 << self._BUTTON_SEL)) self._seesaw.pin_mode_bulk(self._button_mask, self._seesaw.INPUT_PULLUP) # initilise stuff # start backlight in off position self._backlite = (self._backlight_pin) self._backlite.duty_cycle = 0xffff # setup the display as a car named "disp" self._disp = ST7735R(self._disp_spi, cs=digitalio.DigitalInOut(self._disp_cs), dc=digitalio.DigitalInOut(self._disp_dc), rst=(self._disp_rst), rotation=3) self._disp.y_offset = 24 # clear screen self._clear()
def __init__(self, i2c, address, is_inverted=False): try: from adafruit_seesaw import digitalio, neopixel, rotaryio, seesaw except ImportError: print('seesaw missing') return super().__init__(is_inverted) self.seesaw = seesaw.Seesaw(i2c, address) # Check for correct product seesaw_product = (self.seesaw.get_version() >> 16) & 0xFFFF if seesaw_product != 4991: print('Wrong firmware loaded? Expected 4991') self.encoder = rotaryio.IncrementalEncoder(self.seesaw) self.seesaw.pin_mode(24, self.seesaw.INPUT_PULLUP) self.switch = digitalio.DigitalIO(self.seesaw, 24) self.pixel = neopixel.NeoPixel(self.seesaw, 6, 1) self._state = self.encoder.position
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT # Simple seesaw test reading and writing the internal EEPROM # The ATtiny8xx series has a true 128 byte EEPROM, the SAMD09 mimics it in flash with 64 bytes # THE LAST BYTE IS USED FOR I2C ADDRESS CHANGE! import time import board from adafruit_seesaw import seesaw i2c_bus = board.I2C() ss = seesaw.Seesaw(i2c_bus) value = ss.eeprom_read8(0x02) # Read from address 2 print("Read 0x%02x from EEPROM address 0x02" % value) print("Incrementing value") ss.eeprom_write8(0x02, (value + 1) % 0xFF) value = ss.eeprom_read8(0x02) # Read from address 2 print("Second read 0x%02x from EEPROM address 0x02" % value) while True: # Do not write EEPROM in a loop, it has 100k cycle life time.sleep(1)
# 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 rainbowio import colorwheel from adafruit_seesaw import seesaw, neopixel, 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(), 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)
# SPDX-FileCopyrightText: 2021 John Park # SPDX-License-Identifier: MIT # I2C rotary encoder multiple test example. # solder the A0 jumper on the second QT Rotary Encoder board import board from adafruit_seesaw import seesaw, rotaryio, digitalio, neopixel qt_enc1 = seesaw.Seesaw(board.I2C(), addr=0x36) qt_enc2 = seesaw.Seesaw(board.I2C(), addr=0x37) qt_enc1.pin_mode(24, qt_enc1.INPUT_PULLUP) button1 = digitalio.DigitalIO(qt_enc1, 24) button_held1 = False qt_enc2.pin_mode(24, qt_enc2.INPUT_PULLUP) button2 = digitalio.DigitalIO(qt_enc2, 24) button_held2 = False encoder1 = rotaryio.IncrementalEncoder(qt_enc1) last_position1 = None encoder2 = rotaryio.IncrementalEncoder(qt_enc2) last_position2 = None pixel1 = neopixel.NeoPixel(qt_enc1, 6, 1) pixel1.brightness = 0.2 pixel1.fill(0xFF0000) pixel2 = neopixel.NeoPixel(qt_enc2, 6, 1)
# SPDX-License-Identifier: MIT """ This example is for use on (Linux) computers that are using CPython with Adafruit Blinka to support CircuitPython libraries. CircuitPython does not support PIL/pillow (python imaging library)! Author(s): Melissa LeBlanc-Williams for Adafruit Industries """ import digitalio import board from animatedgif import AnimatedGif import numpy # pylint: disable=unused-import from adafruit_seesaw import seesaw, rotaryio, digitalio as ss_digitalio from adafruit_rgb_display import st7789 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? Make sure you have a rotary encoder connected." ) seesaw.pin_mode(24, seesaw.INPUT_PULLUP) button = ss_digitalio.DigitalIO(seesaw, 24) encoder = rotaryio.IncrementalEncoder(seesaw) # Change to match your display BUTTON_UP = board.D23 BUTTON_DOWN = board.D24
import threading import board import busio import adafruit_seesaw.seesaw as seesaw import prometheus_client as prom # Initialize sensor bus = busio.I2C(board.SCL, board.SDA) sensor = seesaw.Seesaw(bus, addr=0x36) # Connect moisture read to moisture metric moisture = prom.Gauge("soil_moisture", "Soil Moisture reading from STEMMA capacative sensor") moisture.set_function(sensor.moisture_read) # Connect temperature read to metric temperature = prom.Gauge( "temperature", "Ambiant temperature reading from STEMMA capacative sensor") temperature.set_function(sensor.get_temp) # Start metrics server print("Starting prometheus metrics server on port 9000...") prom.start_http_server(9000) # Sleep forever (or until a keyboard interrupt) event = threading.Event() event.wait()
# Simple seesaw test writing NeoPixels # Can use any valid GPIO pin, up to 60 pixels! # # See the seesaw Learn Guide for wiring details. # For SAMD09: # https://learn.adafruit.com/adafruit-seesaw-atsamd09-breakout?view=all#circuitpython-wiring-and-test # For ATtiny8x7: # https://learn.adafruit.com/adafruit-attiny817-seesaw/neopixel import time import board from rainbowio import colorwheel from adafruit_seesaw import seesaw, neopixel ss = seesaw.Seesaw(board.I2C()) NEOPIXEL_PIN = 19 # Can be any pin NEOPIXEL_NUM = 12 # No more than 60 pixels! pixels = neopixel.NeoPixel(ss, NEOPIXEL_PIN, NEOPIXEL_NUM) pixels.brightness = 0.3 # Not so bright! color_offset = 0 # Start at red # Cycle through all colors along the ring while True: for i in range(NEOPIXEL_NUM): rc_index = (i * 256 // NEOPIXEL_NUM) + color_offset pixels[i] = colorwheel(rc_index & 255) color_offset += 1