Python smbus.SMBus() Examples
The following are 30
code examples of smbus.SMBus().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
smbus
, or try the search function
.
Example #1
Source File: rw1062.py From pyLCI with Apache License 2.0 | 7 votes |
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)
Example #2
Source File: pcf8574.py From pyLCI with Apache License 2.0 | 7 votes |
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)
Example #3
Source File: lcd_i2c_pcf8574.py From piradio with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: mcp23008.py From pyLCI with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: pcf8574.py From pyLCI with Apache License 2.0 | 6 votes |
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()
Example #6
Source File: main.py From MPU-6050-9250-I2C-CompFilter with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: MPR121.py From rpieasy with GNU General Public License v3.0 | 6 votes |
def connect(self): self.bus = smbus.SMBus(self.i2c_channel) # Software reset (documented in data sheet for MPR121) self.bus.write_byte_data(self.i2c_address, self.__Software_Reset_Register, 0x63) # Put the device into stand-by, ready to write settings. # (Cannot write settings if the device is running.) self.bus.write_byte_data(self.i2c_address, self.__Electrode_Configuration, 0x00) # Write the default settings to the device for (addr, value) in self.__settings: self.bus.write_byte_data(self.i2c_address, addr, value) # Enable all 12 electrodes and put the device into run mode. self.bus.write_byte_data(self.i2c_address, self.__Electrode_Configuration, 0x0C)
Example #8
Source File: _P028_BMx280.py From rpieasy with GNU General Public License v3.0 | 6 votes |
def __init__(self, i2c_bus=None, sensor_address=ADDR): if i2c_bus != None: self.bus = i2c_bus # smbus.SMBus(1) self.sensor_address = sensor_address self.ho = self.HO_1 self.po = self.PO_1 self.to = self.TO_1 self.mode = self.MODE_SLEEP self.tstandy = self.TSTANDBY_1000 self.filter = self.FILTER_OFF self.readinprogress = 0 self.read_calibration_parameters() # initialize once self.bus.write_byte_data(self.sensor_address, self.REGISTER_CTRL_HUM, self.get_reg_ctrl_hum()) self.bus.write_byte_data(self.sensor_address, self.REGISTER_CTRL_MEAS, self.get_reg_ctrl_meas()) self.bus.write_byte_data(self.sensor_address, self.REGISTER_CONFIG, self.get_reg_config())
Example #9
Source File: PCA9685.py From ai-makers-kit with MIT License | 6 votes |
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
Example #10
Source File: PCA9685.py From ai-makers-kit with MIT License | 6 votes |
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
Example #11
Source File: __init__.py From button-shim with MIT License | 6 votes |
def setup(): global _t_poll, _bus if _bus is not None: return _bus = smbus.SMBus(1) _bus.write_byte_data(ADDR, REG_CONFIG, 0b00011111) _bus.write_byte_data(ADDR, REG_POLARITY, 0b00000000) _bus.write_byte_data(ADDR, REG_OUTPUT, 0b00000000) _t_poll = Thread(target=_run) _t_poll.daemon = True _t_poll.start() set_pixel(0, 0, 0) atexit.register(_quit)
Example #12
Source File: MMA8452Q.py From Sixfab_RPi_CellularIoT_App_Shield with MIT License | 6 votes |
def __init__(self): # Get I2C bus self.bus = smbus.SMBus(1) # MMA8452Q address, 0x1C(28) # Select Control register, 0x2A(42) # 0x00(00) StandBy mode self.bus.write_byte_data(0x1C, 0x2A, 0x00) # MMA8452Q address, 0x1C(28) # Select Control register, 0x2A(42) # 0x01(01) Active mode self.bus.write_byte_data(0x1C, 0x2A, 0x01) # MMA8452Q address, 0x1C(28) # Select Configuration register, 0x0E(14) # 0x00(00) Set range to +/- 2g self.bus.write_byte_data(0x1C, 0x0E, 0x00) time.sleep(0.5) #public Function
Example #13
Source File: adafruit_plate.py From pyLCI with Apache License 2.0 | 6 votes |
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)
Example #14
Source File: adafruit_plate.py From pyLCI with Apache License 2.0 | 6 votes |
def __init__(self, addr = 0x20, bus = 1, **kwargs): """Initialises the ``InputDevice`` object. Kwargs: * ``bus``: I2C bus number. * ``addr``: I2C address of the expander. """ 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.init_expander() InputSkeleton.__init__(self, **kwargs)
Example #15
Source File: tea5767stationscanner.py From tea5767 with MIT License | 6 votes |
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
Example #16
Source File: max7318.py From pyLCI with Apache License 2.0 | 6 votes |
def __init__(self, addr = 0x20, 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)
Example #17
Source File: configuration.py From pi-topPULSE with Apache License 2.0 | 6 votes |
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
Example #18
Source File: pantilt.py From pantilt-hat with MIT License | 6 votes |
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
Example #19
Source File: rgb_cable.py From Retropie-CRT-Edition with GNU General Public License v3.0 | 6 votes |
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
Example #20
Source File: LTC2943_1.py From RaspberryPiBarcodeScanner with MIT License | 6 votes |
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.")
Example #21
Source File: main.py From pyLCI with Apache License 2.0 | 6 votes |
def i2c_detect(): o.clear() #This code for printing data one element on one row begs for a separate UI element module o.display_data("Scanning:") bus = smbus.SMBus(1) # 1 indicates /dev/i2c-1 found_devices = [] for device in range(128): try: #If you try to read and it answers, it's there bus.read_byte(device) except IOError: pass else: found_devices.append(str(hex(device))) device_count = len(found_devices) if device_count == 0: Printer("No devices found", i, o, 2, skippable=True) else: Printer(found_devices, i, o, 2, skippable=True) #Some globals for LCS
Example #22
Source File: LCD1602.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 6 votes |
def init(addr, bl): # global BUS # BUS = smbus.SMBus(1) global LCD_ADDR global BLEN LCD_ADDR = addr BLEN = bl try: send_command(0x33) # Must initialize to 8-line mode at first time.sleep(0.005) send_command(0x32) # Then initialize to 4-line mode time.sleep(0.005) send_command(0x28) # 2 Lines & 5*7 dots time.sleep(0.005) send_command(0x0C) # Enable display without cursor time.sleep(0.005) send_command(0x01) # Clear Screen BUS.write_byte(LCD_ADDR, 0x08) except: return False else: return True
Example #23
Source File: lcd_i2c_class.py From piradio with GNU General Public License v3.0 | 6 votes |
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
Example #24
Source File: lcd_i2c_pcf8475.py From piradio with GNU General Public License v3.0 | 6 votes |
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
Example #25
Source File: 31_bmp280.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 6 votes |
def __init__(self, bus_number=None, address=0x77): 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) self.dig_T1 = 0.0 self.dig_T2 = 0.0 self.dig_T3 = 0.0 self.dig_P1 = 0.0 self.dig_P2 = 0.0 self.dig_P3 = 0.0 self.dig_P4 = 0.0 self.dig_P5 = 0.0 self.dig_P6 = 0.0 self.dig_P7 = 0.0 self.dig_P8 = 0.0 self.dig_P9 = 0.0
Example #26
Source File: mlx90614.py From pyLCI with Apache License 2.0 | 5 votes |
def __init__(self, address=0x5a, bus_num=1): self.bus_num = bus_num self.address = address self.bus = smbus.SMBus(bus=bus_num)
Example #27
Source File: I2C.py From SunFounder_Super_Kit_V3.0_for_Raspberry_Pi with GNU General Public License v2.0 | 5 votes |
def __init__(self, address, bus_number=-1, debug=False): self.address = address # By default, the correct I2C bus is auto-detected using /proc/cpuinfo # Alternatively, you can hard-code the bus version below: # self.bus = smbus.SMBus(0); # Force I2C0 (early 256MB Pi's) # self.bus = smbus.SMBus(1); # Force I2C1 (512MB Pi's) if bus_number == -1: self.bus_number = self._get_bus_number() else: self.bus_number = bus_number #print (self.bus_number) self.bus = smbus.SMBus(self.bus_number) self.debug = debug
Example #28
Source File: is31fl3731.py From scroll-phat-hd with MIT License | 5 votes |
def __init__(self, i2c=None, address=0x74): """Initialise the IS31FL3731. :param i2c: smbus-compatible i2c object :param address: 7-bit i2c address of attached IS31FL3731 """ self.i2c = i2c self.address = address self.clear() if self.i2c is not None: for attr in ('read_byte_data', 'write_byte_data', 'write_i2c_block_data'): if not hasattr(self.i2c, attr): raise RuntimeError('i2c transport must implement: "{}"'.format(attr)) if self.i2c is None: try: import smbus self.i2c = smbus.SMBus(1) except ImportError as e: raise ImportError('You must supply an i2c device or install the smbus library.') except IOError as e: if hasattr(e, 'errno') and e.errno == 2: e.strerror += "\n\nMake sure you've enabled i2c in your Raspberry Pi configuration.\n" raise e try: self.reset() except IOError as e: if hasattr(e, 'errno') and e.errno == 5: e.strerror += '\n\nMake sure your Scroll pHAT HD is attached, and double-check your soldering.\n' raise e for frame in reversed(range(_NUM_FRAMES)): self.update_frame(frame) self.show_frame(frame) self.set_mode(_PICTURE_MODE) self.set_audiosync(False)
Example #29
Source File: Adafruit_I2C.py From pi_magazine with MIT License | 5 votes |
def __init__(self, address, busnum=-1, debug=False): self.address = address # By default, the correct I2C bus is auto-detected using /proc/cpuinfo # Alternatively, you can hard-code the bus version below: # self.bus = smbus.SMBus(0); # Force I2C0 (early 256MB Pi's) # self.bus = smbus.SMBus(1); # Force I2C1 (512MB Pi's) self.bus = smbus.SMBus(busnum if busnum >= 0 else Adafruit_I2C.getPiI2CBusNumber()) self.debug = debug
Example #30
Source File: imu.py From Attitude-Estimation with MIT License | 5 votes |
def __init__(self): self.power_mgmt_1 = 0x6b self.power_mgmt_2 = 0x6c self.addr = 0x68 self.bus = smbus.SMBus(1) self.bus.write_byte_data(self.addr, self.power_mgmt_1, 0) print("[IMU] Initialised.") # rad/s