Esempio n. 1
0
    def __init__(self):
        # Create a DotStar instance
        spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
                      mosi=Pin(TinyPICO.DOTSTAR_DATA),
                      miso=Pin(TinyPICO.SPI_MISO))
        self.dotstar = DotStar(
            spi, 1, brightness=0.5)  # Just one DotStar, half brightness

        # Turn on the power to the DotStar
        TinyPICO.set_dotstar_power(True)
        self.dotstar[0] = (255, 0, 0, 0.5)

        # Define state
        self.x = 0
        self.y = 0

        self.prev_x = 0
        self.prev_y = 0

        # Define buttons
        self.pin_forward = Pin(5, Pin.IN)
        self.pin_reverse = Pin(23, Pin.IN)
        self.pin_right = Pin(19, Pin.IN)
        self.pin_left = Pin(18, Pin.IN)

        # Create our device
        self.joystick = Joystick("Joystick")
        # Set a callback function to catch changes of device state
        self.joystick.set_state_change_callback(self.joystick_state_callback)
        # Start our device
        self.joystick.start()
Esempio n. 2
0
def toggle(state=None):
    __init_tinyrgb()
    if state is None:
        state = DOTSTAR_STATE[0]
    # Save state
    DOTSTAR_STATE[0] = 0 if state else 1
    if state:
        TinyPICO.set_dotstar_power(False)
        return "Turn OFF"
    else:
        TinyPICO.set_dotstar_power(True)
        setrgb()
        return "Turn ON"
Esempio n. 3
0
def init_APA102():
    global DOTSTAR
    # Configure SPI for controlling the DotStar
    # Internally we are using software SPI for this as the pins being used are not hardware SPI pins
    spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
                  mosi=Pin(TinyPICO.DOTSTAR_DATA),
                  miso=Pin(TinyPICO.SPI_MISO))
    # Create a DotStar instance
    DOTSTAR = DotStar(spi, 1,
                      brightness=0.4)  # Just one DotStar, half brightness
    # Turn on the power to the DotStar
    TinyPICO.set_dotstar_power(True)
    return True
Esempio n. 4
0
from machine import Pin, SoftSPI
import tinypico as TinyPICO
from dotstar import DotStar
import time, random, micropython, gc

# Configure SPI for controlling the DotStar
# Internally we are using software SPI for this as the pins being used are not hardware SPI pins
spi = SoftSPI(sck=Pin(TinyPICO.DOTSTAR_CLK),
              mosi=Pin(TinyPICO.DOTSTAR_DATA),
              miso=Pin(TinyPICO.SPI_MISO))

# Create a DotStar instance
dotstar = DotStar(spi, 1, brightness=0.5)  # Just one DotStar, half brightness

# Turn on the power to the DotStar
TinyPICO.set_dotstar_power(True)

# Say hello
print("\nHello from TinyPICO!")
print("--------------------\n")

# Show some info on boot
print("Battery Voltage is {}V".format(TinyPICO.get_battery_voltage()))
print("Battery Charge State is {}\n".format(TinyPICO.get_battery_charging()))

# Show available memory
print("Memory Info - micropython.mem_info()")
print("------------------------------------")
micropython.mem_info()

# Create a colour wheel index int
Esempio n. 5
0
BUT_1 = Pin(26, Pin.IN)
BUT_2 = Pin(27, Pin.IN)
BUT_3 = Pin(15, Pin.IN)
BUT_4 = Pin(14, Pin.IN)

# Light  Sensor
LIGHT_SENS = Pin(32, Pin.IN)

# Speaker
SPEAKER = Pin(25, Pin.OUT)

# Blue LED
LED = Pin(4, Pin.OUT)

# Setup

# Turn off the power to the DotStar
TinyPICO.set_dotstar_power(False)

# Configure I2C for controlling anything on the I2C bus
# Software I2C only for this example but the next version of MicroPython for the ESP32 supports hardware I2C too
i2c = I2C(scl=Pin(22), sda=Pin(21))

# Example initialisers for the  OLED and IMU

# Initialise the LIS3HD 3-Axis IC
# imu = lis3dh.LIS3DH_I2C(i2c)

