コード例 #1
0
def find(xstr, directory="examples"):
    from util.shell.terminal import printTitle
    printTitle("find file > " + xstr)
    from os import listdir
    ls = listdir(directory)
    ls.sort()
    for f in ls:
        if f.find(xstr) > -1:
            print(f)
コード例 #2
0
def upgrade(
        urlTar="https://octopusengine.org/download/micropython/stable.tar"):
    from util.shell.terminal import printTitle
    printTitle("upgrade from url > ")
    print(urlTar)
    from util.setup import deploy
    try:
        deploy(urlTar)
    except Exception as e:
        print("Exception: {0}".format(e))
コード例 #3
0
def rm(file=None):
    if file:
        from util.shell.terminal import printTitle, runningEffect
        printTitle("remove file > " + file)
        try:
            from os import remove
            print("(Always be careful)")
            remove(file)
            runningEffect()
        except Exception as e:
            print("Exception: {0}".format(e))
    else:
        print("Input param: path + file name")
コード例 #4
0
def cp(fileSource, fileTarget="main.py"):
    from util.shell.terminal import printTitle, runningEffect
    printTitle("file_copy to " + fileTarget)
    print("(Always be careful)")
    fs = open(fileSource)
    data = fs.read()
    fs.close()

    runningEffect()
    ft = open(fileTarget, 'w')
    ft.write(data)
    ft.close()
    print(" ok")
コード例 #5
0
def cat(file='main.py', title=False):  # concatenate - prepare
    """print data: f("filename") """
    fi = open(file, 'r')
    if title:
        from util.shell.terminal import printTitle
        printTitle("file > " + file)
        # file statistic
        lines = 0
        words = 0
        characters = 0
        for line in fi:
            wordslist = line.split()
            lines = lines + 1
            words = words + len(wordslist)
            characters = characters + len(line)

        print("Statistic > lines: " + str(lines) + " | words: " + str(words) +
              " | chars: " + str(characters))
        print('-' * SEPARATOR_WIDTH)
        fi = open(file, 'r')
    for line in fi:
        print(line, end="")
    globals()["cat"] = cat
コード例 #6
0
from time import sleep
from util.octopus import *
from util.shell.terminal import printTitle

d7 = disp7_init()

d7.show("Connect")
iface = w_connect()
#iface = lan_connect()

printTitle("remote terminal")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

import webrepl
webrepl.start()

print("IP Address: ")
ip = iface.ifconfig()[0]
print(ip)

loop = 0
run = True

while run:
    d7.show("1-{0}.{1}.".format(ip.split('.')[0], ip.split('.')[1]))
    sleep(2)
    d7.show("2-{0}.{1}".format(ip.split('.')[2], ip.split('.')[3]))
    sleep(2)
    loop += 1
    if loop == 3: run = False
コード例 #7
0
from time import sleep
from util.octopus import button_init, button, disp7_init
from util.shell.terminal import printTitle

BB = button_init(0)  # button boot = 0
# debounce: read 10 samples, only tolerate one false reading
debounce = 9

d7 = disp7_init()

select = 0
sec = 0
run = False

