Exemplo n.º 1
0
def octopus_debug(ledon=False, info=True):
    if ledon:
        from components.led import Led
        led = Led(2)

    def _octopus_debug(fnc):
        import time
        print("--- decorator --- @octopus_debug:")
        #if ledon: led.blink()

        try:
            fname = fnc.__name__
        except:
            fname = "?"

        def ff(*args, **kwargs):
            if ledon: led.value(1)
            start = time.time()
            result = fnc(*args, **kwargs)
            end = time.time() - start
            if ledon: led.value(0)

            print("=== function name: ", fname)
            print("=== duration (sec.) --->", str(end))
            return result

        return ff

    return _octopus_debug
Exemplo n.º 2
0
def led_init(pin = pinout.BUILT_IN_LED):
    from components.led import Led
    if pin is not None and pinout is not None and (pin == pinout.RXD0 or pin == pinout.TXD0):
        print("WARNING: PIN {0} is used for UART0. REPL Over serial will be unusable")

    led = Led(pin if pin is not None and pin > 0 else None)
    return led
Exemplo n.º 3
0
# octopusLAB simple example
# ESP32board with "BUILT_IN_LED"
# parameter: delay [ms]

from components.led import Led
# from utils.octopus import led # short way
from utils.pinout import set_pinout

print("---examples/blink_param.py---")

# _ARGS
# ToDo parse: delay=1000,pin=25
delay = 1000
try:
    delay = (int(_ARGS[0]))
    print("delay = ", str(delay))
except Exception as e:
    print("Exception: {0}".format(e))

pinout = set_pinout()  # set board pinout
led = Led(pinout.BUILT_IN_LED)  # BUILT_IN_LED = 2

# start main loop
while True:
    led.blink(delay)
Exemplo n.º 4
0
print("--- octopusLAB: test_led ---")

print("-> init")
from components.led import Led
led = Led(2)

print("-> blink()")
led.blink()

print("-> value() | toggle()")
led.value(1)
led.toggle()

print("-" * 30)
Exemplo n.º 5
0
from components.plc.inputs.fixed import plc_input_fixed_high, plc_input_fixed_low
# from components.plc.elements.rs import PLC_element_RS
from components.plc.elements.rs_pulse import PLC_element_RS_pulse
from components.plc.operands.op_and import PLC_operand_AND
from components.plc.operands.op_or import PLC_operand_OR
from components.lm75 import LM75B
from components.led import Led
from components.rgb import Rgb
from components.i2c_expander import Expander8

print("mqtt-plc.py > mqtt basic example")

print("--- RAM free ---> " + str(mem_free())) 

pinout = set_pinout()
led = Led(pinout.BUILT_IN_LED)

num_neo = 16 # 30 # number of Leds
np = Rgb(pinout.WS_LED_PIN,num_neo) 

ws_r = 0
ws_g = 0
ws_b = 0


IN1, IN2, IN3, IN4     = 0, 1, 2, 3
OUT1, OUT2, OUT3, OUT4 = 4, 5, 6, 7
# OUT4 - signalization

timer_counter = 0
periodic = False
Exemplo n.º 6
0
# octopusLAB pub sub module for led
# usage:
# import octopus.ps_led
# pubsub.publish('led_value', VALUE)

from components.led import Led
import pubsub

led = Led(2)


@pubsub.subscriber("led_value")
def led_val(led_value):
    led.value(led_value)


print("--- starting pubsub: ps_led (led_value) ---")
Exemplo n.º 7
0
# ramdisk for temp nn file
# MicroMLP - multilayer perceptron

from utils.ramdisk import RAMBlockDev
from time import sleep
from microMLP import MicroMLP
from components.led import Led
import os

led = Led(2)
led.blink()

print("---RAM disk init---")

bdev = RAMBlockDev(512, 50) # 512/1024/2048 ok
os.VfsLfs2.mkfs(bdev)
# os.VfsFat.mkfs(bdev)
os.mount(bdev, '/ramdisk')

print("---MLP init---")
mlp = MicroMLP.Create( neuronsByLayers           = [3, 2, 1],
                       activationFuncName        = MicroMLP.ACTFUNC_GAUSSIAN,
                       layersAutoConnectFunction = MicroMLP.LayersFullConnect )

