本文整理匯總了Python中Adafruit_I2C.Adafruit_I2C方法的典型用法代碼示例。如果您正苦於以下問題:Python Adafruit_I2C.Adafruit_I2C方法的具體用法?Python Adafruit_I2C.Adafruit_I2C怎麽用?Python Adafruit_I2C.Adafruit_I2C使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Adafruit_I2C
的用法示例。
在下文中一共展示了Adafruit_I2C.Adafruit_I2C方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, address=0x48, ic=__IC_ADS1015, debug=False):
# Depending on if you have an old or a new Raspberry Pi, you
# may need to change the I2C bus. Older Pis use SMBus 0,
# whereas new Pis use SMBus 1. If you see an error like:
# 'Error accessing 0x48: Check your I2C address '
# change the SMBus number in the initializer below!
self.i2c = Adafruit_I2C(address)
self.address = address
self.debug = debug
# Make sure the IC specified is valid
if ((ic < self.__IC_ADS1015) | (ic > self.__IC_ADS1115)):
if (self.debug):
print "ADS1x15: Invalid IC specfied: %h" % ic
return -1
else:
self.ic = ic
# Set pga value, so that getLastConversionResult() can use it,
# any function that accepts a pga value must update this.
self.pga = 6144
示例2: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, busnum=-1, debug=False, hires=False):
# Accelerometer and magnetometer are at different I2C
# addresses, so invoke a separate I2C instance for each
self.accel = Adafruit_I2C(self.LSM303_ADDRESS_ACCEL, busnum, debug)
self.mag = Adafruit_I2C(self.LSM303_ADDRESS_MAG , busnum, debug)
# Enable the accelerometer
self.accel.write8(self.LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x27)
# Select hi-res (12-bit) or low-res (10-bit) output mode.
# Low-res mode uses less power and sustains a higher update rate,
# output is padded to compatible 12-bit units.
if hires:
self.accel.write8(self.LSM303_REGISTER_ACCEL_CTRL_REG4_A,
0b00001000)
else:
self.accel.write8(self.LSM303_REGISTER_ACCEL_CTRL_REG4_A, 0)
# Enable the magnetometer
self.mag.write8(self.LSM303_REGISTER_MAG_MR_REG_M, 0x00)
# Interpret signed 12-bit acceleration component from list
示例3: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, address=0x40, debug=False):
self.i2c = Adafruit_I2C(address)
self.i2c.debug = debug
self.address = address
self.debug = debug
if (self.debug):
print "Reseting PCA9685 MODE1 (without SLEEP) and MODE2"
self.setAllPWM(0, 0)
self.i2c.write8(self.__MODE2, self.__OUTDRV)
self.i2c.write8(self.__MODE1, self.__ALLCALL)
time.sleep(0.005) # wait for oscillator
mode1 = self.i2c.readU8(self.__MODE1)
mode1 = mode1 & ~self.__SLEEP # wake up (reset sleep)
self.i2c.write8(self.__MODE1, mode1)
time.sleep(0.005) # wait for oscillator
示例4: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, address=0x70, debug=False):
self.i2c = Adafruit_I2C(address)
self.address = address
self.debug = debug
# Turn the oscillator on
self.i2c.write8(self.__HT16K33_REGISTER_SYSTEM_SETUP | 0x01, 0x00)
# Turn blink off
self.setBlinkRate(self.__HT16K33_BLINKRATE_OFF)
# Set maximum brightness
self.setBrightness(15)
# Clear the screen
self.clear()
示例5: calculateFrequency
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def calculateFrequency():
"""calculate the station frequency based upon the upper and lower bits read from the device"""
#bus = smbus.SMBus (0) # RASP older version (256MB)
repeat = 0
f =0.0
with i2clib.I2CMaster() as b:
results = b.transaction(
reading(add, 5)
)
uF = results[0][0]&0x3F
lF = results[0][1]
# this is probably not the best way of doing this but I was having issues with the
# frequency being off by as much as 1.5 MHz
current_freq = round((float(round(int(((int(uF)<<8)+int(lF))*cof/4-22500)/100000)/10)-.2)*10)/10
return current_freq
#import pigpio
#i2c = smbus.SMBus(1) # newer version RASP (512 megabytes)
#bus = smbus.SMBus (0) # RASP older version (256MB)
#af = Adafruit_I2C(0x60, 1, True)
#pipi = pigpio.pi()
示例6: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, address=0x40, debug=False):
self.i2c = Adafruit_I2C(address)
self.address = address
self.debug = debug
if (self.debug):
print "Reseting PCA9685"
self.i2c.write8(self.__MODE1, 0x00)
示例7: begin
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def begin(self, addr = 0x70, bus = -1):
"""Initialize the Trellis at the provided I2C address and bus number."""
self._i2c = Adafruit_I2C.Adafruit_I2C(addr, bus)
self._i2c.writeList(0x21, []) # Turn on the oscillator.
self.blinkRate(HT16K33_BLINK_OFF)
self.setBrightness(15) # Max brightness.
self._i2c.writeList(0xA1, []) # Turn on interrupt, active high.
示例8: __init__
# 需要導入模塊: import Adafruit_I2C [as 別名]
# 或者: from Adafruit_I2C import Adafruit_I2C [as 別名]
def __init__(self, address=0x39, debug=0, pause=0.8):
self.i2c = Adafruit_I2C(address)
self.address = address
self.pause = pause
self.debug = debug
self.gain = 0 # no gain preselected
self.i2c.write8(0x80, 0x03) # enable the device