Ejemplo n.º 1
0
# octopusLAB simple example
# ESP32board + wifi -> analog 36, 39, ...

from components.analog import Analog
from utils.octopus import *

octopus()  # include main library

anIn = Analog(36)  #analog input


def sendValue(value=0, urlPOST="http://www.octopusengine.org/iot17/add18.php"):
    from urequests import post
    header = {}
    header["Content-Type"] = "application/x-www-form-urlencoded"
    deviceID = Env.uID
    place = "octoPy32"
    # value =  int(float(Env.ver)*100)
    try:
        postdata_v = "device={0}&place={1}&value={2}&type={3}".format(
            deviceID, place, value, "batRaw")
        res = post(urlPOST, data=postdata_v, headers=header)
        sleep_ms(100)
        print("sendValue.ok")
    except:
        print("E.sendValue")


print('Start >')
led.value(1)
w()
Ejemplo n.º 2
0
print("--- octopusLAB: test_analog ---")

print("-> init")

from components.analog import Analog
an2 = Analog(33)

print("-> get_adc_aver() value:")
data = an2.get_adc_aver(8)
print(data)

print("-" * 30)
Ejemplo n.º 3
0
# The MIT License (MIT)
# Copyright (c) 2020 Jan Cespivo, Jan Copak
# octopusLAB pubsub example

from time import sleep
import pubsub

print("start: ps_analog.py")

from components.analog import Analog

an2 = Analog(36)

# publish test
#pubsub.publish('value', 123)
sleep(3)

while True:
    value = an2.get_adc_aver(8)
    #print(value)
    pubsub.publish('value', value)
    sleep(0.2)
Ejemplo n.º 4
0
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()

led.blink()
sleep(3)
led.blink()


min = 0
Ejemplo n.º 5
0
    if io_conf.get('relay'):
        print("rel | ",end="")
        RELAY = Pin(pinout.RELAY_PIN) # pin(33) Robot(DEV2)

        def disp2(d,mess,r=0,s=0):
            #d.clear()
            d.move_to(s, r) # x/y
            d.putstr(str(mess))

    if io_conf.get('ad0') or io_conf.get('ad1') or io_conf.get('ad2'):
        print("Analog | ",end="")
        from components.analog import Analog
        #adcpin = pinout.ANALOG_PIN
        adcpin = 39 #default
        an = Analog(adcpin)
        #an0 = Analog(io_conf.get('ad0'))

    if io_conf.get('temp'):
        print("temp | ",end="")
        try: PIN_TEMP = pinout.ONE_WIRE_PIN
        except: PIN_TEMP = 17 # ROBOT
        def temp_init(pin = PIN_TEMP):
            from components.iot import Thermometer
            ts = Thermometer(pin)
            # tx = tt.ds.scan()
            # ts.read_temp(tx[0])
            return ts

    if io_conf.get('servo'):
        print("servo | ",end="")
Ejemplo n.º 6
0
# octopusLAB simple exampple

from time import sleep
from components.analog import Analog

an2 = Analog(33)  # DEV2

while True:
    data = an2.get_adc_aver(8)  # get average of 8 values
    print(data)
    sleep(5)
Ejemplo n.º 7
0
# import upip
# upip.install('micropython-umqtt.robust')

from time import sleep
from utils.wifi_connect import read_wifi_config, WiFiConnect
from utils.mqtt import MQTT
from utils.pinout import set_pinout
from components.led import Led
from components.analog import Analog
from gc import mem_free

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

pinout = set_pinout()
led = Led(pinout.BUILT_IN_LED)
an34 = Analog(34)  # y
an35 = Analog(35)  # x


def simple_blink():
    led.value(1)
    sleep(0.5)
    led.value(0)
    sleep(0.5)


def mqtt_handler(topic, msg):
    print("MQTT handler {0}: {1}".format(topic, msg))
    if "led" in topic:
        print("led:", end='')
        data = bytes.decode(msg)
Ejemplo n.º 8
0
from time import sleep_ms
from random import randrange

# lib imports
from hcsr04 import HCSR04
from colors_rgb import *

# octopus imports
from utils.pinout import set_pinout
from utils.octopus import oled_init
from components.rgb import Rgb
from components.analog import Analog
from components.servo import Servo  # todo: PWM double setup error
from utils.io_config import get_from_file 

battery = Analog(36) # TODO from pinout
pinout = set_pinout()

io_conf = get_from_file()

ws = Rgb(pinout.WS_LED_PIN,io_conf.get('ws'))
ir = Pin(pinout.DEV1_PIN, Pin.IN)

print('oled init start')
# OLED_I2C_ADDRESS = 60  # defaul is 0x3c = 60, alternative 35
oled = None
while not oled:
    try:
        # oled = oled_init(addr=OLED_I2C_ADDRESS)
        oled = oled_init()
        sleep_ms(500)
Ejemplo n.º 9
0
# simple basic example - ESP32 - Micropython - EDU_KIT1
# ROBOTboard with "BUILT_IN_LED", "WS RGB_LED" and "disp7"

from time import sleep

print("-" * 30)
print("ESP32 + Mictopython | main-voltmeter.py")
print("-" * 30)

from utils.octopus import disp7_init

d7 = disp7_init()

from components.analog import Analog

an36 = Analog(36)

k = 1.32 / 1423
while True:
    anRAW = an36.get_adc_aver()
    anV = round(anRAW * k, 2)
    print(anRAW, anV)
    d7.show(anV)
    sleep(0.5)
Ejemplo n.º 10
0
# octopusLAB simple example

from time import sleep
from components.analog import Analog
# from utils.octopus_lib import map
from components.servo import Servo

an2 = Analog(35)
s1 = Servo(16)

s1.set_degree(0)

# 0-150
amin = 0
amax = 150

while True:
    data =  an2.get_adc_aver(2)
    sleep(0.05)
    angle = map(data, 0, 4000, amin, amax)
    print(data,angle)
    s1.set_degree(angle)