当前位置: 首页>>代码示例>>Python>>正文


Python SMBus.write_byte_data方法代码示例

本文整理汇总了Python中smbus.SMBus.write_byte_data方法的典型用法代码示例。如果您正苦于以下问题:Python SMBus.write_byte_data方法的具体用法?Python SMBus.write_byte_data怎么用?Python SMBus.write_byte_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在smbus.SMBus的用法示例。


在下文中一共展示了SMBus.write_byte_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_temp

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
def get_temp():
    # zlecenie konwersji
    i2c_bus = SMBus(1)
    i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 10, 1)
    sleep(1)
    cel = i2c_bus.read_word_data(0x20, 5)
    cel = cel >> 8
    return cel
开发者ID:Mateo89,项目名称:AquaPC-BACKEND,代码行数:10,代码来源:Light2ModHelper.py

示例2: MTSMBus

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class MTSMBus(I2CBus):
    """ Multi-thread compatible SMBus bus.

    This is just a wrapper of SMBus, serializing I/O on the bus for use
    in multi-threaded context and adding _i2c_ variants of block transfers.
    """

    def __init__(self, bus_id=1, **kwargs):
        """
        :param int bus_id: the SMBus id (see Raspberry Pi documentation)
        :param kwargs: parameters transmitted to :py:class:`smbus.SMBus` initializer
        """
        I2CBus.__init__(self, **kwargs)
        self._bus = SMBus(bus_id)
        # I/O serialization lock
        self._lock = threading.Lock()

    def read_byte(self, addr):
        with self._lock:
            return self._bus.read_byte(addr)

    def write_byte(self, addr, data):
        with self._lock:
            self._bus.write_byte(addr, data)

    def read_byte_data(self, addr, reg):
        with self._lock:
            return self._bus.read_byte_data(addr, reg)

    def write_byte_data(self, addr, reg, data):
        with self._lock:
            self._bus.write_byte_data(addr, reg, data)

    def read_word_data(self, addr, reg):
        with self._lock:
            return self._bus.read_word_data(addr, reg)

    def write_word_data(self, addr, reg, data):
        with self._lock:
            self._bus.write_word_data(addr, reg, data)

    def read_block_data(self, addr, reg):
        with self._lock:
            return self._bus.read_block_data(addr, reg)

    def write_block_data(self, addr, reg, data):
        with self._lock:
            self._bus.write_block_data(addr, reg, data)

    def read_i2c_block_data(self, addr, reg, count):
        with self._lock:
            return self._bus.read_i2c_block_data(addr, reg, count)

    def write_i2c_block_data(self, addr, reg, data):
        with self._lock:
            self._bus.write_i2c_block_data(addr, reg, data)
开发者ID:pobot-pybot,项目名称:pybot-i2c,代码行数:58,代码来源:i2c.py

