Python Adafruit_I2C.Adafruit_I2C() Examples

The following are 10 code examples of Adafruit_I2C.Adafruit_I2C(). 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 Adafruit_I2C , or try the search function .
Example #1
Source File: Adafruit_ADS1x15.py    From raspberrypi-examples with MIT License 6 votes vote down vote up
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 
Example #2
Source File: Adafruit_ADS1x15.py    From PiScope with MIT License 6 votes vote down vote up
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 
Example #3
Source File: LSM303.py    From BerePi with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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 
Example #4
Source File: Adafruit_PWM_Servo_Driver.py    From robotstreamer with Apache License 2.0 6 votes vote down vote up
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 
Example #5
Source File: Adafruit_LEDBackpack.py    From pi_magazine with MIT License 6 votes vote down vote up
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() 
Example #6
Source File: Adafruit_PWM_Servo_Driver.py    From runmyrobot with Apache License 2.0 6 votes vote down vote up
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 
Example #7
Source File: radio-smbus-tea5767.py    From tea5767 with MIT License 5 votes vote down vote up
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() 
Example #8
Source File: Adafruit_PWM_Servo_Driver.py    From meArmPi with MIT License 5 votes vote down vote up
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) 
Example #9
Source File: Adafruit_Trellis.py    From Adafruit_Trellis_Python with MIT License 5 votes vote down vote up
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. 
Example #10
Source File: luxreader.py    From Raspberry_Pi_Weather_Station with GNU General Public License v2.0 5 votes vote down vote up
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