def soil(name): #Thread 4
    i2c_bus = busio.I2C(board.SCL, board.SDA)
    ss = Seesaw(i2c_bus, addr=0x36)
    countStemma = 0
    while True:
        # read moisture level through capacitive touch pad
        touch = ss.moisture_read()
        if touch is not None:
            satPercent = 200*(touch-200)/1800
            try:
                logging.info("Thread %s: Logging soil info into MariaDB",name)
                cur.execute("INSERT INTO soil_moisture (moisture,taken_at) VALUES (?,?)", (satPercent,datetime.datetime.now()))
                conn.commit()
            except mariadb.Error as e:
                print(f"Error: {e}")
                dataStorageFail("Soil Moisture Sensor")
        else:
            print("Stemma Data could not be collected")
            countStemma += 1
            #Didn't collect value
        if satPercent >= 60:
            #drip off
            GPIO.output(12,False)
        elif satPercent <= 40:
            #drip on
            GPIO.output(12,True)
            dataPasser.action[0] += 1
        else:
            continue
            #no change drip
        if countStemma >= 5:
            noData("Stemma Soil Moisture Sensor")
        time.sleep(30)
 def __init__(self, address=0x5E, i2c=None, spi=None):
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     self._ss = Seesaw(i2c, address)
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     displayio.release_displays()
     while not spi.try_lock():
         pass
     spi.configure(baudrate=24000000)
     spi.unlock()
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     display_bus = displayio.FourWire(spi,
                                      command=board.D6,
                                      chip_select=board.D5)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
Ejemplo n.º 3
0
class SoilSensor:
    # initialize needed values for communication
    def __init__(self):
        self.i2c_bus = busio.I2C(SCL, SDA)
        # Need to put the address into the sensor constructor for each
        self.ss = Seesaw(self.i2c_bus, addr=0x36)

    # get the soil moisture from the sensor
    def get_moisture(self):
        #i2c_bus = busio.I2C(SCL, SDA)
        # Need to put the address into the sensor constructor for each
        #ss = Seesaw(i2c_bus, addr=0x36)
        # read moisture level through capacitive touch pad
        moisture = self.ss.moisture_read()
        print("Soil Moisture Reading:", moisture)
        return moisture

    # get the soil temperature from the sensor
    def get_temperature(self):
        #i2c_bus = busio.I2C(SCL, SDA)
        # Need to put the address into the sensor constructor for each
        #ss = Seesaw(i2c_bus, addr=0x36)
        # read temperature from the temperature sensor
        temp = self.ss.get_temp()
        print("Soil Temperatured Reading:", temp)
        return temp
Ejemplo n.º 4
0
    def __init__(self, config, i2c):
        self._name = config.get('Name', '')
        self._dht = adafruit_dht.DHT22(int(config.get('DhtPin', 0)))
        self._light_pin = int(config.get('LightPin', 0))
        self._water_pin = int(config.get('WaterPin', 0))
        if config.getboolean('UseSS'):
            self._useSS = True
            self._soil_sensor = Seesaw(i2c, addr=int(config.get('SSAddr', 0x0), 16))
            self._soil_min = int(config.get('SSMin', 0))
            self._soil_max = int(config.get('SSMax', 0))
        else:
            self._useSS = False
        self._light_on = False
        self._water_on = False
        self._turn_light_on = int(config.get('LightOn', 0))
        self._turn_light_off = int(config.get('LightOff', 0))
        self._water_on_pct = int(config.get('MoistureOnPct',25))
        self._water_off_pct = int(config.get('MoistureOffPct', 75))
        self._water_on_time = datetime.strptime(config.get('WaterOnTime', '00:00'), '%H:%M').time()
        self._water_off_time = datetime.strptime(config.get('WaterOffTime', '00:00'), '%H:%M').time()
        self._prefix = config.get('Prefix', '')

        GPIO.setup(self._light_pin, GPIO.OUT, initial=GPIO.HIGH)
        GPIO.setup(self._water_pin, GPIO.OUT, initial=GPIO.HIGH)

        self.temperature = 0.0
        self.humidity = 0.0
        self.soil_temp = 0.0
        self.moisture = 0
        self.prev_temperature = 0.0
        self.prev_humidity = 0.0
        self.prev_moisture = 0.0
        self.prev_soil_temp = 0
        self.water = 0
        self.light = 0