printTitle("stopwatch.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

while True:
    # print(select)
    if run:
        sec += 1
        d7.show(sec / 10)
        print(sec / 10)
        sleep(0.1)

    if button(BB)[0] >= debounce:
        # beep()
        select += 1
        sleep(0.3)
コード例 #8
0
# move step pixels with each button press
step = 5
# debounce: read 10 samples, only tolerate one false reading
debounce = 9

o.fill(0)
o.hline(0, 51, 128, 1)
o.text("octopusLAB 2019", 3, 64 - 7)
o.show()

# draw first position
o.draw_icon(ICON_arrow, x, y)
# init helper var
old_x = x

printTitle("button2oled.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

while True:
    # get new position
    old_x = x
    if button(L)[0] >= debounce: x -= step
    if button(R)[0] >= debounce: x += step
    # only if changed
    if old_x != x:
        # clear current position
        o.draw_icon(ICON_clr, old_x, y)
        # draw new icon
        o.draw_icon(ICON_arrow, x, y)
    # sleep
コード例 #9
0
        displayDigit(o, int(num[n]), n, 2, 6)

XMAX = 128
YMAX = 64
o = oled_init(XMAX, YMAX)      # init oled display
o.clear()            # clear

# default coordinates for position
x = int(XMAX/2)
y = int(YMAX/2)
size = 5

vx = 3
vy = 3

printTitle("oled_pong.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

def drawBall(oled, xold, yold, x, y):
   oled.fill_rect(xold, yold, size, size, 0)
   oled.fill_rect(x, y, size, size, 1)
   oled.show()

drawBall(o,x,y,x,y)   
score = 0

while True:
   xold = x
   yold = y
   x += vx
コード例 #10
0

def bitcoin_usd():
    btcusd = 888

    try:
        res = urequests.get(
            "https://api.coinpaprika.com/v1/tickers/btc-bitcoin")
        btcusd = res.json()['quotes']["USD"]["price"]

    except:
        x = 0
    return int(btcusd)


printTitle("get_bitcoin.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

while True:
    btc = bitcoin_usd()
    print(btc)
    d7.show(btc)
    sleep(10)
    d7pause(sl=0.6)
    d7pause(sl=0.3)
    d7.show(keep_alive)
    sleep(1)
    d7pause(sl=0.3)
    d7.show("btc-usd")
    keep_alive += 1
コード例 #11
0
# octopusLAB simple example
# ESP32board with "BUILT_IN_LED" and OLED display

import machine
from time import sleep
from util.octopus import Env, w, time_init, get_hhmm, get_hhmmss
from util.shell.terminal import printTitle
isOled = False
isDisp7 = True

printTitle("examples/deep_sleep1.py")
from util.led import Led
led = Led(2)

if get_hhmm() == "00:00":
    print("first time setup > ")
    w()
    time_init()

print(get_hhmmss())


def sendValue(val=0, urlPOST="http://your_server/add_item_to_database.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(
コード例 #12
0
# simple basic example - ESP32
# cp("examples/clock.py") > main.py

from time import sleep
from util.octopus import w, get_hhmm, time_init, clt
from util.shell.terminal import printTitle


def clock():
    clt()
    print(get_hhmm(":"))
    sleep(1)
    clt()
    print(get_hhmm(" "))
    sleep(1)


w()  # wifi connect
time_init()  # server > time setup

printTitle("examples/clock.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

while True:
    clock()
コード例 #13
0
# simple basic example - ESP32
# cp("examples/bme280.py") > main.py

from time import sleep
from util.octopus import i2c_init
from util.shell.terminal import printTitle
from bme280 import BME280


def bme280_init():
    i2c = i2c_init(1)
    bme = BME280(i2c=i2c)
    return bme


printTitle("examples/bme280.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

bme280 = bme280_init()

while True:
    print(bme280.values)
    sleep(1)
コード例 #14
0
# octopusLAB simple example 2019
# HW: ESP32 + i2c OLED display
# ampy -p /COM6 put examples/oled_random_lines.py main.py
# start: import examples/oled_random_lines

from util.octopus import oled_init
from util.shell.terminal import printTitle
from os import urandom

o = oled_init()      # init oled display
o.fill(0)            # clear

# default coordinates for position
x = 0
y = 0

printTitle("oled_random_lines.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

while True:
   old_x = x
   old_y = y
   # get new position
   x = int(urandom(1)[0]/2)
   y = int(urandom(1)[0]/4)

   o.line(old_x, old_y, x, y, 1)
   o.show()
   # sleep(0.1) # slow or fast
コード例 #15
0
# simple basic example - ESP32 - thermometer
# cp("examples/bme280-therm.py") > main.py


from time import sleep
from util.octopus import i2c_init, disp7_init
from util.shell.terminal import printTitle
from bme280 import BME280

def bme280_init():
    i2c = i2c_init(1)
    bme = BME280(i2c=i2c)
    print(bme.values)
    return bme

printTitle("examples/bme280-therm.py")
print("this is simple Micropython example | ESP32 & octopusLAB")
print()

disp7 = disp7_init()
sleep(2)

bme280 = bme280_init()

while True:
    print(bme280.values)
    disp7.show(bme280.values[0])
    sleep(1)