예제 #1
0
  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 = wiringpi.I2C()
    self.fd = self.i2c.setup(address)
    self.address = address
    self.debug = debug

    # Make sure the IC specified is valid
    if(ic == self.__IC_ADS1015):
      self.spsDict = self.spsADS1015
    elif(ic == self.__IC_ADS1115):
      self.spsDict = self.spsADS1115
    else:
      if (self.debug):
        print("ADS1x15: Invalid IC specfied: %h" % ic)
      return -1
    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    
 def __init__(self, newCal=False):
     addr = 0x0E  #compass
     self.i2c = wiringpi2.I2C()
     self.devMAG = self.i2c.setup(addr)
     self.initCompass()
     self.offset, self.scaling = self.readCal(newCal)
     if DEBUG:
         print("offset:%s scaling:%s" %
               (str(self.offset), str(self.scaling)))
예제 #3
0
 def __init__(self, addr=ADC_ADR):
     self.NAME = DATANAME
     self.i2c = wiringpi2.I2C()
     self.devADC = self.i2c.setup(addr)
     pwrup = self.i2c.read(self.devADC)  #flush power up value
     if DEBUG == True and pwrup != -1:
         print("ADC Ready")
     self.i2c.read(self.devADC)  #flush first value
     time.sleep(BUS_GAP)
     self.i2c.write(self.devADC, ADC_CYCLE)
     time.sleep(BUS_GAP)
     self.i2c.read(self.devADC)  #flush first value
예제 #4
0
def i2c(i2cAddr, i2cMode, i2cData=None):

    # i2c = wiringpi2.I2C()
    # dev = i2c.setup(0x20) ( not sure about what to pass into the setup function, but presumably a device address? )
    # i2c.read(dev)

    i2c = wiringpi.I2C()
    dev = i2c.setup(0x20)

    i2cReturnedData = {
        'i2cAddress': i2cAddr,
        #'i2cData' : i2c.read(dev)
        'i2cData': 'returned data by I2C device'
    }

    message = Markup('I2C ' + str(i2cAddr) + ' returned : <strong>' +
                     '(not implemented yet)' + '</strong>')
    flash(message, 'success')

    return render_template('playground/index.html', **i2cReturnedData)
예제 #5
0
 def __init__(self, i2c_addr=I2C_ADDR):
     self.i2c = wp.I2C()
     self.fd = self.i2c.setup(i2c_addr)
     self._init()
예제 #6
0
import wiringpi2

wiringpi2.wiringPiSetup()

i2c = wiringpi2.I2C()


class I2C(object):
    def __init__(self, address):
        self.fd = i2c.setup(address)
        self.address = address

    def write8(self, reg, val):
        v = -1
        c = 0
        while v < 0:
            v = i2c.writeReg8(self.fd, reg, val)
            c += 1
        #print("%s: write8 %02X <- %02X: %d tries" % (self, reg, val, c))

    def write16(self, reg, val):
        v = -1
        c = 0
        while v < 0:
            v = i2c.writeReg16(self.fd, reg, val)
            c += 1
        #print("%s: write16 %02X <- %04X: %d tries" % (self, reg, val, c))

    def read16(self, reg):
        v = -1
        c = 0
예제 #7
0
 def __init__(self, pwmFreq=PWMHZ, addr=PWMADR):
     self.i2c = wiringpi2.I2C()
     self.devPWM = self.i2c.setup(addr)
     self.GPIOsetup(pwmFreq, addr)
 def __init__(self):
     addr = 0x0E  #compass
     self.i2c = wiringpi2.I2C()
     self.devMAG = self.i2c.setup(addr)
     self.initCompass()