Ejemplo n.º 5
0
class InputModule(AbstractInput):
    """ A sensor support class that measures soil moisture using adafruit's i2c soil sensor """
    def __init__(self, input_dev, testing=False):
        super(InputModule, self).__init__(input_dev, testing=testing, name=__name__)

        self.sensor = None

        if not testing:
            self.initialize_input()

    def initialize_input(self):
        from adafruit_seesaw.seesaw import Seesaw
        from adafruit_extended_bus import ExtendedI2C

        try:
            self.sensor = Seesaw(
                ExtendedI2C(self.input_dev.i2c_bus),
                addr=int(str(self.input_dev.i2c_location), 16))
        except:
            self.logger.exception("Setting up sensor")

    def get_measurement(self):
        if not self.sensor:
            self.logger.error("Input not set up")
            return

        self.return_dict = copy.deepcopy(measurements_dict)

        if self.is_enabled(0):
            self.value_set(0, self.sensor.moisture_read())

        if self.is_enabled(1):
            self.value_set(1, self.sensor.get_temp())

        return self.return_dict
Ejemplo n.º 6
0
 def __init__(
     self,
     address: int = 0x5E,
     i2c: Optional[I2C] = None,
     spi: Optional[SPI] = None,
     cs: Optional[Pin] = None,
     dc: Optional[Pin] = None,
 ):
     displayio.release_displays()
     if i2c is None:
         i2c = board.I2C()
     if spi is None:
         spi = board.SPI()
     if cs is None:
         cs = board.D5
     if dc is None:
         dc = board.D6
     self._ss = Seesaw(i2c, address)
     self._ss.pin_mode_bulk(self._button_mask, self._ss.INPUT_PULLUP)
     self._ss.pin_mode(8, self._ss.OUTPUT)
     self._ss.digital_write(8, True)  # Reset the Display via Seesaw
     self._backlight = PWMOut(self._ss, 5)
     self._backlight.duty_cycle = 0
     display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
     self.display = ST7735R(display_bus,
                            width=160,
                            height=80,
                            colstart=24,
                            rotation=270,
                            bgr=True)
Ejemplo n.º 7
0
def reading():
    # Soil Moisture Sensor Readings
    i2c_bus = busio.I2C(SCL, SDA)
    ss = Seesaw(i2c_bus, addr=0x36)
    # read moisture level through capacitive touch pad
    touch = ss.moisture_read()
    return touch
Ejemplo n.º 8
0
 def get_temperature(self):
     i2c_bus = busio.I2C(SCL, SDA)
     # Need to put the address into the sensor constructor for each
     ss = Seesaw(i2c_bus, addr=0x36)
     # read temperature from the temperature sensor
     temp = ss.get_temp()
     print("Soil Temperatured Reading:", temp)
     return temp
Ejemplo n.º 9
0
 def get_moisture(self):
     i2c_bus = busio.I2C(SCL, SDA)
     # Need to put the address into the sensor constructor for each
     ss = Seesaw(i2c_bus, addr=0x36)
     # read moisture level through capacitive touch pad
     moisture = ss.moisture_read()
     print("Soil Moisture Reading:", moisture)
     return moisture
Ejemplo n.º 10
0
    def initialize_input(self):
        from adafruit_seesaw.seesaw import Seesaw
        from adafruit_extended_bus import ExtendedI2C

        try:
            self.sensor = Seesaw(ExtendedI2C(self.input_dev.i2c_bus),
                                 addr=int(str(self.input_dev.i2c_location),
                                          16))
        except:
            self.logger.exception("Setting up sensor")
Ejemplo n.º 11
0
def get_temp():
    try:
        i2c_bus = busio.I2C(SCL, SDA)
        ss = Seesaw(i2c_bus, addr=0x36)
        # read temperature from the temperature sensor
        temp = ss.get_temp()
        print("Temperature: {0}".format(temp))
        return round(temp, 2)
    except Exception as e:
        return 0
Ejemplo n.º 12
0
def get_soil():
    try:
        i2c_bus = busio.I2C(SCL, SDA)
        ss = Seesaw(i2c_bus, addr=0x36)
        # read moisture level through capacitive touch pad
        touch = ss.moisture_read()
        # read temperature from the temperature sensor
        temp = ss.get_temp()
        print("Soil moisture: {0}".format(touch))
        return touch
    except Exception as e:
        return 0
Ejemplo n.º 13
0
def moisture_setup(addrresses):
    sensors = []
    for addr in addrresses:
        i2c_bus = busio.I2C(SCL, SDA)
        sensor = Seesaw(i2c_bus, addr)
        sensors.append(sensor)
    return sensors
