Exemplo n.º 1
0
    def __init__(self, i2c):
        self.i2c = i2c

        self._mcp = MCPEdge(i2c, address=0x21, falling_edge=True)
        # Configure PinOut
        #   GPA0..GPA3 are input
        for pin in range(0, 4):
            self._mcp.setup(pin, Pin.IN)
            # GPA0, GPA1, GPA3 needs for PullUp because the 910K external Pull up is too weak
            # GPA2 is an INT active @ low level --> Need a pull-up!
            self._mcp.pullup(pin, True)
        #  GPA4..GPA7 are output
        for pin in range(4, 8):
            self._mcp.setup(pin, Pin.OUT)
        #  GPB0..GPB7 are input (for the buttons)
        for pin in range(8, 16):
            self._mcp.setup(pin, Pin.IN)
        self._mcp.edge_begin([SW1, SW3, SW4, UP, DOWN, LEFT, RIGHT,
                              CLICK])  # Initialize Edge counter
        self.oled_reset()

        self.oled = SSD1306_I2C(width=128,
                                height=64,
                                i2c=i2c,
                                addr=0x3c,
                                external_vcc=True)
        self.oled.init_display()
Exemplo n.º 2
0
def main():
    sleep(0.5)
    i2c=I2C(1,sda=Pin(2), scl=Pin(3), freq=400000)
    global oled
    oled = SSD1306_I2C(128, 64, i2c)

    oled.fill(0)
#    go_up(1)
#     go_down(3)
#     left_to_right(1)
#     right_to_left(3)

    nuRightTest(1)

    x=int(128/3/2)
    y=int(64/3/2)
    global snake
#     snake = [ (x,y,rights[0]), (x-1,y,rights[1]), (x-2,y,rights[2]), (x-3,y,rights[3])]
#     
#     for r in range(2):
#         for sn in snake:
#             drawe(sn[0],sn[1],sn[2])
#             oled.show()
#         sleep(1)
#         move_snake(1,0)
#         oled.show()

    sleep(t)
Exemplo n.º 3
0
def start():
    print("\n")
    i2c = I2C(-1, scl=Pin(5), sda=Pin(4))
    oled = SSD1306_I2C(WIDTH, HEIGHT, i2c)

    splash_screen(oled)
    wifi = wifi_connect(wc.SSID, wc.PASSWORD)

    aqi = AQI()
    sensor = Sensor(i2c)
    mqtt = MQTTData(wc.IO_URL, wc.IO_USERNAME, wc.IO_KEY, wc.SNAME)

    display = Display(oled, aqi, sensor)
    gc.collect()

    loop = asyncio.get_event_loop()
    loop.create_task(mqtt.run(sensor))
    loop.create_task(aqi.run())
    loop.create_task(display.run())
    loop.create_task(heartbeat())

    gc.collect()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        oled.fill(0)
        oled.text('Sensor', 44, 7)
        oled.text('Shutdown', 35, 21)
        oled.show()
    except OSError as exc:
        print(exc)
Exemplo n.º 4
0
def start():
    from ssd1306 import SSD1306_I2C
    import bme280
    from machine import Pin, I2C

    i2c = I2C(-1, scl=Pin(SCL), sda=Pin(SDA))
    ids = i2c.scan()
    print('found {} on i2c bus (scl={}, sda={})'.format(ids, SCL, SDA))

    if not 0x76 in ids:
        print('could not find bme sensor on i2c bus (scl={}, sda={}) .. exit'.
              format(SCL, SDA))
        return

    if not 0x3c in ids:
        print('no ssd1306 display found on i2c bus (scl={}, sda={})'.format(
            SCL, SDA))

    oled = SSD1306_I2C(OLED_W, OLED_H, i2c) if 0x3c in ids else None

    modes = [
        bme280.BME280_OSAMPLE_1,
        bme280.BME280_OSAMPLE_2,
        bme280.BME280_OSAMPLE_4,
        bme280.BME280_OSAMPLE_8,  # default
        bme280.BME280_OSAMPLE_16
    ]
    bme = bme280.BME280(mode=modes[3], i2c=i2c)

    run(oled, bme)