示例3: PiGlowService

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class PiGlowService(rpyc.Service):

	def on_connect(self):
		pass

	def on_disconnect(self):
		pass

	def exposed_init(self):
		self.bus = SMBus(1)
		self.bus.write_byte_data(0x54, 0x00, 0x01)
		self.bus.write_byte_data(0x54, 0x13, 0xFF)
		self.bus.write_byte_data(0x54, 0x14, 0xFF)
		self.bus.write_byte_data(0x54, 0x15, 0xFF)

	def exposed_colours(self, red, orange, yellow, green, blue, white):
		try:
			self.bus.write_i2c_block_data(0x54, 0x01, [red, orange, yellow, green, blue, green, red, orange, yellow, white, white, blue, white, green, blue, yellow, orange, red])
			self.bus.write_byte_data(0x54, 0x16, 0xFF)
		except IOError:
			pass

	def exposed_all_off(self):
		try:
			self.bus.write_i2c_block_data(0x54, 0x01, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
			self.bus.write_byte_data(0x54, 0x16, 0xFF)
		except IOError:
			pass
开发者ID:RTSYork,项目名称:Pidar,代码行数:30,代码来源:piglow.py

示例4: __init__

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class i2cDevice:
    def __init__(self, bus_number):
        self.BC_addr = 0x25
        self.bus = SMBus(bus_number)

    def read_register(self, address):
        self.bus.write_byte(self.BC_addr, address)
        time.sleep(0.02)
        data = struct.pack('B', self.bus.read_byte(self.BC_addr))
        return data

    def write_register(self, address, data):
        self.bus.write_byte_data(self.BC_addr, address, data)
        time.sleep(0.02)
开发者ID:r00tkillah,项目名称:BLINKERCOUGH,代码行数:16,代码来源:blinkercough.py

示例5: Device

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class Device(object):
    def __init__(self, address, bus):
        self._bus = SMBus(bus)
        self._address = address

    def writeRaw8(self, value):
        value = value & 0xff
        self._bus.write_byte(self._address, value)

    def readRaw8(self):
        result = self._bus.read_byte(self._address) & 0xff
        return result

    def write8(self, register, value):
        value = value & 0xff
        self._bus.write_byte_data(self._address, register, value)

    def readU8(self, register):
        result = self._bus.read_byte_data(self._address, register) & 0xFF
        return result

    def readS8(self, register):
        result = self.readU8(register)
        if result > 127:
            result -= 256
        return result

    def write16(self, register, value):
        value = value & 0xffff
        self._bus.write_word_data(self._address, register, value)

    def readU16(self, register, little_endian = True):
        result = self._bus.read_word_data(self._address,register) & 0xFFFF
        if not little_endian:
            result = ((result << 8) & 0xFF00) + (result >> 8)
        return result

    def readS16(self, register, little_endian = True):
        result = self.readU16(register, little_endian)
        if result > 32767:
            result -= 65536
        return result

    def writeList(self, register, data):
        self._bus.write_i2c_block_data(self._address, register, data)

    def readList(self, register, length):
        results = self._bus.read_i2c_block_data(self._address, register, length)
        return results
开发者ID:jcollie,项目名称:rpiwr,代码行数:51,代码来源:i2c.py

示例6: get

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
    def get(self):
        lStatus = 'ok'
        lArgs = self.__mParser.parse_args()
        lBusId = int(lArgs['bus_id'], 0)
        lAddress = int(lArgs['address'], 0)
        lValue = int(lArgs['value'], 0)
        lBus = SMBus(lBusId)

        try:
            if lArgs['cmd'] is None:
                lBus.write_byte(lAddress, lValue)
            else:
                lCommand = int(lArgs['cmd'], 0)
                lBus.write_byte_data(lAddress, lCommand, lValue)
        except IOError, pExc:
            lStatus = "Error writing data: " + str(pExc)
开发者ID:rpoisel,项目名称:switcher-py,代码行数:18,代码来源:resources.py

示例7: __init__

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class IMU:

    def __init__(self):

        # 0 for R-Pi Rev. 1, 1 for Rev. 2
        self.bus = SMBus(1)

        #initialise the accelerometer
        self.writeACC(CTRL_REG1_XM, 0b01100111) #z,y,x axis enabled, continuos update,  100Hz data rate
        self.writeACC(CTRL_REG2_XM, 0b00100000) #+/- 16G full scale

    def writeACC(self, register,value):
        self.bus.write_byte_data(ACC_ADDRESS , register, value)
        return -1
        
    def readACCx(self):
        acc_l = self.bus.read_byte_data(ACC_ADDRESS, OUT_X_L_A)
        acc_h = self.bus.read_byte_data(ACC_ADDRESS, OUT_X_H_A)
    	acc_combined = (acc_l | acc_h <<8)
    	return acc_combined  if acc_combined < 32768 else acc_combined - 65536


    def readACCy(self):
        acc_l = self.bus.read_byte_data(ACC_ADDRESS, OUT_Y_L_A)
        acc_h = self.bus.read_byte_data(ACC_ADDRESS, OUT_Y_H_A)
    	acc_combined = (acc_l | acc_h <<8)
    	return acc_combined  if acc_combined < 32768 else acc_combined - 65536

    def readACCz(self):
        acc_l = self.bus.read_byte_data(ACC_ADDRESS, OUT_Z_L_A)
        acc_h = self.bus.read_byte_data(ACC_ADDRESS, OUT_Z_H_A)
        acc_combined = (acc_l | acc_h <<8)
    	return acc_combined  if acc_combined < 32768 else acc_combined - 65536
    
    def read_simple_accelerometer(self):
        ACCx = self.readACCx()
        ACCy = self.readACCy()
        ACCz = self.readACCz()
        return (ACCx, ACCy, ACCz)
        
    def get_acceleration_norm(self):
        x = self.readACCx() * 0.732 / 1000
        y = self.readACCy() * 0.732 / 1000
        z = self.readACCz() * 0.732 / 1000
        return math.sqrt(x*x+y*y+z*z);
开发者ID:beckel,项目名称:carpi,代码行数:47,代码来源:imu.py

示例8: __init__

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class TMP100:
    """ Class to read the onboard temperatur Sensor"""

    _SLAVE_ADDR = 0x49
    _CONFIG_REG = 0x01
    _TEMP_REG = 0x00
    # config register
    _CONFIG_REG_OS = 0x01
    _CONFIG_REG_RES_9B = 0x00
    _CONFIG_REG_RES_12B = 0x03
    _CONFIG_REG_TRIG_OS = 0x80
    def __init__(self,device_number = 1):
        """ """
        try:
            self.bus = SMBus(device_number)
        except Exception:
            raise i2cError()
        configList = [self._CONFIG_REG_OS, self._CONFIG_REG_RES_12B]
        self.configTMP100(configList)

    def configTMP100(self, list):
        """ Write list elements to tmp100#s configuration register"""
        reg = (list[1] << 5) + list[0]
        # write to config register
        self.bus.write_byte_data(self._SLAVE_ADDR,self._CONFIG_REG,reg)
        if DEBUG:
            # read config register back
            tmpReg = self.bus.read_byte_data(self._SLAVE_ADDR,self._CONFIG_REG)
            print(reg,tmpReg)

    def  getTemperature(self):
        """ Get temperature readings """
        # read first config register
        config = self.bus.read_byte_data(self._SLAVE_ADDR,self._CONFIG_REG)
        #trigger single shot
        newConfig = config + self._CONFIG_REG_TRIG_OS
        # write config register new value back
        self.bus.write_byte_data(self._SLAVE_ADDR,self._CONFIG_REG,newConfig)
        time.sleep(0.001) # wait a bit
        #read temperature register
        raw = self.bus.read_i2c_block_data(self._SLAVE_ADDR,self._TEMP_REG)[:2]
        val = ((raw[0] << 8) + raw[1]) >> 4

        #TODO: get resolution factor properly :)
        return val*0.0625
开发者ID:NicolasCaspari,项目名称:WeatherShield,代码行数:47,代码来源:tmp100_class.py

示例9: PCF8574

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class PCF8574(object):

    class GPIO(object):

        def __init__(self, expander, bit, inverted=False):
            self.expander = expander
            self.bit = bit
            self.inverted = inverted

        def on(self):
            self.expander.write_bit(self.bit, not self.inverted)

        def off(self):
            self.expander.write_bit(self.bit, self.inverted)
    
    def __init__(self, address, bus=1, byte=0):
        self.address = address
        self.bus = SMBus(bus)
        self.byte = byte
        self.data = 0xFF

    def __del__(self):
        self.write_byte(0xFF)

    def commit(self):
        self.bus.write_byte_data(self.address, self.byte, self.data)
        
    def write_byte(self, data):
        self.data = data
        self.commit()

    def write_bit(self, bit, value):
        mask = 1 << bit
        if value:
            self.data |= mask
        else:
            self.data &= ~mask
        self.commit()

    def get_gpio(self, bit, inverted=False):
        return self.GPIO(self, bit, inverted)
开发者ID:divot,项目名称:brewmaster,代码行数:43,代码来源:gpio.py

示例10: GetAlt

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
def GetAlt():
    # get the altitude from the MPL3115a2 device
    print "GetAlt()"

    # device address and register addresses
    altAddress = 0x60
    ctrlReg1 = 0x26
    ptDataCfg = 0x13

    # values
    oversample128 = 0x38
    oneShot = 0x02
    altMode = 0x80

    bus = SMBus(1)
    for i in range(0, 5):
        whoAmI = bus.read_byte_data(altAddress, 0x0C)
        if whoAmI == 0xC4:
            break
        elif i == 4:
            sys.exit()
        else:
            time.sleep(0.5)
    bus.write_byte_data(altAddress, ptDataCfg, 0x07)

    oldSetting = bus.read_byte_data(altAddress, ctrlReg1)

    newSetting = oldSetting | oversample128 | oneShot | altMode

    bus.write_byte_data(altAddress, ctrlReg1, newSetting)

    status = bus.read_byte_data(altAddress, 0x00)
    while (status & 0x08) == 0:
        status = bus.read_byte_data(altAddress, 0x00)
        time.sleep(0.5)
    msb, csb, lsb = bus.read_i2c_block_data(altAddress, 0x01, 3)
    alt = ((msb << 24) | (csb << 16) | (lsb << 8)) / 65536.0
    if alt > (1 << 15):
        alt -= 1 << 16

    return alt
开发者ID:adam0antium,项目名称:drone,代码行数:43,代码来源:signalLogger.py

示例11: heatProcI2C

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
def heatProcI2C(cycle_time, duty_cycle, conn):
    p = current_process()
    print "Starting:", p.name, p.pid
    bus = SMBus(0)
    bus.write_byte_data(0x26, 0x00, 0x00)  # set I/0 to write
    while True:
        while conn.poll():  # get last
            cycle_time, duty_cycle = conn.recv()
        conn.send([cycle_time, duty_cycle])
        if duty_cycle == 0:
            bus.write_byte_data(0x26, 0x09, 0x00)
            time.sleep(cycle_time)
        elif duty_cycle == 100:
            bus.write_byte_data(0x26, 0x09, 0x01)
            time.sleep(cycle_time)
        else:
            on_time, off_time = getonofftime(cycle_time, duty_cycle)
            bus.write_byte_data(0x26, 0x09, 0x01)
            time.sleep(on_time)
            bus.write_byte_data(0x26, 0x09, 0x00)
            time.sleep(off_time)
开发者ID:honestrock,项目名称:RasPiBrew,代码行数:23,代码来源:raspibrew.py

示例12: reset

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
 def reset():
     i2c_bus = SMBus(1)
     i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 0, 0)
     i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 1, 0)
     i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 2, 0)
     i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 3, 0)
     i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 4, 255)
