def __init__(self, port, addr):
self.addr = addr
self.bus = smbus.SMBus(port)
# Write a single command
python类SMBus()的实例源码
def __init__(self, address=ADDR):
self.address = address
self._brightness = 127
self.bus = smbus.SMBus(1)
self.bus.write_byte_data(self.address, CMD_MODE, MODE)
self.bus.write_byte_data(self.address, CMD_OPTIONS, OPTS)
self.bus.write_byte_data(self.address, CMD_BRIGHTNESS, self._brightness)
self._BUF_MATRIX_1 = [0] * 8
self._BUF_MATRIX_2 = [0] * 8
def __init__(self):
self.picoReg = dict()
self.picoData = dict()
self.i2c = smbus.SMBus(1)
self.regDict = {
"ledOrange": 0x09,
"ledGreen": 0x0a,
"ledBlue": 0x0b,
"ledEnable": 0x15,
}
return
def __init__(self, addr, port=1):
self.addr = addr
self.bus = smbus.SMBus(port)
# Write a single command
def __init__(self):
# Program the AVR. It has a tendency to fail without the delays here.
time.sleep(5)
subprocess.call('/usr/local/bin/program_avr.sh')
time.sleep(5)
self.bus = smbus.SMBus(1) # /dev/i2c-1
def __init__(self):
self.bus = smbus.SMBus(1) # /dev/i2c-1
def __init__(self):
self.bus = smbus.SMBus(1) # /dev/i2c-1
def __init__(self):
# Program the AVR. It has a tendency to fail without the delays here.
time.sleep(5)
subprocess.call('/usr/local/bin/program_avr.sh')
time.sleep(5)
self.bus = smbus.SMBus(1) # /dev/i2c-1
def __init__(self, address, bus = smbus.SMBus(1)):
self.address = address
self.bus = bus
def __init__(self, port=1, address=0x0E, gauss=1.3, declination=(1, 57)):
self.bus = smbus.SMBus(port)
self.address = address
(degrees, minutes) = declination
self.__declDegrees = degrees
self.__declMinutes = minutes
self.__declination = (degrees + minutes / 60) * math.pi / 180
(reg, self.__scale) = self.__scales[gauss]
# 8 Average, 15 Hz, normal measurement
self.bus.write_byte_data(self.address, 0x00, 0x70)
self.bus.write_byte_data(self.address, 0x01, reg << 5) # Scale
# Continuous measurement
self.bus.write_byte_data(self.address, 0x02, 0x00)
def __init__(self, lcd_address, lcd_width):
# Define some device parameters
self.I2C_ADDR = lcd_address # 0x3f I2C device address
# To detect use sudo i2cdetect -y 0
# or for RPi 2 sudo i2cdetect -y 1
self.LCD_WIDTH = lcd_width # 16 or 20 Maximum characters per line
print ("class LCD " + str(lcd_width))
#LCD_WIDTH = 20 OR 16 # Maximum characters per line
# Define some device constants
self.LCD_CHR = 1 # Mode - Sending data
self.LCD_CMD = 0 # Mode - Sending command
self.LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
self.LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
self.LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line
self.LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line
self.LCD_BACKLIGHT = 0x08 # On
#LCD_BACKLIGHT = 0x00 # Off
self.ENABLE = 0b00000100 # Enable bit
# Timing constants
self.E_PULSE = 0.0005
self.E_DELAY = 0.0005
#Open I2C interface
self.bus = smbus.SMBus(0) # Rev 1 Pi uses 0
#bus = smbus.SMBus(1) # Rev 2 Pi uses 1
#def lcd_init():
# Initialise display
self.lcd_byte(0x33,self.LCD_CMD) # 110011 Initialise
self.lcd_byte(0x32,self.LCD_CMD) # 110010 Initialise
self.lcd_byte(0x06,self.LCD_CMD) # 000110 Cursor move direction
self.lcd_byte(0x0C,self.LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
self.lcd_byte(0x28,self.LCD_CMD) # 101000 Data length, number of lines, font size
self.lcd_byte(0x01,self.LCD_CMD) # 000001 Clear display
time.sleep(self.E_DELAY)
def __init__(self, addr=ADDRESS, port=1):
self.addr = addr
self.bus = smbus.SMBus(port)
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
def __init__(self, addr, port=1):
self.addr = addr
self.bus = smbus.SMBus(port)
# Write a single command
def __init__(self, address, bus=0, debug=False):
self.address = address
self.bus = smbus.SMBus(bus)
self.debug = debug
def __init__(self, address, busnum):
"""Create an instance of the I2C device at the specified address on the
specified I2C bus number."""
self._address = address
self._bus = smbus.SMBus(busnum)
self._logger = logging.getLogger('Adafruit_I2C.Device.Bus.{0}.Address.{1:#0X}' \
.format(busnum, address))
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
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
def __init__(self, addr, port=I2CBUS):
self.addr = addr
self.bus = smbus.SMBus(port)
# Write a single command
Adafruit_I2C.py 文件源码
项目:Raspberry-Pi-ntp-server-LCD-display
作者: jacken
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
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