Exemplo n.º 5
0
 def __init__(self):
     self.i2c = I2C(scl=Pin('SCL'), sda=Pin('SDA'))
     self.screen = SSD1306_I2C(128, 64, self.i2c)
     self.wrt = Writer(self.screen, freesans20, False),\
                Writer(self.screen, font10, False)
     self._msg_ = 'Iniciando'
     self._data_ = None
Exemplo n.º 6
0
    def ip_display(self):
        """Show connection status on the SSD1306 display."""
        if not self.cfg.get("use_screen"):
            return
        i2c = I2C(
                -1,
                scl=Pin(self.cfg.get("i2c_screen_scl")),
                sda=Pin(self.cfg.get("i2c_screen_sda"))
        )
        screen = SSD1306_I2C(128, 32, i2c)
        screen.fill(0)
        if self.mode == STA_MODE:
            ip = self.sta_if.ifconfig()[0]
            screen.text('Normal Mode', 0, 0)
            screen.text('IP Address:', 0, 8)
            screen.text(ip, 0, 16)
        if self.mode == AP_MODE:
            ip = self.ap.ifconfig()[0]
            screen.text('Access Point:', 0, 0)
            screen.text(Connection.AP_SSID, 0, 8)
            screen.text('IP Address:', 0, 16)
            screen.text(ip, 0, 24)

        screen.show()
        time.sleep(5)
Exemplo n.º 7
0
def main():
    from machine import Pin, I2C
    from ssd1306 import SSD1306_I2C
    from utime import sleep

    i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
    oled = SSD1306_I2C(128, 64, i2c)

    #     points = [(10,10),(11,10),\
    #               (12,11),(12,12),\
    #               (13,13),(14,13),\
    #               (14,12),(14,11)]
    points = [\
        (9,11),(10,11),(11,11),
        (12,12),\
        (13,13),(13,14),(13,15),\
        (14,16),\
        (15,17),(16,17),(17,17),\
        (18,16),\
        (19,15),(19,14),(19,13),\
        (20,12)]

    for snake in range(5):
        for p in points:
            oled.pixel(snake * (20 - 9) + p[0], p[1], 1)
            oled.show()
        sleep(.01)

    for snake in range(5):
        for p in points:
            oled.pixel(snake * (20 - 9) + p[0], p[1], 0)
            oled.show()
        sleep(.005)
Exemplo n.º 8
0
def setup(use_spi=False, soft=True):
    if use_spi:
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # X1    DC
        # X2    CS
        # X3    Rst
        # X6    CLK
        # X8    DATA
        pdc = machine.Pin('X1', machine.Pin.OUT_PP)
        pcs = machine.Pin('X2', machine.Pin.OUT_PP)
        prst = machine.Pin('X3', machine.Pin.OUT_PP)
        if soft:
            spi = machine.SPI(sck=machine.Pin('X6'), mosi=machine.Pin('X8'), miso=machine.Pin('X7'))
        else:
            spi = machine.SPI(1)
        ssd = SSD1306_SPI(WIDTH, HEIGHT, spi, pdc, prst, pcs)
    else:  # I2C
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # Y9    CLK
        # Y10   DATA
        if soft:
            pscl = machine.Pin('Y9', machine.Pin.OPEN_DRAIN)
            psda = machine.Pin('Y10', machine.Pin.OPEN_DRAIN)
            i2c = machine.I2C(scl=pscl, sda=psda)
        else:
            i2c = machine.I2C(2)
        ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
    return ssd
Exemplo n.º 9
0
def lcd_init():
    global oled
    from machine import Pin, I2C
    from ssd1306 import SSD1306_I2C

    i2c = I2C(-1, sda=Pin(4), scl=Pin(5), freq=400000)
    oled = SSD1306_I2C(128, 64, i2c)
