def an_WF(WFname, WFpassword, WFpattern):
    """定义开发板连接无线网络的函数,返回MAC"""
    import network
    import time
    import machine
    from machine import Pin, I2C, SPI, Timer
    import ssd1306
    spi = SPI(baudrate=10000000,
              polarity=1,
              phase=0,
              sck=Pin(14, Pin.OUT),
              mosi=Pin(13, Pin.OUT),
              miso=Pin(12))
    display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(5), Pin(4), Pin(16))

    try:
        display.poweron()
        display.init_display()
        print('loading......')

    except Exception as ex:
        #led_blue.value(0)
        print('Unexpected error: {0}'.format(ex))
        display.poweroff()

    summ = 0
    wlan = network.WLAN(network.STA_IF)  # 设置开发板的网

    wlan.active(True)  # 打开网络连接

    if not wlan.isconnected():  # 判断是否有网络连接

        print('connecting to network...')
        display.fill(0)
        display.text('loading...', 23, 31)
        display.show()
        # 设置想要连接的无线网络
        if WFpattern == '1':
            wlan.connect(WFname)
        else:
            wlan.connect(WFname, WFpassword)

        while not wlan.isconnected():  # 等待连接上无线网络
            time.sleep(1)
            summ = summ + 1
            display.fill(0)
            if (summ <= 5):
                display.text('loading...', 23, 31)
            if (summ > 5 and summ <= 10):
                display.text('loading....', 17, 31)
            if (summ > 10 and summ <= 15):
                display.text('loading.....', 13, 31)
            if (summ > 15 and summ <= 20):
                display.text('loading......', 10, 31)
            display.show()
            if summ == 20:
                return "WF:OFF"
    return "WF:ON"
    """
Exemple #2
0
    def configure(self, config):

        super().configure(config)

        import ssd1306

        self.display = None

        try:

            if self.display_type == "SSD1306_I2C":

                i2c = machine.I2C(self.i2c.bus,
                                  scl=machine.Pin(self.i2c.gpio_scl),
                                  sda=machine.Pin(self.i2c.gpio_sda)
                                  #                    freq=self.i2c.max_freq
                                  )

                #          addrs = i2c.scan()
                #          print("Scanning I2C devices:", [hex(x) for x in addrs])
                #          if self.sla not in addrs:
                #            import ubinascii
                #            print("ICT device not detected on address", ubinascii.hexlify(device_addr))

                self.display = ssd1306.SSD1306_I2C(self.width, self.height,
                                                   i2c)

                self.display.poweron()

            elif self.display_type == "SSD1306_SPI":

                spi = None

                if self.bitbanging_mode:

                    spi = machine.SPI(self.spi.id,
                                      baudrate=self.spi.baudrate,
                                      polarity=self.spi.polarity,
                                      phase=self.spi.phase,
                                      sck=machine.Pin(self.spi.gpio_sck),
                                      mosi=machine.Pin(self.spi.gpio_mosi),
                                      miso=machine.Pin(self.spi.gpio_miso))

                else:

                    spi = machine.SPI(self.spi.id,
                                      baudrate=self.spi.baudrate,
                                      polarity=self.spi.polarity,
                                      phase=self.spi.phase)

                self.display = ssd1306.SSD1306_SPI(
                    self.width, self.height, spi,
                    machine.Pin(self.spi.gpio_dc),
                    machine.Pin(self.spi.gpio_res),
                    machine.Pin(self.spi.gpio_cs))

        except OSError as e:
            import kiota.Util as Util
            Util.log(self, "failed to configure display", e)
Exemple #3
0
def initDisplay(spi):
    dc = Pin(config.DC)
    rst = Pin(config.RST)
    cs = Pin(config.CS)
    oled_pwr = Pin(config.OLED_PWR, Pin.OUT, value=0)
    oled_pwr.value(1)
    display = ssd1306.SSD1306_SPI(config.DISPLAY_WIDTH, config.DISPLAY_HEIGHT,
                                  spi, dc, rst, cs)
    return display
Exemple #4
0
    def __init__(self):
        self.disp = ssd1306.SSD1306_SPI(128, 64, board.display_spi,
                           dc =  board.display_dc,
                           res = board.display_res,
                           cs =  board.display_cs,
                           external_vcc=False, mirror_v=True, mirror_h=True)

        self.disp.contrast(50)
        self.disp_image("logo")
        self.disp.show()
        self.erase_time = 0
        self.indicators = []
        self.indicators_width = 0
Exemple #5
0
def init_spi_oled():
    spi = SPI(-1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
    # ESP8266 Pin assignment
    #i2c = I2C(-1, scl=Pin(5), sda=Pin(4))

    oled_width = 128
    oled_height = 64
    oled = ssd1306.SSD1306_SPI(oled_width,
                               oled_height,
                               spi,
                               dc=Pin(17),
                               cs=Pin(5),
                               res=Pin(16))
    return oled
Exemple #6
0
    def __init__(self):
        self.disp = ssd1306.SSD1306_SPI(128,
                                        64,
                                        SPI(1),
                                        dc=Pin("B1", Pin.OUT),
                                        res=Pin("C9", Pin.OUT),
                                        cs=Pin("A8", Pin.OUT),
                                        external_vcc=False,
                                        mirror_v=True,
                                        mirror_h=True)

        self.disp.contrast(50)
        self.disp_image("img/logo.pbm")
        self.disp.show()
        self.erase_time = 0
Exemple #7
0
    def __init__(self):
        #Display connected through SPI bus
        self.disp = ssd1306.SSD1306_SPI(128, 64, board.display_spi,
                            dc =  board.display_dc,
                            res = board.display_res,
                            cs =  board.display_cs,
                            external_vcc=False, mirror_v=True, mirror_h=True)
#        #variant: display connected through I2C bus
#        from machine import Pin, I2C
#        self.disp = ssd1306.SSD1306_I2C(128, 64, I2C(1))
        self.disp.contrast(100) #0~255 TODO: Test ouside in bright sunlight
        self.disp_image(images.logo)
        self.erase_time = time.ticks_ms() + 2000
        self.font_big = writer.Writer(self.disp.framebuf, font_big)
        self.font_big.set_clip(False, True, False)
        self.font_med = writer.Writer(self.disp.framebuf, font_med)
        self.font_med.set_clip(False, True, True)
        self.font_small = writer.Writer(self.disp.framebuf, font_small)
        self.font_small.set_clip(False, True, True)
        self.slider_last_val = 0
        self.slider_last_time = 0
Exemple #8
0
    def __init__(self):
        # True =  SPI display, False = I2C display
        self.useSPI = True
        self.timer = 0
        self.vol = int(self.max_vol / 2) + 1
        seed(ticks_us())
        self.btnU = 1 << 1
        self.btnL = 1 << 2
        self.btnR = 1 << 3
        self.btnD = 1 << 4
        self.btnA = 1 << 5
        self.btnB = 1 << 6
        self.frameRate = 30
        self.screenW = 128
        self.screenH = 64
        self.Btns = 0
        self.lastBtns = 0
        self.adc = ADC(0)
        self.PinBuzzer = Pin(15, Pin.OUT)
        if self.useSPI:
            # configure oled display SPI SSD1306
            self.hspi = SPI(1, baudrate=8000000, polarity=0, phase=0)
            #DC, RES, CS
            self.display = ssd1306.SSD1306_SPI(128, 64, self.hspi, Pin(2),
                                               Pin(16), Pin(0))
            self.pinBtn = Pin(5, Pin.OUT)
            self.pinPaddle = Pin(4, Pin.OUT)
        else:  # I2C display

            # configure oled display I2C SSD1306
            self.i2c = I2C(-1, Pin(5), Pin(4))  # SCL, SDA
            self.display = ssd1306.SSD1306_I2C(128, 64, self.i2c)
            self.PinBtnL = Pin(12, Pin.IN, Pin.PULL_UP)
            self.PinBtnR = Pin(13, Pin.IN, Pin.PULL_UP)
            self.PinBtnU = Pin(14, Pin.IN, Pin.PULL_UP)
            self.PinBtnD = Pin(2, Pin.IN, Pin.PULL_UP)
            self.PinBtnA = Pin(0, Pin.IN, Pin.PULL_UP)
            self.PinBtnB = Pin(
                16, Pin.IN)  #GPIO 16 always pull down cannot pull up
def ap_WF_open(bit):
    """设置成"""
    import network
    import machine
    from machine import Pin, I2C, SPI, Timer
    import ssd1306
    spi = SPI(baudrate=10000000,
              polarity=1,
              phase=0,
              sck=Pin(14, Pin.OUT),
              mosi=Pin(13, Pin.OUT),
              miso=Pin(12))
    display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(5), Pin(4), Pin(16))
    if (bit == True):
        try:
            display.poweron()
            display.init_display()
            print('AP_set......')
            display.fill(0)
            display.text('AP_set......', 17, 31)
            display.show()

        except Exception as ex:
            #led_blue.value(0)
            print('Unexpected error: {0}'.format(ex))
            display.poweroff()

    ap = network.WLAN(network.AP_IF)  # create access-point interface
    if (bit == True):
        ap.active(True)  # activate the interface
        #设置成开放
        ap.config(
            essid='Sev-AP', authmode=network.AUTH_OPEN
        )  # set the ESSID of the access point,password='******'et the ESSID of the access point,password='******'
    else:
        ap.active(False)
Exemple #10
0
def lcd_thread():

    spi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
    display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(25), Pin(26), Pin(27))
    display.poweron()
    display.init_display()

    global ts
    global ts2
    global weather_1
    global tem_1
    global tem_2

    while True:
        #time.sleep(1)
        display.text(ts, 1, 1)
        display.text(ts2, 1, 8)
        display.draw_chinese_fast('密山', 5, 0)
        display.draw_chinese_fast('温度', 0, 1)
        display.draw_chinese_fast('天气', 0, 2)
        display.draw_chinese_fast(weather_1, 2, 2)
        t1 = '{} C'.format(tem_1)
        t2 = '{} C'.format(tem_2)
        print(t1, t2)
        display.text(t1, 40, 16)
        display.text(t2, 40, 24)

        display.show()

        time.sleep(0.1)

        global debug
        if debug:
            break
        display.fill(0)
    print('结束lcd_thread')
Exemple #11
0
    def init_oled(self):
        oled_width = 128
        oled_height = 64
        oled_dc = 2  # D4
        oled_rst = 5  # D1
        oled_cs = 0  # D3

        SPI_MODE = 1  # hardware SPI

        # MOSI = D7
        # CLK = D5

        spi = machine.SPI(SPI_MODE, baudrate=8000000, polarity=0, phase=0)
        oled = ssd1306.SSD1306_SPI(oled_width, oled_height, spi,
                                   machine.Pin(oled_dc), machine.Pin(oled_rst),
                                   machine.Pin(oled_cs))
        oled.contrast(128)
        oled.fill(0)
        oled.rect(0, 0, oled_width, oled_height, 1)
        oled.hline(0, 15, 128, 1)
        oled.hline(0, 16, 128, 1)
        oled.text(self.mqtt_sub.split('/')[1], 3, 4)
        oled.show()
        return oled
Exemple #12
0
import gc
import sys
gc.collect()
print (gc.mem_free())
import network
import utime
from utime import sleep_ms,ticks_ms, ticks_us, ticks_diff
from machine import Pin, SPI, PWM, ADC
from math import sqrt
import ssd1306
from random import getrandbits, seed

# configure oled display SPI SSD1306
hspi = SPI(1, baudrate=8000000, polarity=0, phase=0)
#DC, RES, CS
display = ssd1306.SSD1306_SPI(128, 64, hspi, Pin(2), Pin(16), Pin(0))
seed(ticks_us())

#---buttons

btnU = const (1 << 1)
btnL = const (1 << 2)
btnR = const (1 << 3)
btnD = const (1 << 4)
btnA = const (1 << 5)
btnB = const (1 << 6)

Btns = 0
lastBtns = 0

pinBtn = Pin(5, Pin.OUT)
Exemple #13
0
import machine
from utime import sleep
import ssd1306

spi_sck=machine.Pin(2)
spi_tx=machine.Pin(3)
spi=machine.SPI(0,baudrate=200000,sck=spi_sck, mosi=spi_tx)
CS = machine.Pin(1)
DC = machine.Pin(4)
RES = machine.Pin(5)
oled = ssd1306.SSD1306_SPI(128, 64, spi, DC, RES, CS)

counter = 0;
while True:
    oled.fill(0)
    oled.show()
    oled.text('CoderDojo Rocks!', 0, 0, 1)
    oled.text(str(counter), 0, 57, 1)
    oled.show()
    counter += 1;
    sleep(1)
    
# GND  -> GND

#DHT11 -> ESP32
# 2    -> D13

import ssd1306, time, dht, network, machine
from machine import Pin, SPI
from umqtt.simple import MQTTClient

print("Iniciando...")
sensor = dht.DHT11(Pin(13, Pin.IN, Pin.PULL_UP))
time.sleep(5.0)

spi = SPI(1, baudrate=8000000, sck=Pin(18), mosi=Pin(23), polarity=0, phase=0)
# dc, res, cs
oled = ssd1306.SSD1306_SPI(128, 64, spi, Pin(4), Pin(15), Pin(5))

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect('COLOCAR_AP', 'COLOCAR_SENHA')
while wifi.isconnected() == False:
    machine.idle()
print('Conexao realizada.')
print(wifi.ifconfig())

SERVIDOR = "mqtt.thingspeak.com"
CHANNEL_ID = "34342"
WRITE_API_KEY = "RPVYR5VW7A0U6X9T"
cliente = MQTTClient("umqtt_client", SERVIDOR)
topico = "channels/" + CHANNEL_ID + "/publish/" + WRITE_API_KEY
Exemple #15
0
import time
import ssd1306
import simple_menu
from settings import settings
from machine import SPI, I2C, Pin

rotary_enc = {"pb" : Pin(16, Pin.IN), "ra" : Pin(2, Pin.IN), "rb" : Pin(0, Pin.IN), "pin_irq" : Pin.IRQ_FALLING}
st = settings()
settings_obj = st.get_settings()

i2c_obj = I2C(-1, Pin(14), Pin(13))
addr = i2c_obj.scan()
if 0x3C in addr:
    display = ssd1306.SSD1306_I2C(width=128, height=64, i2c=i2c_obj, addr=0x3C, external_vcc=False)
else:
    display = ssd1306.SSD1306_SPI(width=128, height=64, spi=SPI(1), dc=Pin(4), res=Pin(5), cs=Pin(15), external_vcc=False)

menu_list = ['back', 'clock', 'alarm', 'wifi connect', 'wifi server', 'settings', 'reset', 'alphabet']
menu_actions = ['<BACK>', 'clock', 'alarm', 'wificonnect', 'wifiserver', 'settings', 'reset', 'simple_alphabet']
menu_obj = {"menu_list": menu_list, "menu_actions": menu_actions}

menu = simple_menu.simple_menu(display, rotary_enc, menu_obj, settings_obj)

while True:
    display.fill_rect(0,0,128,64,0)
    display.text("{: ^16s}".format("WELCOME"),0,0,1)
    display.text("{: ^16s}".format("PRESS START"),0,30,1)
    display.show()

    if not rotary_enc['pb'].value():
        menu.show()
# Just test the ping sensor on the OLED display
from machine import Pin, PWM
from utime import sleep, sleep_us, ticks_us
import ssd1306

spi_sck = machine.Pin(2)
spi_tx = machine.Pin(3)
spi = machine.SPI(0, baudrate=100000, sck=spi_sck, mosi=spi_tx)
CS = machine.Pin(1)
DC = machine.Pin(4)
RES = machine.Pin(5)

width = 128
height = 64
oled = ssd1306.SSD1306_SPI(width, height, spi, DC, RES, CS)
led_onboard = machine.Pin(25, machine.Pin.OUT)

TRIGGER_PIN = 16  # With USB on the top, this pin is the bottom left corner
ECHO_PIN = 17  # One up from bottom left corner
trigger = Pin(TRIGGER_PIN, Pin.OUT)  # send trigger out to sensor
echo = Pin(ECHO_PIN, Pin.IN)  # get the delay interval back


def ping():
    trigger.low()
    sleep_us(2)  # Wait 2 microseconds low
    trigger.high()
    sleep_us(5)  # Stay high for 5 miroseconds
    trigger.low()
    while echo.value() == 0:
        signaloff = ticks_us()
import ssd1306

WIDTH = 128
HEIGHT = 64

# default is data on GP7 and clock on GP6

CS = machine.Pin(1)
SCL = machine.Pin(2)
SDA = machine.Pin(3)
DC = machine.Pin(4)
RES = machine.Pin(5)
spi = machine.SPI(0, sck=SCL, mosi=SDA)
# print(spi)

oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES,
                           CS)  # Init oled display

# Raspberry Pi logo as 32x32 bytearray
# pi_logo = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00|?\x00\x01\x86@\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00~\xfc\x00\x00L'\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c \x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")

# 32X32 = 1024, 1024 / 8 = 128 bytes
# print(len(pi_logo))

# coderdojo_logo = bytearray(b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD\xFD\xFE\x0E\xE6\xF6\xF6\x06\xFC\xFD\xF9\xF1\xC3\x03\x07\x0F\x1F\x3F\x7F\xFF\xFF\xFF\x0F\xF9\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF9\xFB\xFB\xFC\x7F\x7F\x3F\x1F\x07\x00\x00\x00\x00\x00\x00\x00\x07\xFF\xF0\xDF\x7F\xFF\xFF\xFF\xFF\xFF\x1F\x07\x03\x01\x01\x00\x10\x10\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xE0\xFF\xFF\xFF\xFF\xFD\xFB\xF7\xEF\xEF\xDC\xF0\xA0\x80\x80\x00\x08\x08\x0F\x08\x8E\x80\x80\xC0\xC0\xC0\xE0\xF0\xF8\xFC\xFE\xFF\xFF\xFF")

my_bytearray = (
    b"\xFF\xFF\xFF\xBF\xDF\xEF\xF7\xFF\xFB\xFF\xFD\xFD\xFE\x0E\xE6\xF6\xF6\x06\xFC\xFD\xF9\xF1\xC3\x03\x07\x0F\x1F\x3F\x7F\xFF\xFF\xFF\x0F\xF9\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC\xF9\xFB\xFB\xFC\x7F\x7F\x3F\x1F\x07\x00\x00\x00\x00\x00\x00\x00\x07\xFF\xF0\xDF\x7F\xFF\xFF\xFF\xFF\xFF\x1F\x07\x03\x01\x01\x00\x10\x10\xF0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\xE0\xFF\xFF\xFF\xFF\xFD\xFB\xF7\xEF\xEF\xDC\xF0\xA0\x80\x80\x00\x08\x08\x0F\x08\x8E\x80\x80\xC0\xC0\xC0\xE0\xF0\xF8\xFC\xFE\xFF\xFF\xFF"
)

coderdojo_logo = bytearray(my_bytearray)
fb_len = len(coderdojo_logo)
Exemple #18
0
import framebuf

def load_image(name):
    "takes a filename, returns a framebuffer"
    f = open(name, 'rb')
    if b'P4\n' != f.readline():                         # Magic number
        raise ImportError("Invalid file")
    f.readline()                                       # Creator comment
    width, height = list(int(j) for j in f.readline()[:-1].decode().split(" ")) # Dimensions
    data = bytearray(f.read())
    return framebuf.FrameBuffer(data, width, height, framebuf.MONO_HLSB)


d = ssd1306.SSD1306_SPI(128, 64, SPI(1),
        dc=Pin("B1", Pin.OUT),
        res=Pin("C9", Pin.OUT),
        cs=Pin("A8", Pin.OUT),
        external_vcc=False, mirror_v=True, mirror_h=True)



while 1:
    d.text("Hello world!", 0, 0, 1)
    d.framebuf.line(127, 0, 0, 63, 1)
    d.show()
    time.sleep(1)

    d.framebuf.blit(load_image("test.pbm"), 0, 0)
    d.show()
    time.sleep(1)
Exemple #19
0
co2_end2 = 20

light_start1 = 6
light_end1 = 9
light_start2 = 15
light_end2 = 22

mqtt_server = 'tailor.cloudmqtt.com'
res = machine.Pin(16)
dc = machine.Pin(17)
cs = machine.Pin(5)
spi1 = machine.SPI(2,
                   baudrate=14500000,
                   sck=machine.Pin(18),
                   mosi=machine.Pin(23))
oled = ssd1306.SSD1306_SPI(128, 64, spi1, dc, res, cs)
utc_shift = 3  #задать дельту временной зоны
startTime = time.ticks_ms()
wifissid2 = 'Tensor'
wifipassword2 = '87654321'
wifissid1 = 'Tomato24'
wifipassword1 = '77777777'
relay1 = machine.Pin(25)
relay2 = machine.Pin(26)
p1 = machine.Pin(27)
relay1.init(relay1.OUT)
relay2.init(relay2.OUT)
p1.init(p1.OUT)
rtc = machine.RTC()
tcounter = 0
main_timer1 = machine.Timer(2)
Exemple #20
0
import ssd1306
import urequests
import ujson
import network
import machine
import dht

#i2c = I2C(scl=Pin(14), sda=Pin(2), freq=100000)
#display = ssd1306.SSD1306_I2C(128,64, i2c)
spi = SPI(baudrate=10000000,
          polarity=1,
          phase=0,
          sck=Pin(14, Pin.OUT),
          mosi=Pin(13, Pin.OUT),
          miso=Pin(12))
display = ssd1306.SSD1306_SPI(128, 64, spi, Pin(5), Pin(4), Pin(16))

try:
    display.poweron()
    display.init_display()
    display.text("hi~", 10, 30)
    # Write display buffer
    display.show()
except Exception as ex:
    display.poweroff()


def connect_wifi(essid, password):
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
Exemple #21
0
from machine import Pin, SPI
import ssd1306

spi = SPI(-1, baudrate=8000000, phase=0, polarity=0)

oled = ssd1306.SSD1306_SPI(128, 64, spi, res=Pin(4), dc=Pin(5), cs=Pin(15))
oled.fill(0)
oled.show()
Exemple #22
0
pwr_on = Pin(2, Pin.OUT, value=0)
oled_pwr = Pin(33, Pin.OUT, value=0)
touch = Pin(TOUCH, Pin.IN)
touch_pwr = Pin(TOUCH_PWR, Pin.OUT, value=0)

spi = SoftSPI(baudrate=27000000, sck=Pin(18), mosi=Pin(23), miso=Pin(32))
dc = Pin(19)
rst = Pin(4)
cs = Pin(5)

pwr_on.value(1)
touch_pwr.value(0)

oled_pwr.value(1)
display = ssd1306.SSD1306_SPI(128, 64, spi, dc, rst, cs)
display.poweron()
display.text('Hello', 0, 0, 1)
display.show()

while (1):
    SoftSPI.deinit(spi)
    touch_pwr = Pin(TOUCH_PWR, Pin.OUT, value=1)
    time.sleep_ms(20)
    touched = (touch.value() == 1)
    spi = SoftSPI(baudrate=27000000, sck=Pin(18), mosi=Pin(23), miso=Pin(32))
    if (touched):
        display.fill_rect(0, 0, 100, 16, 0)
        display.text('Hello Tammy', 0, 0, 1)
    else:
        display.fill_rect(0, 0, 100, 16, 0)
# ESP32 Pin assignment
#i2c = I2C(-1, scl=Pin(22), sda=Pin(21))

# ESP8266 Pin assignment
#i2c = I2C(-1, scl=Pin(5), sda=Pin(4))

# ESP32 SPI initalization
hspi = SPI(2,
           baudrate=8000000,
           polarity=0,
           phase=0,
           sck=Pin(18),
           mosi=Pin(23),
           miso=Pin(19))

#oled_width = 128
#oled_height = 64
oled = ssd1306.SSD1306_SPI(128, 64, hspi, dc=Pin(17), res=Pin(16), cs=Pin(5))

# class SSD1306_SPI(SSD1306):
#     def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):

oled.text('Hello, World 1!', 0, 0)
oled.text('Hello, World 2!', 0, 10)
oled.text('Hello, World 3!', 0, 20)
oled.text('Hello, World 4!', 0, 30)
oled.text('Hello, World 5!', 0, 40)

oled.show()
Exemple #24
0
import machine, dht, ssd1306, time, esp
import pbm

esp.osdebug(None)
GPIO2 = 2
sensor = dht.DHT22(machine.Pin(GPIO2))
spi = machine.SPI(1, baudrate=80000000, polarity=0, phase=0)
oled = ssd1306.SSD1306_SPI(128, 64, spi, machine.Pin(5), machine.Pin(0),
                           machine.Pin(15))
#DC, reset, and CS
cat = pbm.PBM_P1("cat.pbm")

OLED_WIDTH, OLED_HEIGTH = 128, 64
machine.freq(160000000)

##MAIN LOOP
while True:

    oled.fill(0)

    for row in range(cat.height):
        for col in range(cat.width):
            oled.pixel(col, row, cat.get(row, col))
    oled.show()
Exemple #25
0
                oled.pixel(j, i, 1)
    else:
        oled.text('Print', 0, second_line)
        oled.text('finished!', 0, third_line)

    oled.show()

# Initialize the display
if config.display_protocol == 'i2c':
    i2c = machine.I2C(-1, machine.Pin(5), machine.Pin(4))
    oled = ssd1306.SSD1306_I2C(
        config.display_width, config.display_height, i2c)

elif config.display_protocol == 'spi':
    spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0)
    oled = ssd1306.SSD1306_SPI(config.display_width, config.display_height, spi, machine.Pin(
        config.dc), machine.Pin(config.reset), machine.Pin(config.cs))

# Configuring the output according to the resolution
if config.display_width == 64 and config.display_height == 48:
    first_line = 8
    second_line = 20
    third_line = 32
    percentage_pos = None
    bar_margin_top = 0
    bar_length = 64
    bar_height = 3
elif config.display_width == 128 and config.display_height == 64:
    first_line = 16
    second_line = 32
    third_line = 48
    percentage_pos = [112, 3]
Exemple #26
0
def do_menu():
    global module_name

    pinBtn = Pin(5, Pin.OUT)
    pinPaddle = Pin(4, Pin.OUT)

    from machine import SPI
    import ssd1306

    # configure oled display I2C SSD1306
    hspi = SPI(1, baudrate=8000000, polarity=0, phase=0)
    #DC, RES, CS
    display = ssd1306.SSD1306_SPI(128, 64, hspi, Pin(2), Pin(16), Pin(0))

    SKIP_NAMES = ("boot", "main", "menus")

    files = [item[0] for item in os.ilistdir(".") if item[1] == 0x8000]

    module_names = [
        filename.rsplit(".", 1)[0] for filename in files
        if (filename.endswith(".py") or filename.endswith(".mpy"))
        and not filename.startswith("_")
    ]
    module_names = [
        module_name for module_name in module_names
        if not module_name in SKIP_NAMES
    ]
    module_names.sort()
    tot_file = len(module_names)
    tot_rows = const(5)
    screen_pos = 0
    file_pos = 0

    launched = False
    while not launched:
        gc.collect()
        display.fill(0)
        display.text(sys.platform + " " + str(gc.mem_free()), 5, 0, 1)
        i = 0
        for j in range(file_pos, min(file_pos + tot_rows, tot_file)):
            current_row = 12 + 10 * i
            if i == screen_pos:
                display.fill_rect(5, current_row, 118, 10, 1)
                display.text(str(j) + " " + module_names[j], 5, current_row, 0)
            else:
                display.fill_rect(5, current_row, 118, 10, 0)
                display.text(str(j) + " " + module_names[j], 5, current_row, 1)
            i += 1
        display.show()
        getBtn()

        if pressed(btnU, True):
            if screen_pos > 0:
                screen_pos -= 1
            else:
                if file_pos > 0:
                    file_pos = max(0, file_pos - tot_rows)
                    screen_pos = tot_rows - 1

        if pressed(btnD, True):
            if screen_pos < min(tot_file - file_pos - 1, tot_rows - 1):
                screen_pos = min(tot_file - 1, screen_pos + 1)
            else:
                if file_pos + tot_rows < tot_file:
                    file_pos = min(tot_file, file_pos + tot_rows)
                    screen_pos = 0

        if pressed(btnR, True):
            display.fill(0)
            display.text("launching ", 5, 20, 1)
            display.text(module_names[file_pos + screen_pos], 5, 40, 1)
            display.show()
            sleep_ms(1000)
            module_name = module_names[file_pos + screen_pos]
            return True

        if pressed(btnL, True):
            launched = True
            display.fill(0)
            display.text("exited ", 5, 24, 1)
            display.show()
            return False
        display.show()
import machine
import ssd1306
from time import sleep

WIDTH = 128
HEIGHT = 64
spi_sck=machine.Pin(2)
spi_tx=machine.Pin(3)
spi=machine.SPI(0,baudrate=100000,sck=spi_sck, mosi=spi_tx)
CS = machine.Pin(1)
DC = machine.Pin(4)
RES = machine.Pin(5)
oled = ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, DC, RES, CS)

def eval_screen(function, x, y):
    if eval(function):
        oled.pixel(x, y, 0)
    else:
        oled.pixel(x, y, 1)

oled.fill(0)

for x in range(WIDTH):
    for y in range(HEIGHT):
        eval_screen('pow(x, y) % 2', x, y)
oled.show()
 def __init__(self, dc, res, cs, width, height, border=0):
     self.w = width
     self.h = height
     self.b = border
     spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0)
     self._screen = ssd1306.SSD1306_SPI(width, height, spi, dc, res, cs)
Exemple #29
0
sta_if.active(True)
sta_if.connect('EEERover', 'exhibition')
while (not sta_if.isconnected()):
    pass
print('connected')

#Connect to MQTT Broker
from umqtt.simple import MQTTClient
client = MQTTClient('machine.unique_id()', '192.168.0.10')
client.connect()

#Set up I2C and OLED Pins
from machine import Pin, I2C
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
spi = machine.SPI(1, baudrate=8000000, polarity=0, phase=0)
oled = ssd1306.SSD1306_SPI(128, 32, spi, machine.Pin(15), machine.Pin(0),
                           machine.Pin(16))

#Show OLED Menu
Screen.Screen.menu()
time.sleep(1)

#Set up Buttons
button1 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP)
button2 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)
button3 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP)

#Wait for selection by user input on buttons
#To add more medicines or organs etc, just update Medicines class file
#You can also change code below to allow scrollable screen for more option selection
fini = 0
while (fini == 0):
Exemple #30
0
import urequests

from machine import Pin, SPI
import ssd1306
from time import sleep

spi = SPI(2,
          baudrate=80000000,
          polarity=0,
          phase=0,
          bits=8,
          firstbit=0,
          sck=Pin(18),
          mosi=Pin(23),
          miso=Pin(19))
lcd = ssd1306.SSD1306_SPI(128, 64, spi, Pin(4), Pin(2), Pin(5))

sta = network.WLAN(network.STA_IF)
sta.active(True)
sta.connect("SSID", "PASSWORD")
print(sta.ifconfig())
sleep(2)

lcd.fill(0)
lcd.text("Total Kasus", 0, 0)
lcd.text("Corona Indonesia", 0, 10)
lcd.text("Untuk Hari ini", 0, 20)
lcd.show()
sleep(1)
lcd.fill(0)
lcd.text("Mengambil Data", 0, 0)