Пример #1
0
 def __init__(self):
     i2c.init()
     sleep(1)
     self._sbank(0)
     t = self._rreg(0)
     if t == 0x20: self._init_reg()
     self._sbank(0)
def init():
    i2c.init()
    while not _ADDR in i2c.scan():
        print("Crickit not found!")
        time.sleep(1)
    reg_buf[0] = 0x7F
    reg_buf[1] = 0xFF
    i2c.write(_ADDR, reg_buf)
Пример #3
0
    def _init(self):
        i2c.init()
        temp = 0
        sleep(1)

        # Intentionally duplicated
        self._select_bank(0)

        temp = self._read_reg(0)
        if temp == 0x20:
            print("Writing registers")
            self._init_reg_part()
            #del init_reg
        self._select_bank(0)
Пример #4
0
    def _init(self, game_mode=False):
        i2c.init()
        temp = 0
        sleep(1)

        # Intentionally duplicated
        self._select_bank(0)

        temp = self._read_reg(0)
        if temp == 0x20:
            print("Writing registers")
            self._init_reg_part()
            # del init_reg
        self._select_bank(1)
        if game_mode:
            self._write_reg(0x65, 0x12)
        else:
            self._write_reg(0x65, 0xB7)
        self._select_bank(0)
Пример #5
0
 def __init__(self):
     i2c.init(freq=100000, sda=pin20, scl=pin19)
     writeBuf = bytearray(2)
     readBuf = bytearray(1)
     writeBuf[0] = 0x00
     i2c.write(0x6F, writeBuf, False)
     readBuf = i2c.read(0x6F, 1, False)
     readCurrentSeconds = readBuf[0]
     writeBuf[0] = 0x07
     writeBuf[1] = 0x43
     i2c.write(0x6F, writeBuf, False)
     writeBuf[0] = 0x03
     i2c.write(0x6F, writeBuf, False)
     readBuf = i2c.read(0x6F, 1, False)
     readWeekDayReg = readBuf[0]
     writeBuf[0] = 0x03
     writeBuf[1] = 0x08 | readWeekDayReg
     i2c.write(0x6F, writeBuf, False)
     writeBuf[0] = 0x00
     writeBuf[1] = 0x80 | readCurrentSeconds
     i2c.write(0x6F, writeBuf, False)
Пример #6
0
from microbit import i2c, sleep
from gc import collect

i2c.init()


class Sunlight():
    def __init__(self):
        while (self.read(0x00) != 0x45):
            print('Si1145 not ready...')
            sleep(1000)
        print('Si1145 preparing...')
        self.reset()
        self.deinit()
        print('Si1145 ready!')

    def read(self, reg, num_bytes=1, signed=False, le=False):
        i2c.write(0x60, bytearray([reg]))
        n = 0
        for x in reversed(i2c.read(0x60, num_bytes)):
            n <<= 8
            n |= x
        if signed:
            mask = 2**((num_bytes * 8) - 1)
            n = -(n & mask) + (n & ~mask)
        collect()
        return n

    def reset(self):
        i2c.write(0x60, bytearray([0x08, 0x0]))
        i2c.write(0x60, bytearray([0x09, 0x0]))
Пример #7
0
def init_i2c():
    global g_i2c_initialized
    if g_i2c_initialized is False:
        i2c.init(100000, pin20, pin19)
        g_i2c_initialized = True
Пример #8
0
 def __init__(self, addr=0x44):
     i2c.init(freq=20000)
     self._addr = addr
Пример #9
0
 def __init__(self):
     i2c.init(freq=20000)
     i2c.write(0x40, bytearray([0x88]))