# Initialise the OLED screen
# oled = ssd1306.SSD1306_I2C(128, 64, i2c)
Esempio n. 6
0
File: board.py Progetto: tve/mqboard
def define_led():
    global act_led, fail_led, bat_volt_pin, bat_fct
    if kind == "tve-bare":
        # bare esp32-wroom module with LED across IO23 and gnd
        lpin = machine.Pin(23, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "huzzah32":
        # Adafruit Huzzah32 feather
        lpin = machine.Pin(13, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        fail_led = led
    elif kind == "esp32-sim1":
        # TvE custom ESP32 SIM module v1
        lpin1 = machine.Pin(2, machine.Pin.OUT, None, value=1)
        act_led = lambda v: lpin1(v)
        lpin2 = machine.Pin(5, machine.Pin.OUT, None, value=1)
        fail_led = lambda v: lpin2(not v)
        bat_volt_pin = machine.ADC(machine.Pin(35))
        bat_volt_pin.atten(machine.ADC.ATTN_11DB)
    elif kind == "lolin-d32":
        # Wemos Lolin D-32
        lpin = machine.Pin(5, machine.Pin.OUT, None, value=1)
        led = lambda v: lpin(not v)
        bat_volt_pin = machine.ADC(machine.Pin(35))
        bat_volt_pin.atten(machine.ADC.ATTN_11DB)
        act_led, fail_led = (led, led)
    elif kind == "nodemcu":
        # NodeMCU
        lpin = machine.Pin(2, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "esp32thing":
        # Sparkfun ESP32 Thing
        lpin = machine.Pin(5, machine.Pin.OUT, None, value=0)
        led = lambda v: lpin(v)
        act_led, fail_led = (led, led)
    elif kind == "ezsbc":
        # EzSBC
        lpin1 = machine.Pin(19, machine.Pin.OUT, None, value=1)
        act_led = lambda v: lpin1(not v)
        lpin2 = machine.Pin(16, machine.Pin.OUT, None, value=1)
        fail_led = lambda v: lpin2(not v)
    elif kind == "tinypico":
        # TinyPICO has an RGB LED so we use the red channel for WiFi and the blue
        # channel for message rx
        from machine import SPI, Pin
        import tinypico as TinyPICO
        from dotstar import DotStar

        spi = SPI(
            sck=Pin(TinyPICO.DOTSTAR_CLK),
            mosi=Pin(TinyPICO.DOTSTAR_DATA),
            miso=Pin(TinyPICO.SPI_MISO),
        )
        dotstar = DotStar(spi, 1, brightness=0.5)  # Just one DotStar, half brightness
        TinyPICO.set_dotstar_power(True)

        color = [255, 0, 0]

        def set_red(v):
            color[0] = 255 if v else 0
            dotstar[0] = color

        def set_blue(v):
            color[2] = 255 if v else 0
            dotstar[0] = color

        fail_led = set_red
        act_led = set_blue
    elif kind == "pybd":
        from pyb import LED

        def led(n, v):
            if v:
                LED(n).on()
            else:
                LED(n).off()

        act_led = lambda v: led(3, v)
        fail_led = lambda v: led(1, v)
# BME280 with OLED display

from machine import Pin, I2C, RTC
import ssd1306, time, bme280_float
from tinypico import set_dotstar_power

set_dotstar_power(False)
rtc = RTC()
i2c = I2C(scl=Pin(21), sda=Pin(22))
oled = ssd1306.SSD1306_I2C(128, 32, i2c, 0x3c)  # small display
bme = bme280_float.BME280(i2c=i2c)

oled.contrast(0)  #set contrast to low


def display_temperature():
    temp, pres, hum = bme.values
    oled.fill(0)
    oled.text('T: ' + temp, 0, 0, 1)
    oled.show()


def display_humidity():
    temp, pres, hum = bme.values
    oled.fill(0)
    oled.text('H: ' + hum, 0, 0, 1)
    oled.show()


def display_pressure():
    temp, pres, hum = bme.values
Esempio n. 8
0
 def off(self):
     TP.set_dotstar_power(False)
     dbg("response off")
     return True
Esempio n. 9
0
 def on(self):
     TP.set_dotstar_power(True)
     DOTSTAR[0] = self.on_color
     dbg("response on")
     return True
Esempio n. 10
0
# DotStar Setup
import tinypico as TP
from micropython_dotstar import DotStar

# Color Values
RED = (255, 0, 0, 0.5)
GREEN = (0, 255, 0, 0.5)
BLUE = (0, 0, 255, 0.5)
WHITE = (255, 255, 255, 0.5)

spi = machine.SPI(sck=machine.Pin(TP.DOTSTAR_CLK),
                  mosi=machine.Pin(TP.DOTSTAR_DATA),
                  miso=machine.Pin(TP.SPI_MISO))
DOTSTAR = DotStar(spi, 1, brightness=0.5)  # Just one DotStar, half brightness
TP.set_dotstar_power(False)

# This XML is the minimum needed to define one of our virtual switches
# to the Amazon Echo Dot / Amazon Echo (2nd generation)

SETUP_XML = """<?xml version="1.0"?>
<root>
  <device>
    <deviceType>urn:LeMaRiva:device:controllee:1</deviceType>
    <friendlyName>%(device_name)s</friendlyName>
    <manufacturer>Belkin International Inc.</manufacturer>
    <modelName>Emulated Socket</modelName>
    <modelNumber>3.1415</modelNumber>
    <UDN>uuid:Socket-1_0-%(device_serial)s</UDN>
    <serialNumber>221517K0101769</serialNumber>
    <binaryState>0</binaryState>