nnFalse  = MicroMLP.NNValue.FromBool(False)
nnTrue   = MicroMLP.NNValue.FromBool(True)
# and
mlp.AddExample( [nnTrue, nnFalse, nnFalse], [nnFalse] )
mlp.AddExample( [nnTrue, nnFalse, nnTrue ], [nnFalse] )
mlp.AddExample( [nnTrue, nnTrue , nnTrue ], [nnTrue] )
mlp.AddExample( [nnTrue, nnTrue , nnFalse], [nnFalse] )
Exemplo n.º 8
0
from time import sleep
from machine import Pin
from utils.pinout import set_pinout
from utils.wifi_connect import read_wifi_config, WiFiConnect
from utils.mqtt import MQTT
from components.led import Led
from components.rgb import Rgb
from components.servo import Servo
from components.button import Button
from utils.octopus import disp7_init
from gc import mem_free

print("--- RAM free ---> " + str(mem_free()))

pinout = set_pinout()
built_in_led = Led(pinout.BUILT_IN_LED)

num_neo = 16  # 30 # number of Leds
np = Rgb(pinout.WS_LED_PIN, num_neo)

ws_r = 0
ws_g = 0
ws_b = 0

boot_pin = Pin(0, Pin.IN)
boot_button = Button(boot_pin, release_value=1)

servo = Servo(pinout.PWM1_PIN)
d7 = disp7_init()

Exemplo n.º 9
0
# octopusLAB - ESP32board + EDU_SHIELD1

# from utils.pinout import set_pinout
# pinout = set_pinout()

# --- leds ---

from components.led import Led

led2 = Led(16)  # PWM2
led3 = Led(25)  # PWM3

# --- buttons ---
from machine import Pin
from components.button import Button

boot_pin = Pin(0, Pin.IN)
boot_button = Button(boot_pin, release_value=1)

pin34 = Pin(34, Pin.IN)
pin35 = Pin(35, Pin.IN)
# pin36 = Pin(36, Pin.IN)
# pin39 = Pin(39, Pin.IN)
right_button = Button(pin35, release_value=1)
left_button = Button(pin34, release_value=1)

# --- relay ---
relay = Led(17)  # PWM1

# --- oled ---
# I2C oled display
Exemplo n.º 10
0
# octopusLAB test - 2019
from time import sleep
from utils.octopus import button_init, button, w, web_server, ap_init
from components.led import Led
led = Led(2)
button0 = button_init(0)
debounce = 9
ap = False

print("esp32 web server - start >")
for id in range(10):
    print(10 - id)
    led.blink()
    if button(button0)[0] >= debounce:
        print("button > AP_start")
        ap = True
        for id in range(5):
            led.blink(100, 100)
        break

sleep(1)
if ap: wc = ap = ap_init()
else: wc = w()

sleep(1)
web_server()
Exemplo n.º 11
0
uID5 = getUid(short=5)

from time import sleep
from machine import Pin,PWM,Timer
from components.iot.pwm_fade import fade_in
from components.led import Led
from components.button import Button
from time import ticks_ms, ticks_diff
from components.analog import Analog
from components.iot import Thermometer
from utils.database.influxdb import InfluxDB
from utils.wifi_connect import WiFiConnect

print("init")
led_light = False
led = Led(2)
duty = 0
pir = 0
keep_alive = 0
light_treshold = 1500
led_button = Button(0, release_value=1)
anLight = Analog(36)
pwm = PWM(Pin(17, Pin.OUT), 500, duty) # PWM1
tt = Thermometer(32)
print("light", anLight.get_adc_aver(8))
print("temp.",tt.get_temp())

print("wifi")
net = WiFiConnect()
net.connect()
Exemplo n.º 12
0
import blesync_uart.server
import utils.ble.bluefruit as bf

from utils.octopus_lib import getUid

uID5 = getUid(short=5)

print("OctopusLAB edu shield 1, 2 x butn, OLED, BLE")

# from utils.pinout import set_pinout
# pinout = set_pinout()

from components.button import Button
from components.led import Led

led = Led(2)
led2 = Led(16)
led3 = Led(17)
oled = oled_init()

led.blink(100)
led2.blink(100)
led3.blink(100)

print("thread_blink")
import _thread


def tblink(num=20, period_ms=50):
    for _ in range(num):
        led.value(1)
Exemplo n.º 13
0
from time import sleep

print("--- examples/test_shield.py ---")
print("-" * 30)
print("--- Led2 | Led3 ---")
from components.led import Led
l2 = Led(25)
l3 = Led(27)

l2.blink()
l3.blink()

print("--- buzzer ---")
from components.buzzer import Buzzer
piezzo = Buzzer(15)
piezzo.beep()
sleep(0.5)
piezzo.beep()

print("--- OLED ---")
from utils.octopus import oled_init
oled = oled_init()

print("--- Button ---")
from components.button import Button
btn_L = Button(34, release_value=1)
btn_R = Button(35, release_value=1)


@btn_L.on_press
def on_press_L_button():