Ejemplo n.º 14
0
def main():
    """Primary entry point for the application"""
    log_format = '[%(asctime)s] %(levelname)s %(message)s'
    logging.basicConfig(format=log_format, level=logging.INFO)
    logging.info('** GardenPI Soil Moisture Test Utility Starting **')
    start_time = time.time()
    i2c = board.I2C()
    sensors = []
    mins = []
    maxs = []

    # load the config
    config = utils.load_config()

    if config['General'].getboolean('UseShelf1'):
        sensors.append(
            Seesaw(i2c, addr=int(config['Shelf1'].get('SSAddr', 0x0), 16)))
        mins.append(int(config['Shelf1'].get('SSMin', 200)))
        maxs.append(int(config['Shelf1'].get('SSMax', 2000)))
    if config['General'].getboolean('UseShelf2'):
        sensors.append(
            Seesaw(i2c, addr=int(config['Shelf2'].get('SSAddr', 0x0), 16)))
        mins.append(int(config['Shelf2'].get('SSMin', 200)))
        maxs.append(int(config['Shelf2'].get('SSMax', 2000)))
    if config['General'].getboolean('UseShelf3'):
        sensors.append(
            Seesaw(i2c, addr=int(config['Shelf3'].get('SSAddr', 0x0), 16)))
        mins.append(int(config['Shelf3'].get('SSMin', 200)))
        maxs.append(int(config['Shelf3'].get('SSMax', 2000)))

    # NOTE: 200 == very dry; 2000 == very wet
    while True:
        for idx, ss in enumerate(sensors):
            try:
                temp = utils.ctof(ss.get_temp())
                touch = ss.moisture_read()
                scaled = utils.scale_to_percent(touch, mins[idx], maxs[idx])
                print("Device: {}\tTemp: {:.1f} *F\tRaw: {}\tScaled: {:.2f}%".
                      format(idx, temp, touch, scaled))
            except RuntimeError as e:
                print("Reading from SS failure: ", e.args)

        time.sleep(2)

    logging.info("Script Finished")
    logging.info("Elapsed Time: %s seconds ", (time.time() - start_time))
Ejemplo n.º 15
0
def set_sensors():
    i2c_bus = busio.I2C(SCL, SDA)
    ss = Seesaw(i2c_bus, addr=0x36)
    GPIO.cleanup()
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(17, GPIO.OUT)
    return ss
Ejemplo n.º 16
0
class SeesawSoilSensor(drivers.Sensor):

    i2c_address = 54  # 0x36
    moisture_metric = 'soil-moisture'
    t9e_metric = 'soil-temp'

    def setup(self):
        i2c_bus = busio.I2C(SCL, SDA)
        self.ss = Seesaw(i2c_bus, addr=int(self.i2c_address))

    def read(self):
        # read moisture level through capacitive touch pad
        moisture = self.ss.moisture_read()
        metrics.create_metric_log(self.moisture_metric, moisture)

        # read temperature from the temperature sensor
        t9e = self.ss.get_temp()
        metrics.create_metric_log(self.t9e_metric, t9e)
    def __init__(self,
                 gpio_relay,
                 gpio_flow,
                 ip_address=None,
                 humid_temp="DHT22",
                 moisture="I2C"):
        IotDevice.__init__(self)

        if gpio_relay == "SIM":
            self.gpio_relay = None
        else:
            if ip_address is not None:
                self.gpio_relay = LED(gpio_relay,
                                      PiGPIOFactory(host=ip_address))
            else:
                self.gpio_relay = LED(gpio_relay)

        # For now we want to leave the DHT sensor (measures temperature and humidity)
        # connected to pin 18.
        if humid_temp == "BME280":
            i2c = board.I2C()
            self.ht_sensor = Bme280(i2c)
            self.ht_sensor.set_sea_level_pressure(1022.2)
        elif humid_temp == "DHT11":
            self.ht_sensor = adafruit_dht.DHT11(board.D18)
        elif humid_temp == "DHT22":
            self.ht_sensor = adafruit_dht.DHT22(board.D18)
        else:
            self.ht_sensor = None

        # For now we want to leave SCL to pin 3 and SDA to pin 2 for i2c interface.
        # meaning moisture sensor will need to be connected to these pins
        if moisture == "SIM":
            self.moisture_sensor = None
        else:
            self.moisture_sensor = Seesaw(busio.I2C(board.D3, board.D2),
                                          addr=0x36)

        if gpio_flow == "SIM":
            self.gpio_flow = None
        else:
            self.gpio_flow = FrequencySignal(gpio_flow)