Exemplo n.º 10
0
def main():
    sleep(1)
    i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
    global oled
    oled = SSD1306_I2C(128, 64, i2c)

    setupUI()

    #UpDownLeftRightTests()

    oled.fill(0)
    x = 0
    y = int(64 / 3 / scale / 2)
    initSnakeLR(x, y)
    global dx, dy
    dx, dy = 1, 0
    #drawSnake()

    # horzSeq = "d--b--a-=c-=d--" #Left to Right (positive direction curve down first)
    # vertSeq = "b=-c=-d--a--b=-" #Bottom to top (positive direction curve right first)

    #     drawSeg(5,3,"b--")
    #     #drawSeg(6,3,"a-=") # continue right
    #     #drawSeg(5,2,"b=-")
    #     #drawSeg(5,2,"c=-")
    #     #drawSeg(5,2,"d--")
    #     drawSeg(5,2,"a--")
    #     oled.show()

    while True:
        CheckButtons()
        moveSnake(dx, dy)
        sleep(spd)
        moveSnake(dx, dy)
        sleep(spd)
Exemplo n.º 11
0
 def bootstrap(self, timeout):
     from wifi import WiFi
     network = WiFi()
     from ssd1306 import SSD1306_I2C
     from machine import Pin, I2C
     bus = I2C(-1, Pin(4), Pin(5))
     display = SSD1306_I2C(128, 32, bus)
     from views import Views
     with network.Context(timeout) as c:
         while 1:
             ttl = self.ttl(timeout)
             if not ttl:
                 self._core.show(display, None)
                 self.data_changed = False
                 break
             self._core.show(
                 display,
                 Views['network']['wait'](c.net.token, timeout, ttl)
             )
             if c.net.connected:
                 self._core.show(
                     display,
                     Views['network']['connected']()
                 )
                 self.data_changed = self._core.setup_mode()
                 break
             self._sleep(0.5)
     del network, WiFi, display, SSD1306_I2C, Views, Pin, I2C, bus
     collect()
     return self.data_changed
def main():
    width  = 128 # SSD1306 horizontal resolution
    height = 32   # SSD1306 vertical resolution

    i2c_dev = I2C(0,scl=Pin(1),sda=Pin(0),freq=200000)  # start I2C on I2C1 (GPIO 26/27)
    i2c_addr = [hex(ii) for ii in i2c_dev.scan()] # get I2C address in hex format

    sensor = am2320.AM2320(i2c_dev)

    oled = SSD1306_I2C(width, height, i2c_dev) # oled controller

    tempbuffer = TemperatureBuffer (width)

    text_x = 0 # start point for text in x-dir
    text_y = 0 # start point for text in y-dir
    text_y_space = 13 # space between text in y-dir

    max_temp = 30
    min_temp = 0

    graph_start_y = 22

    # This value used by temp_to_yoffset - put outside of function so only need to calculate once
    # Scale is temperature range divided by number pixels
    scale =  (height -1 - graph_start_y) / (max_temp - min_temp)

    while (1):
        sensor.measure()
        temperature = sensor.temperature()
        humidity = sensor.humidity()
        print("Temp: {}C RH {}%".format(temperature, humidity))
        # Check that the value is in a valid range (skip errornous readings)
        if (temperature > max_temp or humidity > 100) :
            print (" skipping erroroneous value")
            continue
        tempbuffer.addValue(temperature)

        oled.fill(0) # clear the OLED
        
        # Create text display
        text_1 = "Temp: {:.1f}C".format(sensor.temperature())
        text_2 = "RH: {:.1f}%".format(sensor.humidity())
        oled.text(text_1,text_x,text_y) # Show temperature
        oled.text(text_2,text_x,text_y+text_y_space) # Show Humidity

        # Create line graph across bottom of screen
        # Most recent value at right of screen (could reverse if preferred)
        x_pos = 0
        values = tempbuffer.getValues()
        for temp_value in values:
            # Convert temperature value into y position (high value = graph_start_y, low value = height of screen)
            y_pos = graph_start_y + int((max_temp - temp_value) * scale)
            # Draw a pixel for each value
            oled.pixel(x_pos, y_pos, 1)
            x_pos += 1

        oled.show() # output to OLED display
        
        utime.sleep(1)
