from time import sleep from util.octopus import w, lcd2_init, get_hhmm, time_init from util import printTitle w() # wifi connect lcd = lcd2_init() # 8 x 7segment display init lcd.clear() lcd.move_to(3, 0) lcd.putstr("octopusLAB") def clock(): lcd.move_to(5, 1) lcd.putstr(get_hhmm(":")) sleep(0.5) lcd.move_to(5, 1) lcd.putstr(get_hhmm(" ")) sleep(1) time_init() # server > time setup printTitle("examples/clock.py") print("this is simple Micropython example | ESP32 & octopusLAB") print() while True: clock()
# 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 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(
BALL_SIZE = 5 OLED = oled_init(SCREEN_WIDTH, SCREEN_HEIGHT) # init oled display OLED.clear() # clear L, R, C = buttons_init() # def displayNum(num): # num = str(num) # for n in range(len(num)): # displayDigit(OLED, int(num[n]), n, 2, 6) # default coordinates for position printTitle("oled_pong.py") print("this is simple Micropython example | ESP32 & octopusLAB") print() class oled_pong: def __init__(self): #print("__init__") self.start_game(self) def start_game(self, start_lives = 3): x = int(SCREEN_WIDTH/2) y = 50 paddle_x = x-int(PADDLE_WIDTH/2) self.score = 0
from time import sleep from util.octopus import button_init, button, disp7_init from util 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)
# 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
# get bitcoin from time import sleep import urequests, json from util.octopus import w, disp7_init from util import printTitle w() d7 = disp7_init() def bitcoin_usd(): res = urequests.get("https://api.coinmarketcap.com/v1/ticker/bitcoin/") btcusd = res.json()[0]['price_usd'] return float(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(20) d7.show("btc-usd") sleep(3)
# 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 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)
# simple basic example - ESP32 # cp("examples/bme280.py") > main.py from time import sleep from util.octopus import i2c_init from util 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)
from time import sleep from util.octopus import * from util 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