开发者ID:Mateo89,项目名称:AquaPC-BACKEND,代码行数:9,代码来源:Light2ModHelper.py

示例13: readMPL3155

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
def readMPL3155():
    # I2C Constants
    ADDR = 0x60
    CTRL_REG1 = 0x26
    PT_DATA_CFG = 0x13
    bus = SMBus(2)

    who_am_i = bus.read_byte_data(ADDR, 0x0C)
    print hex(who_am_i)
    if who_am_i != 0xc4:
        tfile = open('temp.txt', 'w')
        tfile.write("Barometer funktioniert nicht")
        tfile.close()
        exit(1)

    # Set oversample rate to 128
    setting = bus.read_byte_data(ADDR, CTRL_REG1)
    #newSetting = setting | 0x38
    newSetting = 0x38
    bus.write_byte_data(ADDR, CTRL_REG1, newSetting)

    # Enable event flags
    bus.write_byte_data(ADDR, PT_DATA_CFG, 0x07)

    # Toggel One Shot
    setting = bus.read_byte_data(ADDR, CTRL_REG1)
    if (setting & 0x02) == 0:
        bus.write_byte_data(ADDR, CTRL_REG1, (setting | 0x02))

    # Read sensor data
    print "Waiting for data..."
    status = bus.read_byte_data(ADDR,0x00)
    #while (status & 0x08) == 0:
    while (status & 0x06) == 0:
        #print bin(status)
        status = bus.read_byte_data(ADDR,0x00)
        time.sleep(1)

    print "Reading sensor data..."
    status = bus.read_byte_data(ADDR,0x00)
    p_data = bus.read_i2c_block_data(ADDR,0x01,3)
    t_data = bus.read_i2c_block_data(ADDR,0x04,2)

    p_msb = p_data[0]
    p_csb = p_data[1]
    p_lsb = p_data[2]
    t_msb = t_data[0]
    t_lsb = t_data[1]

    pressure = (p_msb << 10) | (p_csb << 2) | (p_lsb >> 6)
    p_decimal = ((p_lsb & 0x30) >> 4)/4.0

    celsius = t_msb + (t_lsb >> 4)/16.0

    tfile = open('temp.txt', 'w')
    tfile.write("Luftdruck "+str(pressure/100)+" Hektopascal. ")
    tfile.write("Temperatur "+str("{0:.1f}".format(celsius).replace('.',','))+" Grad Celsius")
    tfile.close()