Exemplo n.º 13
0
 def turn_off(self):
     from ssd1306 import SSD1306_I2C
     from machine import I2C, Pin
     display = SSD1306_I2C(128, 32, I2C(-1, Pin(4), Pin(5)))
     display.poweroff()
     from machine import deepsleep
     if DEEPSLEEP:
         deepsleep()
Exemplo n.º 14
0
    def __init__(self):
        self.pscl = Pin('S5', Pin.OUT_PP)
        self.psda = Pin('S3', Pin.OUT_PP)
        self.i2c = I2C(scl=self.pscl, sda=self.psda)
        self.lcd = SSD1306_I2C(128, 32, self.i2c)

        self.lcd.rect(0, 0, 128, 32, 1)  # Cadre blanc
        self.lcd.show()  # Afficher!
Exemplo n.º 15
0
def oled_init():
    SDA1 = Pin(26)
    SCL1 = Pin(27)
    WIDTH = 128  # oled display width
    HEIGHT = 64  # oled display height
    i2c1 = I2C(1, sda=SDA1, scl=SCL1)
    oled = SSD1306_I2C(WIDTH, HEIGHT, i2c1)
    print("SSD1306_I2C: {}".format(SSD1306_I2C))
    return oled
Exemplo n.º 16
0
def show_led(url, query):
    from machine import I2C
    i2c = machine.I2C(-1, sda=machine.Pin(9), scl=machine.Pin(10), freq=400000)
    from ssd1306 import SSD1306_I2C
    oled = SSD1306_I2C(128, 64, i2c)
    oled.text("Hi", 0, 0)
    oled.text(url, 0, 15)
    oled.text(query, 0, 30)
    oled.show()
Exemplo n.º 17
0
def main_loop():
      
    gpio_scl=Pin(14)
    gpio_sda=Pin(12)
    i2c=I2C(scl=gpio_scl,sda=gpio_sda,freq=400000)
    print(i2c.scan())
    i2c.writeto_mem(87,1,b'\xf0')
    i2c.writeto_mem(87,3,b'\x02')
    i2c.writeto_mem(87,33,b'\x01')
    i2c.writeto_mem(87,10,b'\x43')
    i2c.writeto_mem(87,12,b'\xff')
    i2c.writeto_mem(87,13,b'\xff')
    i2c.writeto_mem(87,9,b'\x0b')
    i2c.writeto_mem(87,8,b'\x0f')  
    i2c2 = I2C(scl=Pin(5), sda=Pin(4))  
    oled = SSD1306_I2C(128, 64, i2c2)
    oled.fill(1)
    oled.show()
    oled.fill(0)
    oled.show() 
    while True:
      oo2=[]
      IRdata1=[]
      Rdata1=[]
      l=0
      while(l<1):
        if(i2c.readfrom_mem(87,4,1)==b'\x1f'):
          oo2=i2c.readfrom_mem(87,7,192)
          for i in range(1,33):        
            IRdata1.append(oo2[6*(i-1)+0]*65536+oo2[6*(i-1)+1]*256+oo2[6*(i-1)+2])
            Rdata1.append(oo2[6*(i-1)+3]*65536+oo2[6*(i-1)+4]*256+oo2[6*(i-1)+5])  
          l=l+1
          oled.text('SPO2&HR detector', 0, 0)
          oled.text('Place ur finger', 4, 20)
          oled.show()
      if Rdata1[10]>=3500: 
        oled.fill(0)
        oled.show()
        oled.text('Hold on for 8s', 4, 20)
        oled.show()
        time.sleep(1)
        oled.fill(0)
        oled.show()
        HR,PO=get(oled)
        if HR>20:
          oled.fill(0)
          oled.show()
          oled.text('Uploading data', 4, 20)
          oled.show()
          upload(HR,PO)
          oled.fill(0)
          oled.show()
          oled.text('successful!', 4, 20)
          oled.show()
          time.sleep(1)
          oled.fill(0)
          oled.show()
