예제 #1
0
def voltage_set(addr, chn, voltage):
    """ Set the output voltage of the DAC7678;
    :param addr: int, I2C address of the DAC7678;
    :param chn: int, Channel number of the DAC7678, can be 0~7;
    :param voltage: Target output voltage;
    :return: None
    """
    if voltage < 0.0 or voltage > 3.0:
        print "Voltage out of range"
        return
    if chn < 0 or 8 <= chn:
        print "Unknown channel"
        return
        # a,b,c,d
        # i,j,k,l
    maxv = 3

    dac = float(voltage) / maxv
    dac *= 0xFFFF
    dac = int(dac)
    dac_low = dac & 0xFF
    dac_high = (dac >> 8) & 0xFF

    # Write into selected channel
    i2c.write(addr, [chn, dac_high, dac_low])
    # Update Selected channel
    i2c.write(addr, [0x10 | chn, 0x0, 0x0])
예제 #2
0
def write_buffer(func_id_string,data):
    try:
        func_id_string = func_id_string.upper()
        func_id = FUN_ID_MAP[func_id_string]
        wr_dat_buf = [func_id]
        wr_dat_buf.extend(data)
        i2c.write(I2C_ADDR,wr_dat_buf)
    except KeyError:
        print "[sc18is602.write_buffer]:Please input correct SS channel!"
예제 #3
0
def set_dir(addr, p0x, p1x):
    i2c.write(addr, [0x6, p0x, p1x])
예제 #4
0
def all_output_low(addr):
    i2c.write(addr, [0x2, 0x00, 0x00])
예제 #5
0
def all_output_high(addr):
    i2c.write(addr, [0x2, 0xff, 0xff])
예제 #6
0
def all_input(addr):
    i2c.write(addr, [0x6, 0xff, 0xff])
예제 #7
0
def all_output(addr):
    i2c.write(addr, [0x6, 0x00, 0x00])
예제 #8
0
def set_output(addr, p0x, p1x):
    i2c.write(addr, [0x2, p0x, p1x])