def soil_reading():
    #read moisture level through capacitive touch pad
    ss = Seesaw(i2c_bus, addr=0x36)
    touch = ss.moisture_read()
    time.sleep(1)
    touch2 = ss.moisture_read()
    difference = touch - touch2

    #check sensor for daily errors
    if (difference > 3 or difference < -3):
        print("moisture warning", difference)

    

    #read temperature from  the temperature from the temperature sensor
    temp = ss.get_temp()
    time.sleep(1)
    temp2 = ss.get_temp()
    temp_difference = temp - temp2

    #check sensor for daily errors
    if (temp_difference > 3 or temp_difference < -3):
        print("tempurature warning", temp_difference)
    
    print("temp: ",temp, " moisture: ",touch)
    time.sleep(1)
Ejemplo n.º 19
0
class InputModule(AbstractInput):
    """A sensor support class that measures soil moisture using adafruit's i2c soil sensor."""
    def __init__(self, input_dev, testing=False):
        super().__init__(input_dev, testing=testing, name=__name__)

        self.sensor = None

        if not testing:
            self.try_initialize()

    def initialize(self):
        from adafruit_seesaw.seesaw import Seesaw
        from adafruit_extended_bus import ExtendedI2C

        try:
            self.sensor = Seesaw(ExtendedI2C(self.input_dev.i2c_bus),
                                 addr=int(str(self.input_dev.i2c_location),
                                          16))
        except:
            self.logger.exception("Setting up sensor")

    def get_measurement(self):
        if not self.sensor:
            self.logger.error(
                "Error 101: Device not set up. See https://kizniche.github.io/Mycodo/Error-Codes#error-101 for more info."
            )
            return

        self.return_dict = copy.deepcopy(measurements_dict)

        if self.is_enabled(0):
            self.value_set(0, self.sensor.moisture_read())

        if self.is_enabled(1):
            self.value_set(1, self.sensor.get_temp())

        return self.return_dict
Ejemplo n.º 20
0
class SoilSensor:
    i2c_bus = busio.I2C(SCL, SDA)
    # Need to put the address into the sensor constructor for each
    ss = Seesaw(i2c_bus, addr=0x36)

    def get_moisture(self):
        i2c_bus = busio.I2C(SCL, SDA)
        # Need to put the address into the sensor constructor for each
        ss = Seesaw(i2c_bus, addr=0x36)
        # read moisture level through capacitive touch pad
        moisture = ss.moisture_read()
        print("Soil Moisture Reading:", moisture)
        return moisture
    
    def get_temperature(self):
        i2c_bus = busio.I2C(SCL, SDA)
        # Need to put the address into the sensor constructor for each
        ss = Seesaw(i2c_bus, addr=0x36)
        # read temperature from the temperature sensor
        temp = ss.get_temp()
        print("Soil Temperatured Reading:", temp)
        return temp
Ejemplo n.º 21
0
#This is the tutorial testing for the soil sensor
#Just wired all my sensors and tested them individually
#Tomorrow I wire them all on the same board if I can and run it on a cron command
# to start dumping data into a database with SQLite-
#I will have photos posted on how I wired each sensor up to the bread board
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 from the temperature sensor
    temp = ss.get_temp()

    print("temp: " + str(temp) + " moisture: " + str(touch))
    time.sleep(1)