Exemplo n.º 18
0
def main():
    from machine import Pin, I2C
    from ssd1306 import SSD1306_I2C

    i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
    oled = SSD1306_I2C(128, 64, i2c)

    oled.text("Hello Tom's", 0, 0)
    oled.show()
Exemplo n.º 19
0
def main():
    load_config()
    print('Config =', config)
    tc_type = config['tc_type']
    led = Pin(2, Pin.OUT)
    led.value(1)

    i2c = I2C(sda=Pin(4), scl=Pin(5), freq=350000)
    disp = SSD1306_I2C(64, 48, i2c)
    disp.text('Type ' + tc_type, 0, 0)
    disp.show()

    spi = SPI(1, baudrate=1000000, polarity=1)
    cs = Pin(16, Pin.OUT)
    max31856 = Max31856(spi, cs, tc_type)

    wlan = network.WLAN(network.STA_IF)
    mqtt = None

    if wlan.isconnected():
        hostname = wlan.config('dhcp_hostname')
        root = b"emon/thermocouple_" + hostname + '/'
        mqtt = MQTTClient(hostname, **config['mqtt'])
        mqtt.connect()
        mqtt.set_last_will(root + 'alive', '0')
        mqtt.publish(root + 'alive', '1')
        mqtt.publish(root + 'status',
                     'Thermocouple type %s' % max31856.tc_type)

    while True:
        time.sleep(config['interval_seconds'])
        led.value(0)
        tc = max31856.temperature(read_chip=True)
        cj = max31856.cold_junction()
        f, fs = max31856.faults()
        tcs = '{:7.2f}'.format(tc)
        cjs = '{:7.2f}'.format(cj)
        print('Temperatures:', tcs, cjs)
        if mqtt:
            if f:
                print(fs)
                mqtt.publish(root + 'fault', fs)
            else:
                mqtt.publish(root + 'tc', tcs)
                mqtt.publish(root + 'cj', cjs)

        disp.framebuf.fill(0)
        disp.text('Type ' + tc_type, 0, 0)
        if f:
            disp.text('Fault', 0, 9)
            disp.text(fs, 0, 18)
        else:
            disp.text(tcs, 0, 9)
            disp.text(cjs, 0, 18)
        disp.show()
        led.value(1)
Exemplo n.º 20
0
 def __init__(self, config):
     self.enabled = config['enabled']
     if self.enabled:
         pins = config['pins']
         size = config['size']
         i2c = I2C(-1, Pin(pins[0]), Pin(pins[1]))
         self.display = SSD1306_I2C(size[0], size[1], i2c)
         self.counter = 0
         self.rows = size[1] // 8
         self.cols = size[0] // 8
Exemplo n.º 21
0
def __init():
    global __OLED
    if __OLED is None:
        from machine import Pin, I2C
        from ssd1306 import SSD1306_I2C
        from LogicalPins import get_pin_on_platform_by_key
        i2c = I2C(-1, Pin(get_pin_on_platform_by_key('i2c_scl')),
                  Pin(get_pin_on_platform_by_key('i2c_sda')))
        __OLED = SSD1306_I2C(128, 64, i2c)
    return __OLED
Exemplo n.º 22
0
def main():
    i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
    global oled
    oled = SSD1306_I2C(128, 64, i2c)

    oled.fill(0)
    go_up(1)
    go_down(3)
    left_to_right(1)
    right_to_left(3)
