• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python smbus.SMBus类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __init__

class PiGlow:
	i2c_addr = 0x54 # fixed i2c address of SN3218 ic
	bus = None

	def __init__(self, i2c_bus=1):
		self.bus = SMBus(i2c_bus)

        # first we tell the SN3218 to enable output (turn on)
		self.write_i2c(CMD_ENABLE_OUTPUT, 0x01)

        # then we ask it to enable each bank of LEDs (0-5, 6-11, and 12-17)
		self.write_i2c(CMD_ENABLE_LEDS, [0xFF, 0xFF, 0xFF])

	def update_leds(self, values):
		#print "update pwm"
		self.write_i2c(CMD_SET_PWM_VALUES, values)
		self.write_i2c(CMD_UPDATE, 0xFF)

	# a helper that writes the given value or list of values to the SN3218 IC
	# over the i2c protocol
	def write_i2c(self, reg_addr, value):
        # if a single value is provided then wrap it in a list so we can treat
        # all writes in teh same way
		if not isinstance(value, list):
			value = [value];

        # write the data to the SN3218
		self.bus.write_i2c_block_data(self.i2c_addr, reg_addr, value)
开发者ID:JamesH65,项目名称:piglow,代码行数:28,代码来源:james2.py


示例2: AM2320

class AM2320(object):
    """
    AM2320 temperature and humidity sensor class.

    :param interface:  I2C interface id.
    :type interface: :int
    :param sensor_address: AM2320 sensor I2C address. Optional, default 0x5C (92).
    :type sensor_address: int
    """

    def __init__(self, interface, sensor_address=0x5c):
        self.interface = interface
        self.address = sensor_address
        self.temperature = -1000.0
        self.humidity = -1
        self.bus = SMBus(interface)

    def _read_raw(self, command, regaddr, regcount):
        try:
            self.bus.write_i2c_block_data(self.address, 0x00, [])
            self.bus.write_i2c_block_data(self.address, command, [regaddr, regcount])

            sleep(0.002)

            buf = self.bus.read_i2c_block_data(self.address, 0, 8)
        except IOError, exc:
            raise CommunicationError(str(exc))

        buf_str = "".join(chr(x) for x in buf)

        crc = unpack('<H', buf_str[-2:])[0]
        if crc != self._am_crc16(buf[:-2]):
            raise CommunicationError("AM2320 CRC error.")
        return buf_str[2:-2]
开发者ID:contactless,项目名称:wb-mqtt-am2320,代码行数:34,代码来源:am2320.py


示例3: HTU21D

class HTU21D():
    """Class for accessing HTU21D sensors via I2C.

    Code taken from https://github.com/jasiek/HTU21D.

    Args:
        busno (int): The I2C bus (0 or 1, default is 1).
        address (byte): The I2C address of the sensor.
    """
    CMD_TRIG_TEMP_HM = 0xE3
    CMD_TRIG_HUMID_HM = 0xE5
    CMD_TRIG_TEMP_NHM = 0xF3
    CMD_TRIG_HUMID_NHM = 0xF5
    CMD_WRITE_USER_REG = 0xE6
    CMD_READ_USER_REG = 0xE7
    CMD_RESET = 0xFE

    def __init__(self, busno=1, address=config.SENSOR_ID_HUMIDITY_EXT):
        self.bus = SMBus(busno)
        self.i2c_address = address

    def read_temperature(self):
        self.reset()
        msb, lsb, crc = self.bus.read_i2c_block_data(
            self.i2c_address, self.CMD_TRIG_TEMP_HM, 3)
        return -46.85 + 175.72 * (msb * 256 + lsb) / 65536

    def read_humidity(self):
        self.reset()
        msb, lsb, crc = self.bus.read_i2c_block_data(
            self.i2c_address, self.CMD_TRIG_HUMID_HM, 3)
        return (-6 + 125 * (msb * 256 + lsb) / 65536.0) / 100.0

    def reset(self):
        self.bus.write_byte(self.i2c_address, self.CMD_RESET)
开发者ID:mfhepp,项目名称:stratosphere,代码行数:35,代码来源:sensors.py


示例4: __init__

class LEDSign:
    def __init__(self):
        self.s = SMBus(0)
        self.lock = Lock()

    def print_message(self, line, message):
        if len(message) > 255:
            message = message[:255]
        if message[:-1] != "\x00":
            message = "".join([message, "\x00"])
        self.print_message_loop(line, message)

    def print_message_loop(self, line, message):
        if message == "":
            return
        self.lock.acquire()
        self.s.write_i2c_block_data(signAddress, line, [ord(x) for x in message[0:payLoadLen]])
        self.lock.release()
        self.print_message_loop(line, message[payLoadLen:])

    def get_status(self):
        self.lock.acquire()
        labStatus = self.s.read_byte(signAddress)
        self.lock.release()
        return labStatus
开发者ID:FOULAB,项目名称:foubot-modules,代码行数:25,代码来源:ledsign.py


示例5: PCF8574