# 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)
Ejemplo n.º 23
0
background, a smaller purple rectangle, and some yellow text.
"""

import board
import displayio
import terminalio
from adafruit_display_text import label
from adafruit_seesaw.seesaw import Seesaw
from adafruit_st7735r import ST7735R

# Release any resources currently in use for the displays
displayio.release_displays()

reset_pin = 8
i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
ss.pin_mode(reset_pin, ss.OUTPUT)

spi = board.SPI()
tft_cs = board.D5
tft_dc = board.D6

display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)

ss.digital_write(reset_pin, True)
display = ST7735R(display_bus,
                  width=160,
                  height=80,
                  colstart=24,
                  rotation=270,
                  bgr=True)
Ejemplo n.º 24
0
dht_pin = 4
air_humidity, air_temperature = Adafruit_DHT.read_retry(dht_sensor, dht_pin)

# Current plant that is being monitored
plant = 'palm'

# connnect to database
con = psycopg2.connect(database=target_db,
                       user=db_user,
                       password=user_password,
                       host='localhost')
cur = con.cursor()

i2c_bus = busio.I2C(SCL, SDA)

ss = Seesaw(i2c_bus, addr=0x36)

# read moisture level several times and take average to limit measure error
measurements = 0
max_moisture = 0
min_moisture = 2000

for i in range(15):
    moisture_measurement = ss.moisture_read()
    measurements = measurements + moisture_measurement

    if moisture_measurement > max_moisture:
        max_moisture = moisture_measurement

    if moisture_measurement < min_moisture:
        min_moisture = moisture_measurement
Ejemplo n.º 25
0
esp.set_certificate(DEVICE_CERT)

# Set AWS RSA Private Key
esp.set_private_key(DEVICE_KEY)

# Connect to WiFi
print("Connecting to WiFi...")
wifi.connect()
print("Connected!")

# Initialize MQTT interface with the esp interface
MQTT.set_socket(socket, esp)

# Soil Sensor Setup
i2c_bus = busio.I2C(board.SCL, board.SDA)
ss = Seesaw(i2c_bus, addr=0x36)


# Define callback methods which are called when events occur
# pylint: disable=unused-argument, redefined-outer-name
def connect(client, userdata, flags, rc):
    # This function will be called when the client is connected
    # successfully to the broker.
    print('Connected to AWS IoT!')
    print('Flags: {0}\nRC: {1}'.format(flags, rc))

    # Subscribe client to all shadow updates
    print("Subscribing to shadow updates...")
    aws_iot.shadow_subscribe()

Ejemplo n.º 26
0
                    | (1 << BUTTON_SEL))
numbers = {
    '0': [0x1E, 0x21, 0x1E],
    '1': [0x11, 0x3F, 0x01],
    '2': [0x13, 0x25, 0x19],
    '3': [0x21, 0x29, 0x16],
    '4': [0x38, 0x08, 0x3F],
    '5': [0x39, 0x29, 0x26],
    '6': [0x1E, 0x29, 0x06],
    '7': [0x23, 0x2C, 0x30],
    '8': [0x16, 0x29, 0x16],
    '9': [0x10, 0x29, 0x1E],
}

i2c_bus = busio.I2C(board.SCL, board.SDA)
ss = Seesaw(i2c_bus)
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)

wing = dotstar_featherwing.DotStarFeatherWing()
wing.auto_write = False
# wing.brightness = 0.2

purple = (100, 0, 100)
black = (0, 0, 0)
flash = (250, 220, 220)
turquoise = (0, 100, 50)
red = (220, 0, 0)
green = (0, 220, 0)
blueish = (0, 0, 150)

wall = turquoise
Ejemplo n.º 27
0
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)
Ejemplo n.º 28
0
# CircuitPython 3.0 CRICKIT demo
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo
from busio import I2C
import audioio
import microcontroller
import board
import time

i2c = I2C(board.SCL, board.SDA)
ss = Seesaw(i2c)

print("Yanny or Laurel data logging!")

LOOKATPERSON = 90
LOOKLEFT = 60
LOOKRIGHT = 120

#################### 1 Servo
pwm = PWMOut(ss, 17)
pwm.frequency = 50
myservo = servo.Servo(pwm)
myservo.angle = LOOKATPERSON  # introduce yourself

#################### 2 buttons w/2 LEDs
BUTTON_1 = 2
BUTTON_2 = 3
LED_1 = 8
LED_2 = 9
Ejemplo n.º 29
0
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)
Ejemplo n.º 30
0
# 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
Ejemplo n.º 31
0
        return ~self.ss.digital_read_bulk(self.mask)


class DummyAudio:
    def play(self, f, loop=False):
        pass

    def stop(self):
        pass

    def mute(self, mute):
        pass


i2c = board.I2C()
ss = Seesaw(i2c, 0x5E)
spi = board.SPI()
displayio.release_displays()
while not spi.try_lock():
    pass
spi.configure(baudrate=24000000)
spi.unlock()
ss.pin_mode(8, ss.OUTPUT)
ss.digital_write(8, True) # reset display
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80,
                            rowstart=24)
del _INIT_SEQUENCE
buttons = GamePadSeesaw(ss)
audio = DummyAudio()
backlight = PWMOut(ss, 5)
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor
import board
import time

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
motor_a.throttle = 0.5  # half speed forward

# Create drive (PWM) object
my_drive = PWMOut(seesaw, 13)  # Drive 1 is on s.s. pin 13
my_drive.frequency = 1000  # Our default frequency is 1KHz

while True:

    my_drive.duty_cycle = 32768  # half on
    time.sleep(0.8)

    my_drive.duty_cycle = 16384  # dim
    time.sleep(0.1)

    # and repeat!
Ejemplo n.º 33
0
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):