开发者ID:kirchnet,项目名称:Newspaper-Reader,代码行数:60,代码来源:barometric_function.py

示例14: __init__

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
class MB85RC04:
	def __init__(self, I2C_bus_number = 1,  address = 0x50):
		self.bus = SMBus(I2C_bus_number)
		self.address = address


	def readByte(self, registerAddress):
		if(registerAddress > 255):
			self.address = self.address | 1
			registerAddress = registerAddress - 256
		else:
			self.address = self.address & 0xFE	
		return self.bus.read_byte_data(self.address, registerAddress)
	
	def writeByte(self, registerAddress, data):
		if(registerAddress > 255):
                        self.address = self.address | 1
                        registerAddress = registerAddress - 256
                else:
                        self.address = self.address & 0xFE
                self.bus.write_byte_data(self.address, registerAddress, data)

	def readBytes(self, registerAddress):
                if(registerAddress > 255):
                        self.address = self.address | 1
                        registerAddress = registerAddress - 256
                else:
                        self.address = self.address & 0xFE
                return self.bus.read_i2c_block_data(self.address, registerAddress)
	
	def writeBytes(self, registerAddress, data):
                if(registerAddress > 255):
                        self.address = self.address | 1
                        registerAddress = registerAddress - 256
                else:
                        self.address = self.address & 0xFE
                self.bus.write_i2c_block_data(self.address, registerAddress, data)
开发者ID:AlexeyBulatov,项目名称:Navio2,代码行数:39,代码来源:MB85RC04.py

示例15: set_fun_speed

# 需要导入模块: from smbus import SMBus [as 别名]
# 或者: from smbus.SMBus import write_byte_data [as 别名]
def set_fun_speed(level):
    i2c_bus = SMBus(1)

    if level == 0:
        i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 4, 255)
    if level == 1:
        i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 4, 125)
    if level == 2:
        i2c_bus.write_byte_data(Register.LIGHT2_ADDRESS, 4, 0)
开发者ID:Mateo89,项目名称:AquaPC-BACKEND,代码行数:11,代码来源:Light2ModHelper.py


注:本文中的smbus.SMBus.write_byte_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。