本文整理汇总了Python中smbus.SMBus方法的典型用法代码示例。如果您正苦于以下问题:Python smbus.SMBus方法的具体用法?Python smbus.SMBus怎么用?Python smbus.SMBus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类smbus
的用法示例。
在下文中一共展示了smbus.SMBus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, bus_number=None, address=0x40):
'''Init the class with bus_number and address'''
if self._DEBUG:
print self._DEBUG_INFO, "Debug on"
self.address = address
if bus_number == None:
self.bus_number = self._get_bus_number()
else:
self.bus_number = bus_number
self.bus = smbus.SMBus(self.bus_number)
if self._DEBUG:
print self._DEBUG_INFO, 'Reseting PCA9685 MODE1 (without SLEEP) and MODE2'
self.write_all_value(0, 0)
self._write_byte_data(self._MODE2, self._OUTDRV)
self._write_byte_data(self._MODE1, self._ALLCALL)
time.sleep(0.005)
mode1 = self._read_byte_data(self._MODE1)
mode1 = mode1 & ~self._SLEEP
self._write_byte_data(self._MODE1, mode1)
time.sleep(0.005)
self.frequency = 60
示例2: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, gyro, acc, tau):
# Class / object / constructor setup
self.gx = None; self.gy = None; self.gz = None;
self.ax = None; self.ay = None; self.az = None;
self.gyroXcal = 0
self.gyroYcal = 0
self.gyroZcal = 0
self.gyroRoll = 0
self.gyroPitch = 0
self.gyroYaw = 0
self.roll = 0
self.pitch = 0
self.yaw = 0
self.dtTimer = 0
self.tau = tau
self.gyroScaleFactor, self.gyroHex = self.gyroSensitivity(gyro)
self.accScaleFactor, self.accHex = self.accelerometerSensitivity(acc)
self.bus = smbus.SMBus(1)
self.address = 0x68
示例3: get_smbus
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def get_smbus(self):
# detect i2C port number and assign to i2c_bus
i2c_bus = 0
for line in open('/proc/cpuinfo').readlines():
m = re.match('(.*?)\s*:\s*(.*)', line)
if m:
(name, value) = (m.group(1), m.group(2))
if name == "Revision":
if value[-4:] in ('0002', '0003'):
i2c_bus = 0
else:
i2c_bus = 1
break
try:
return smbus.SMBus(i2c_bus)
except IOError:
print ("Could not open the i2c bus.")
示例4: _write_device_state
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def _write_device_state(state):
"""INTERNAL. Send the state bits across the I2C bus"""
try:
PTLogger.debug("Connecting to bus...")
i2c_bus = SMBus(_bus_id)
state_to_send = 0x0F & state
PTLogger.debug("Writing new state: " + _get_bit_string(state_to_send))
i2c_bus.write_byte_data(_device_addr, 0, state_to_send)
result = _verify_device_state(state_to_send)
if result is True:
PTLogger.debug("OK")
else:
PTLogger.warning("Error: New state could not be verified")
return result
except:
PTLogger.warning("Error: There was a problem writing to the device")
return False
示例5: setup
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def setup(self):
if self._is_setup:
return True
if self._i2c is None:
try:
from smbus import SMBus
self._i2c = SMBus(1)
except ImportError:
if version_info[0] < 3:
raise ImportError("This library requires python-smbus\nInstall with: sudo apt-get install python-smbus")
elif version_info[0] == 3:
raise ImportError("This library requires python3-smbus\nInstall with: sudo apt-get install python3-smbus")
self.clear()
self._set_config()
atexit.register(self._atexit)
self._is_setup = True
示例6: detect
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def detect(self):
"""
This function try to detect in i2c bus 0 if any i2c device is
connected looking for addreses.
"""
p_bCheck = False
try: bus = smbus.SMBus(0)
except:
logging.info("WARNING: can't connect to i2c0")
return p_bCheck
p_lDevList = [32, 33] # 0x20/0x21 i2c address;
for device in p_lDevList:
try:
bus.read_byte(device)
p_bCheck = True
except:
pass
bus.close()
bus = None
if not p_bCheck: logging.info("WARNING: hardware jamma-rgb-pi NOT found")
else: logging.info("INFO: hardware jamma rgb-pi found")
return p_bCheck
示例7: init
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def init(self, board_rev=2, address=0x20):
bus=1
if board_rev == 1:
bus = 0
self.__bus=smbus.SMBus(bus)
self.__bus.write_byte_data(0x20,0x00,0x00)
self.__displayfunction = self.__4BITMODE | self.__2LINE | self.__5x8DOTS
#self.__displaycontrol = self.__DISPLAYCONTROL | self.__DISPLAYON | self.__CURSORON | self.__BLINKON
self.__displaycontrol = self.__DISPLAYCONTROL | self.__DISPLAYON
self.__data = 0
self.writeFourBits(0x03)
time.sleep(0.005)
self.writeFourBits(0x03)
time.sleep(0.00015)
self.writeFourBits(0x03)
self.writeFourBits(0x02)
self.writeCommand(self.__FUNCTIONSET | self.__displayfunction)
self.writeCommand(self.__displaycontrol)
self.writeCommand(0x6)
self.clear()
self.blink(False)
return
# Display Line 1 on LCD
示例8: init
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def init(self, board_rev=2):
bus = 1
if board_rev == 1:
bus = 0
self.__bus=smbus.SMBus(bus)
self.writeCommand(0x03)
self.writeCommand(0x03)
self.writeCommand(0x03)
self.writeCommand(0x02)
self.__displayfunction = self.__FUNCTIONSET | self.__2LINE | self.__5x8DOTS | self.__4BITMODE
self.__displaycontrol = self.__DISPLAYCONTROL | self.__DISPLAYON | self.__CURSORON | self.__BLINKON
self.writeCommand(self.__displayfunction)
self.writeCommand(self.__DISPLAYCONTROL | self.__DISPLAYON)
self.writeCommand(self.__CLEARDISPLAY)
self.writeCommand(self.__ENTRYMODESET | self.__ENTRYLEFT)
sleep(0.2)
# Display Line 1 on LCD
示例9: init
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def init(self, board_rev=2, address=0x27):
bus = 1
if board_rev == 1:
bus = 0
if address > 0x00:
self.i2c_address = address
self.__bus=smbus.SMBus(bus)
self.writeCommand(0x03)
self.writeCommand(0x03)
self.writeCommand(0x03)
self.writeCommand(0x02)
self.__displayfunction = self.__FUNCTIONSET | self.__2LINE | self.__5x8DOTS | self.__4BITMODE
self.__displaycontrol = self.__DISPLAYCONTROL | self.__DISPLAYON | self.__CURSORON | self.__BLINKON
self.writeCommand(self.__displayfunction)
self.writeCommand(self.__DISPLAYCONTROL | self.__DISPLAYON)
self.writeCommand(self.__CLEARDISPLAY)
self.writeCommand(self.__ENTRYMODESET | self.__ENTRYLEFT)
sleep(0.2)
# Display Line 1 on LCD
示例10: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self):
self.i2c = smbus.SMBus(1)
self.bus = i2clib.I2CMaster()
self.add = 0x60 # I2C address circuit
self.signal = 0
self.chipID = self.getChipID()
self.readyFlag = 0
self.muteFlag = 0
print("FM Radio Module TEA5767. Chip ID:", self.chipID)
self.freq = self.calculateFrequency()
if self.freq < 87.5 or self.freq > 107.9:
self.freq = 101.9
self.signal = self.getLevel()
self.stereoFlag = self.getStereoFlag()
print("Last frequency = " , self.freq, "FM. Signal level = ", self.signal, " " , self.stereoFlag)
self.writeFrequency(self.freq, 1, 1)
# self.preparesocket()
# self.ws = None
示例11: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, bus=1, addr=0x27, debug=False, **kwargs):
"""Initialises the ``Screen`` object.
Kwargs:
* ``bus``: I2C bus number.
* ``addr``: I2C address of the board.
* ``debug``: enables printing out LCD commands.
* ``**kwargs``: all the other arguments, get passed further to HD44780 constructor
"""
self.bus_num = bus
self.bus = smbus.SMBus(self.bus_num)
if type(addr) in [str, unicode]:
addr = int(addr, 16)
self.addr = addr
self.debug = debug
HD44780.__init__(self, debug = self.debug, **kwargs)
self.enable_backlight()
示例12: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, bus=1, addr=0x20, debug=False, **kwargs):
"""Initialises the ``Screen`` object.
Kwargs:
* ``bus``: I2C bus number.
* ``addr``: I2C address of the board.
* ``debug``: enalbes printing out LCD commands.
* ``chinese``: flag enabling workarounds necessary for Chinese boards to enable LCD backlight.
"""
self.bus_num = bus
self.bus = smbus.SMBus(self.bus_num)
if type(addr) in [str, unicode]:
addr = int(addr, 16)
self.addr = addr
self.debug = debug
BacklightManager.init_backlight(self, **kwargs)
HD44780.__init__(self, debug=self.debug, **kwargs)
示例13: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, bus=1, addr=0x20, debug=False, chinese=True, **kwargs):
"""Initialises the ``Screen`` object.
Kwargs:
* ``bus``: I2C bus number.
* ``addr``: I2C address of the board.
* ``debug``: enalbes printing out LCD commands.
* ``chinese``: flag enabling workarounds necessary for Chinese boards to enable LCD backlight.
"""
self.bus_num = bus
self.bus = smbus.SMBus(self.bus_num)
if type(addr) in [str, unicode]:
addr = int(addr, 16)
self.addr = addr
self.debug = debug
self.chinese = chinese
self.i2c_init()
BacklightManager.init_backlight(self, **kwargs)
HD44780.__init__(self, debug=self.debug, **kwargs)
示例14: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, bus=1, addr=0x27, debug=False, **kwargs):
"""Initialises the ``Screen`` object.
Kwargs:
* ``bus``: I2C bus number.
* ``addr``: I2C address of the board.
* ``debug``: enables printing out LCD commands.
* ``**kwargs``: all the other arguments, get passed further to HD44780 constructor
"""
self.bus_num = bus
self.bus = smbus.SMBus(self.bus_num)
if type(addr) in [str, unicode]:
addr = int(addr, 16)
self.addr = addr
self.debug = debug
self.i2c_init()
HD44780.__init__(self, debug=self.debug, **kwargs)
示例15: __init__
# 需要导入模块: import smbus [as 别名]
# 或者: from smbus import SMBus [as 别名]
def __init__(self, addr = 0x27, bus = 1, int_pin = None, **kwargs):
"""Initialises the ``InputDevice`` object.
Kwargs:
* ``bus``: I2C bus number.
* ``addr``: I2C address of the expander.
* ``int_pin``: GPIO pin to which INT pin of the expander is connected. If supplied, interrupt-driven mode is used, otherwise, library reverts to polling mode.
"""
self.bus_num = bus
self.bus = smbus.SMBus(self.bus_num)
if type(addr) in [str, unicode]:
addr = int(addr, 16)
self.addr = addr
self.int_pin = int_pin
self.init_expander()
InputSkeleton.__init__(self, **kwargs)