class PCF8574(object):

    def __init__(self, bus_id, address):
        super().__init__()
        self.__bus = SMBus(bus_id)
        self.__address = address
        self.__value = self.__getRealValue()

    @property
    def value(self):
        return self.__value

    @value.setter
    def value(self, value):
        self.__bus.write_byte(self.__address,
                              (~value) & 0xff
                              )
        self.__value = value

    def flipBits(self, changeBits):
        self.value ^= changeBits

    def __getRealValue(self):
        value = self.__bus.read_byte(self.__address)
        return (~value) & 0xff
开发者ID:rpoisel,项目名称:loxone-http-bridge,代码行数:25,代码来源:main.py


示例6: __init__

class motorControlBoard:
    """Class to allow communication with the motor
       control board built by me using I2C."""
    __board_I2C_address = 0

    def __init__(self, board_address):
        if isinstance(board_address, int):
            if board_address > 0 and board_address < 0x78:
                self.__board_I2C_address = board_address
            else:
                raise Exception("Board address must be an integer between 0 and 0b1111000 (=120) exclusive.")
        else:
                raise Exception("Board address must be an integer.")
        self.__bus = SMBus(1)   # FIXME = have an option to make this zero for the old Raspberry Pis

    def set_speeds(self, left_speed, right_speed):
        # Enforce limits due to 8-bit resolution
        if(left_speed < -0xff):		left_speed = -0xff
        if(left_speed > +0xff):		left_speed = +0xff
        # Enforce limits due to 8-bit resolution
        if(right_speed < -0xff):	right_speed = -0xff
        if(right_speed > +0xff):	right_speed = +0xff

        direction = 0x00;
        if(left_speed < 0):     direction |= MOTOR_CONTROL_LEFT_BACK
        elif(left_speed > 0):   direction |= MOTOR_CONTROL_LEFT_FORE
        if(right_speed < 0):    direction |= MOTOR_CONTROL_RIGHT_BACK
        elif(right_speed > 0):  direction |= MOTOR_CONTROL_RIGHT_FORE

        self.__bus.write_i2c_block_data(self.__board_I2C_address, MOTOR_CONTROL_SET_DIR_SPEED_CMD, [direction, abs(left_speed), abs(right_speed)])
开发者ID:anwar-hegazy,项目名称:i2c_motor_control,代码行数:30,代码来源:motorControl.py


示例7: __init__

    def __init__(self, busNum):
#       Remove annoying init message (The Raspberry Pi Guy) 
        if busNum == 0:
            self.__bus = SMBus(0)
        else:
            self.__bus = SMBus(1)
        self.__addr = self.__checkI2Caddress(72)
        self.__DACEnabled = 0
开发者ID:Aegidius,项目名称:apluraspi,代码行数:8,代码来源:xsgh_PCF8591P.py


示例8: get_temp

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,代码行数:8,代码来源:Light2ModHelper.py


示例9: test_open

def test_open():
    bus = SMBus()
    py.test.raises(IOError, 'bus.open(-13)')

    bus.open(BUS)  # does not raise

    if hasattr(bus, '_fd'):
        assert bus._fd != -1
开发者ID:JavierIH,项目名称:smbus-cffi,代码行数:8,代码来源:test_smbus_integration.py


示例10: Bus_Hepler_i2c

class Bus_Hepler_i2c():
	def __init__(self, bus_location=1):
		self.bus = SMBus(bus_location)
		
	def write_byte(self, address, register, byte):
		self.bus.write_i2c_block_data(address, register, [byte])
		
	def read_block_data(self, address, cmd): 
		return self.bus.read_i2c_block_data(address, cmd)
开发者ID:pixelskull,项目名称:10DOF-Sensor-Python-Driver,代码行数:9,代码来源:Sensor.py


示例11: __init__

 def __init__(self, busNum):
     #print "init PCF8591"
     if busNum == 0:
         self.__bus = SMBus(0) # on a Rev 1 board
         #print "bus 0"
     else:
         self.__bus = SMBus(1) # on a Rev 2 board
     self.__addr = self.__checkI2Caddress(0x48)
     self.__DACEnabled = 0x00
开发者ID:konradko,项目名称:pi2go,代码行数:9,代码来源:sgh_PCF8591P.py


示例12: DetectCap

def DetectCap(i2c_addr, i2c_bus, product_id):
    bus = SMBus(i2c_bus)

    try:
        if bus.read_byte_data(i2c_addr, R_PRODUCT_ID) == product_id:
            return True
        else:
            return False
    except IOError:
        return False
开发者ID:pimoroni,项目名称:cap1xxx,代码行数:10,代码来源:cap1xxx.py


示例13: __init__

 def __init__(self, busNum):
     print "init PCF8591"
     if busNum == 0:
         self.__bus = SMBus(0)  # on a Rev 1 board
         # print "bus 0"
     else:
         self.__bus = SMBus(1)  # on a Rev 2 board
     self.__addr = self.__checkI2Caddress(0x48)
     self.__DACEnabled = 0x00
     print self.readADC()  # dummy call to raise exception if no chip presnt on the i2c bus
     print "PCF8591 init completed"