Exemplo n.º 23
0
    def __init__(self):
        self.EN_DYN = Pin(16, Pin.OUT)
        self.EN_DYN.on()
        self.SPEED_PULSE = Pin(15, Pin.IN, pull=None)

        self.i2c = SoftI2C(scl=Pin(14), sda=Pin(12))
        self.oled = SSD1306_I2C(128, 64, self.i2c)

        self.ina = Ina219(self.i2c, r_shunt=50)
        self.ina.pga = 0  # maximum sensitivity
        self.ina.avg = 7  # maximum averaging

        self.btns = Btns([0, 2, 4, 32], 0.05)
Exemplo n.º 24
0
    def __init__(self,
                 width = 128, height = 64,
                 scl_pin_id = 15, sda_pin_id = 4,
                 freq = 400000):

        self.width = width
        self.height = height
        self.poweron()
        self.i2c = I2C(scl = Pin(scl_pin_id, Pin.OUT),
                               sda = Pin(sda_pin_id),
                               freq = freq)
        self.display = SSD1306_I2C(width, height, self.i2c)
        self.show = self.display.show
Exemplo n.º 25
0
    def __init__(self):
        self.width = w = 64
        self.height = h = 48
        self.line_height = lh = h // 4

        try:
            i2c = I2C(-1, Pin(pinmap.SCL), Pin(pinmap.SDA))
            self.display = display = SSD1306_I2C(w, h, i2c)
            display.poweron()
            display.contrast(255)
            display.fill(0)
            display.show()
        except:
            self.display = None
Exemplo n.º 26
0
 def show_current_otp(self):
     start = self._get_time()
     from ssd1306 import SSD1306_I2C
     from machine import Pin, I2C
     bus = I2C(-1, Pin(4), Pin(5))
     display = SSD1306_I2C(128, 32, bus)
     from views import Views
     while self._get_time() - start <= OTP_SESSION:
         self._core.show(display, Views['otp'](
             self._core.get_otp_tuple()
         ))
         self._sleep(0.5)
     del display, SSD1306_I2C, Views, Pin, I2C, bus
     collect()
Exemplo n.º 27
0
def setup_oled():
    global oled
    # create reset pulse
    reset_pin_oled.off()
    time.sleep_ms(200)
    reset_pin_oled.on()

    i2c_oled = I2C(scl=scl_pin_oled, sda=sda_pin_oled, freq=400000)

    oled = SSD1306_I2C(128, 64, i2c_oled)
    if DEBUG:
        idev_oled = i2c_oled.scan()
        print("idev_oled= ", end='')
        print(idev_oled)
    return oled
Exemplo n.º 28
0
def oled_init():
    global oled

    i2cObj = I2C()
    i2cObj.open("ssd1306")
    print("ssd1306 inited!")

    oled = SSD1306_I2C(128, 64, i2cObj)
    oled.fill(0)  #清屏背景黑色
    oled.text('2022-01-03', 30, 5)
    oled.text('12:00:00', 30, 22)
    oled.text(str('----------------------'), 3, 32)
    oled.text('connecting', 30, 40)

    oled.show()
Exemplo n.º 29
0
    async def _display_coro(self):
        display = SSD1306_I2C(128, 32, i2c)

        while True:
            display.poweron()
            display.fill(0)
            display.text(
                "COLD: {:.3f}".format(self.cold_counter.value() / 1000), 16, 4)
            display.text(
                "HOT:  {:.3f}".format(self.hot_counter.value() / 1000), 16, 20)
            display.show()
            await asyncio.sleep(3)
            display.poweroff()

            while self.button():
                await asyncio.sleep_ms(20)
Exemplo n.º 30
0
    def __init__(self, i2c=None, addr=60, row_height=10, width=128, height=64):
        if i2c is None:
            i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000)
        
        # All characters have dimensions of 8x8 pixels and there is currently no way to change the font.
        self.width = width
        self.height = height
        self.row_height = row_height
        self.row_max = height - row_height 
        self.row_idx = 0
        self.range = range(self.row_height)
        # self.scroll_step = - height % row_height

        self.oled = SSD1306_I2C(width, height, i2c, addr=addr)
        self.oled.fill(0)
        self.oled.show()