开发者ID:RyanteckLTD,项目名称:scratch_gpio,代码行数:11,代码来源:sgh_PCF8591P.py


示例14: __init__

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,代码行数:14,代码来源:blinkercough.py


示例15: Pines

class Pines(object):
    """docstring for Pines"""
    def __init__(self,address):
        conf.estado = 0b11111111
        self.address = address
        self.bus = SMBus(1)
    def cero(self,pin):
        conf.estado &=~(1<<pin)
        self.bus.write_byte(self.address , conf.estado)
        return conf.estado

    def uno(self , pin):
        conf.estado |=(1<<pin)
        self.bus.write_byte(self.address , conf.estado)
        return conf.estado
            
    def toggle(self,pin):
        numero = 2**pin
        conf.estado = conf.estado^numero
        self.bus.write_byte(self.address , conf.estado)
        return conf.estado

    def toggle2(self,pin1,pin2):
        self.toggle(pin1)
        self.toggle(pin2)   
    
    def reset(self):
        self.estado = self.estado|255
        self.bus.write_byte(address , self.estado)  
开发者ID:bojack5,项目名称:smartbender,代码行数:29,代码来源:cilindro.py


示例16: DAC12

class DAC12(object):

    def __init__(self, dac_num, maximum=100.0):
        bus, self.addr = get_dac_addr(dac_num)
        self.bus = SMBus(bus)
        self.coeff = 4096/float(maximum)

    def conv(self, valeur):
        return int(ceil(valeur * self.coeff)) & 0xFFFF

    def set_eeprom(self, valeur):
        self.bus.write_word_data(self.addr, WRITE_DAC_AND_EEPROM, self.conv(valeur))

    def set(self, valeur):
        self.bus.write_word_data(self.addr, WRITE_DAC, self.conv(valeur))
开发者ID:samgratte,项目名称:BeagleboneBlack,代码行数:15,代码来源:bbb_dac.py


示例17: __init__

    def __init__(self,device=0,Port=None,Server=None):
        """
        @param device The I2C bus to use e.g. /dev/i2c-0, /dev/i2c-1 etc.
        @param Port Default=None if set to an Integer this will be the TCP/IP port to listen on.
        @param Server Default=None if set to a string e.g. '192.168.200.137' the bus listening on that address/port combination will be connected to.
        @todo Ckeck for Raspberry Pi, and its version in /Proc/CPUInfo

        If you Init an I2CBus like s = I2C(1,Port=50000) it wil listen to connections from a remote bw_library
        on any other computer a bw_library installation can make use of tcp communications like the I2C bus is connected to the local machine.

        Netbus = SPI(Server= '192.168.200.1',port=50000)
        In this case the device parameter is ignored.
        """
        self.Port = Port
        self.Server=Server
        if self.Server != None:  # TCP Client mode
            self.NetInit()
            self.Transaction=self._NetTransaction
        else:
            try:
                self.I2cBus = SMBus(device)
            except :
                print 'Need python-smbus for I2C bus to work'
                print ''
                print 'To install: sudo apt-get install python-smbus'
                return None
            if self.Port != None: #TCP Server Mode
                self.ServerThread = threading.Thread(target=self.ListenerTread)
                self.ServerThread.start()
开发者ID:rewolff,项目名称:bw_library,代码行数:29,代码来源:bw.py


示例18: __init__

    def __init__(
            self,
            brightness=None, speed=None, pulse=None, pulse_dir=None,
            i2c_bus=None):

        if i2c_bus is None:
            i2c_bus = self.get_i2c_bus()

        # Enables the LEDs
        self.bus = SMBus(i2c_bus)

        # Tell the SN3218 to enable output
        self.bus.write_byte_data(I2C_ADDR, EN_OUTPUT_ADDR, 0x01)

        # Enable each LED arm
        self.bus.write_byte_data(I2C_ADDR, EN_ARM1_ADDR, 0xFF)
        self.bus.write_byte_data(I2C_ADDR, EN_ARM2_ADDR, 0xFF)
        self.bus.write_byte_data(I2C_ADDR, EN_ARM3_ADDR, 0xFF)

        # Set default brightness and pulsing params
        self.brightness = brightness
        self.speed = speed
        self.pulse = pulse
        self.pulse_dir = pulse_dir

        # Define the LED state variable
        self.__STATE = {'leds': {}, 'params': {}}
开发者ID:bjornt,项目名称:PyGlow,代码行数:27,代码来源:PyGlow.py


示例19: get

    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,代码行数:16,代码来源:resources.py


示例20: __init__

	def __init__(self, i2c_bus=1):
		self.bus = SMBus(i2c_bus)

		# Enable output
		self.write(CMD_ENABLE_OUTPUT, 0x01)
		# Enable LEDs ( 0-5, 6-11, 12-17 )
		self.write(CMD_ENABLE_LEDS, [0xFF, 0xFF, 0XFF])
开发者ID:Gadgetoid,项目名称:python-sn3218,代码行数:7,代码来源:sn3218.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python smc_firewall.cmd函数代码示例发布时间:2022-05-27
下一篇:
Python SMBConnection.SMBConnection类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap