コード例 #1
1
ファイル: gpio_work.py プロジェクト: ZH8000/FlyCamera
# Import standard Python time library.
import time

# Import GPIO and FT232H modules.
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H

# Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
FT232H.use_FT232H()

# Create an FT232H object that grabs the first available FT232H device found.
ft232h = FT232H.FT232H()

# Configure digital inputs and outputs using the setup function.
# Note that pin numbers 0 to 15 map to pins D0 to D7 then C0 to C7 on the board.
ft232h.setup(7, GPIO.IN)   # Make pin D7 a digital input.
ft232h.setup(8, GPIO.OUT)  # Make pin C0 a digital output.

# Loop turning the LED on and off and reading the input state.
print 'Press Ctrl-C to quit.'
while True:
	# Set pin C0 to a high level so the LED turns on.
	#ft232h.output(8, GPIO.HIGH)
	# Sleep for 1 second.
	#time.sleep(1)

	# Set pin C0 to a low level so the LED turns off.
	#ft232h.output(8, GPIO.LOW)
	# Sleep for 1 second.
	#time.sleep(1)
	# Read the input on pin D7 and print out if it's high or low.
コード例 #2
0
    def __init__(self):
        '''This code is taken from the SPI example on Adafruit's Website
           https://learn.adafruit.com/adafruit-ft232h-breakout/spi
        '''

        # Temporarily disable FTDI serial drivers.
        FT232H.use_FT232H()
        # Find the first FT232H device.
        ft232h = FT232H.FT232H()
        # Create a SPI interface from the FT232H using pin 8 (C0) as chip select.
        # Use a clock speed of 3mhz, SPI mode 0, and most significant bit first.
        self.spi = FT232H.SPI(ft232h,
                              cs=8,
                              max_speed_hz=3000000,
                              mode=0,
                              bitorder=FT232H.MSBFIRST)

        self.power_mode = 3  # set power mode to normal
        self.dout = 0  # set DOUT to three state at end of transfer
        self.range = 0  # set range to double Vref
        self.coding = 1  # set coding to straight binary
        self.seq = 0  # turn off sequencer
        self.write = 1  # write command
        self.shadow = 0  # turn off sequencer

        # Initialize ADC after  power up by sending ones for two cycles.
        self.spi.write([0xff, 0xff])
        self.spi.write([0xff, 0xff])
コード例 #3
0
ファイル: usb_to_gpio.py プロジェクト: tslator/ArloBot
    def __init__(self):
        """
        Implements the Borg pattern which provides shared state among multiple objects
        """

        self.__dict__ = self.__shared_state

        try:
            # Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
            FT232H.use_FT232H()
        except RuntimeError as rte:
            raise UsbToGpioError(rte)

        try:
            # Create an FT232H object that grabs the first available FT232H device found.
            self._ft232h = FT232H.FT232H()
        except RuntimeError as rte:
            raise UsbToGpioError(rte)

        # Create the I2C ADC devices
        try:
            # Create an I2C device at address ADS7828_ADDR_0
            self.ADCDevices.AddDevice(ADS7828(self._ft232h, self.__ADS7828_ADDR_0))

        except RuntimeError as rte:
            raise UsbToGpioError(rte)

        try:
            # Create an I2C device at address ADS7828_ADDR_1
            self.ADCDevices.AddDevice(ADS7828(self._ft232h, self.__ADS7828_ADDR_1))

        except RuntimeError as rte:
            raise UsbToGpioError(rte)
コード例 #4
0
def init_adafruit_ft232h():
    # Apply or remove the reset from the SPIROM daughterboard
    # via a GPIO on the AdaFruit FT232H SPI/I2C/UART/GPIO breakout board.
    global ft232h, adafruit_initialized

    if not adafruit_initialized:
        # Temporarily disable the built-in FTDI serial driver on Mac & Linux
        # platforms.
        FT232H.use_FT232H()

        # Create an FT232H object that grabs the first available FT232H device
        # found.
        ft232h = FT232H.FT232H()

        # The daughterboard reset line has a pull-up to 3v3. The "operate"
        # position of switch DW1.4 is "ON" which shorts it to ground (i.e.,
        # "Run" = Low, "Reset" = high). Even though the FT232H can nominally
        # drive the IO to 3v3, it would be better to instead simply tristate
        # the IO and let the pull-up do the work.
        # For initialization, we'll drive it low.
        ft232h.setup(SPIROM_RESET_GPIO, GPIO.OUT)

        ft232h.output(SPIROM_RESET_GPIO, GPIO.LOW)

        # Note that we're now initialized
        adafruit_initialized = True
コード例 #5
0
def init_adafruit_ft232h():
    # Apply or remove the reset from the SPIROM daughterboard
    # via a GPIO on the AdaFruit FT232H SPI/I2C/UART/GPIO breakout board.
    global ft232h, adafruit_initialized

    if not adafruit_initialized:
        # Temporarily disable the built-in FTDI serial driver on Mac & Linux
        # platforms.
        FT232H.use_FT232H()

        # Create an FT232H object that grabs the first available FT232H device
        # found.
        ft232h = FT232H.FT232H()

        # The daughterboard reset line has a pull-up to 3v3. The "operate"
        # position of switch DW1.4 is "ON" which shorts it to ground (i.e.,
        # "Run" = Low, "Reset" = high). Even though the FT232H can nominally
        # drive the IO to 3v3, it would be better to instead simply tristate
        # the IO and let the pull-up do the work.
        # For initialization, we'll drive it low.
        ft232h.setup(SPIROM_RESET_GPIO, GPIO.OUT)

        ft232h.output(SPIROM_RESET_GPIO, GPIO.LOW)

        # Note that we're now initialized
        adafruit_initialized = True
コード例 #6
0
 def __init__(self, n):
     # Create an FT232H object.
     self.ft232h = FT232H.FT232H()
     # Create a SPI interface for the FT232H object.  Set the SPI bus to 6mhz.
     self.spi = FT232H.SPI(self.ft232h, max_speed_hz=12800000)
     # Create a pixel data buffer and lookup table.
     self.buffer = bytearray(n * 24)
     self.lookup = self.build_byte_lookup()
コード例 #7
0
 def __init__(self, address=MAX2484_I2C_ADDR_DEFAULT, i2c=None, **kwargs):
     """initialize MAX2484 on the specified address, """
     self._logger = logging.getLogger('MAX2484')
     if i2c == None:
         import Adafruit_GPIO.FT232H as FT232H
         FT232H.use_FT232H()
         ft232h = FT232H.FT232H()
     self._device = FT232H.I2CDevice(ft232h, address, **kwargs)
     self.roms = []
コード例 #8
0
	def __init__(self, address=MCP4725_I2C_ADDR_DEFAULT, i2c=None, debug = False, **kwargs):
		"""initialize MCP4725 on the specified address, """
		self._logger = logging.getLogger('MCP4725')
		if i2c == None:
			import Adafruit_GPIO.FT232H as FT232H
			FT232H.use_FT232H()
			ft232h = FT232H.FT232H()
		self._device = FT232H.I2CDevice(ft232h, address, **kwargs)
		self.address = address
		self.debug = debug
コード例 #9
0
 def __init__(self):
     FT232H.use_FT232H()
     self.ft232h = FT232H.FT232H()
     self.spiClockFreqInHz = 1000000
     self.chipSelectPinOnFt232h = 8
     self.spiMode = 0
     self.spi = FT232H.SPI(self.ft232h,
                           cs=self.chipSelectPinOnFt232h,
                           max_speed_hz=self.spiClockFreqInHz,
                           mode=self.spiMode,
                           bitorder=FT232H.MSBFIRST)
     self.__rawToDegreeConvertionRatio = 360.0 / 65536.0
コード例 #10
0
 def __init__(self, num_pixels, num_rows):
     # Create an FT232H object.
     self.ft232h = FT232H.FT232H()
     # Create a SPI interface for the FT232H object.  Set the SPI bus to 6mhz.
     self.spi = FT232H.SPI(self.ft232h, max_speed_hz=SPI_BAUD)
     # Create a pixel data buffer and lookup table.
     self.buffer = bytearray(num_pixels * BYTES_PER_PIXEL * 3)
     self.lookup = self.build_byte_lookup()
     #print self.lookup
     self.set_brightness(25)  #set brightness to 25% by default
     self.num_pixels = num_pixels
     self.rows = num_rows
     self.cols = num_pixels / num_rows
コード例 #11
0
	def FTDI_setup(self):
                	try:
				if(self.ft232h):
					print("[*] FTDI Drivers already enabled ")
				else:
	                               	self.statusbar.showMessage("    Badge  | Setting up FTDI drivers ",1000)
					print("[*] Enabling Adafruit FTDI ")
                        		FT232H.use_FT232H()
                        		self.ft232h = FT232H.FT232H()

			except Exception as e:
                                self.statusbar.showMessage("    Badge  | FTDI driver setup failed ",1000)
                                print("[*] Error : "+str(e))
コード例 #12
0
ファイル: util.py プロジェクト: zrna-research/zrna-api
 def _get_connection(self, connection_type, device_path):
     if connection_type == 'usb_serial':
         if device_path is not None:
             return serial.Serial(device_path)
     elif sys.argv[1] == 'uart':
         # FT232H, D0 <-> PA9, USART1_TX
         # FT232H, D1 <-> PA10, USART1_RX
         return serial.Serial('/dev/ttyUSB0', baudrate=115200)
     elif FT232H_ENABLED and sys.argv[1] == 'spi':
         FT232H.use_FT232H()
         self.ft232h = FT232H.FT232H()
         # FT232H, D0 <-> PB13, SCK
         # FT232H, D1 <-> PB15, MOSI
         # FT232H, D2 <-> PB14, MISO
         # FT232H, C8 <-> PB12, NSS
         return FT232H.SPI(self.ft232h,
                           cs=8,
                           max_speed_hz=1000000,
                           mode=0,
                           bitorder=FT232H.MSBFIRST)
     elif FT232H_ENABLED and sys.argv[1] == 'i2c':
         # FT232H, D0, pullup <-> PB10, I2C2_SCL
         # FT232H, D1 + D2 tied together, pullup <-> PB9, I2C2_SDA
         FT232H.use_FT232H()
         self.ft232h = FT232H.FT232H()
         return FT232H.I2CDevice(self.ft232h, 0x15)
コード例 #13
0
 def __init__(self, slave_addr=0x68):
     FT232H.use_FT232H()
     self.ft232h = FT232H.FT232H()
     self.init_gpio()
     self.i2c = FT232H.I2CDevice(self.ft232h, slave_addr)
     self.time_value = {
         'sec': 0,
         'min': 0,
         'hour': 0,
         '12hour': False,
         'AM': False,
         'date': 0,
         'weekday': 1,
         'month': 1,
         'year': 2000
     }
コード例 #14
0
def init_imu():
    #check if the Accel/Mag is there
    #-set i2c to point at accelerometer & Mag
    i2c = FT232H.I2CDevice(ft232h, XM.ADDRESS)
    check = i2c.readU8(XM.WHO_AM_I)
    if check != XM.WHO_AM_I_OK:
        print "ACCEL INIT FAIL..."
        return 1
    #check if the GYRO is there
    #-set i2c to point at XM
    i2c = FT232H.I2CDevice(ft232h, GYRO.ADDRESS)
    check = i2c.readU8(GYRO.WHO_AM_I)
    if check != GYRO.WHO_AM_I_OK:
        print "GYRO INIT FAIL..."
        return 1
    #success!
    return 0
コード例 #15
0
ファイル: util.py プロジェクト: zrna-research/zrna-api
def i2c_scan():
    if FT232H_ENABLED:
        for address in range(127):
            if address <= 7 or address >= 120:
                continue
            i2c = FT232H.I2CDevice(ft232h, address)
            if i2c.ping():
                print('Found I2C device at address 0x{0:02X}'.format(address))
コード例 #16
0
ファイル: ft232h.py プロジェクト: Bones-74/radial-sockets
    def __init__(self, bname, bport, num_channels):
        super(ada_ft232h, self).__init__(bname, bport, num_channels)

        #FT232H.enumerate_device_serials()

        # Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms.
        FT232H.use_FT232H()

        # Create an FT232H object that grabs the first available FT232H device found.
        self.ft232h = FT232H.FT232H()

        self.channel_dirs = dict()
        self.channel_sense = dict()
        self.channel_configured = dict()

        # initialise all gpio as inputs first of all
        for pin in range(0, 16):
            self.ft232h.setup(pin, GPIO.IN)  # Make pin a digital input
コード例 #17
0
    def __init__(self, i2cBus, address=SHT_ADDR):
        self.address = address

        # Initialise the I2C instance for the sensor -
        # default is first FT232H instance but when muxing will be different
        self._device = ft.I2CDevice(i2cBus, address)
        time.sleep(0.002)
        if not (self._device.ping()):
            print("Problem accessing device at " + hex(address))
コード例 #18
0
ファイル: mcp2515.py プロジェクト: rgeyer/ft232h
 def __init__(self, ft232h, cs_pin=3):
     # Mode is defaulted to 0, and bit order to MSBFIRST
     ft232h.setup(cs_pin, GPIO.OUT)
     self._ft232h = ft232h
     self._cs = cs_pin
     # 450kHz was too slow for retrieval of rx buffers, 2Mhz worked, bumped
     # it to twice that for funsies.. Then realized that 10Mhz is the max,
     # so let's do that!
     self._spi = FT232H.SPI(ft232h, max_speed_hz=10000000)
コード例 #19
0
def configGyro(fullScale="245DPS"):
    i2c = FT232H.I2CDevice(ft232h, GYRO.ADDRESS)
    i2c.write8(GYRO.CTRL_REG1_G, 0x0F)  #normal mode, all axes
    #set gyro scale
    scaleVal = GYRO.RANGE_G[fullScale]
    regVal = 0x00 | scaleVal
    i2c.write8(GYRO.CTRL_REG4_G, regVal)
    print regVal
    return 0
コード例 #20
0
def configAccel(rate="100HZ", fullScale="2G"):
    #-set i2c to point at accelerometer & Mag
    i2c = FT232H.I2CDevice(ft232h, XM.ADDRESS)
    #set accel data to 100Hz and enable all axes
    i2c.write8(XM.CTRL_REG1_XM, 0b01101111)  #0x67) #0b01010111)  #0b01100111)
    #set the accel scale
    scaleVal = XM.RANGE_A[fullScale]
    regVal = 0x00 | scaleVal
    i2c.write8(XM.CTRL_REG2_XM, regVal)
    return 0
コード例 #21
0
 def run(self):
     for address in range(127):
         if address <= 7 or address >= 120:
             continue
         i2c = FT232H.I2CDevice(self.ft232h, address)
         if i2c.ping():
             self.count = self.count + 1
             self.emit(SIGNAL('I2c_device_found(int)'), address)
     self.emit(SIGNAL('I2c_device_found(int)'), self.count + 1000)
     print("[*] Terminating I2C Scanner Thread ")
     self.terminate()
コード例 #22
0
ファイル: MPU9250.py プロジェクト: samuelbsoares/RippleDrive
    def __init__(self, address=None, ft232h=None):
        """
        Initializes address, bus, and ft232h/i2c devices
        """

        ##### CHECK FOR POSSIBLE EXCEPTIONS/ERRORS IN FUNCTIONS BELLOW
        # Temporarily disables FTDI serial drivers.
        FT232H.use_FT232H()

        # Initializes the address if not provided
        if not address: address = self.DEFAULT_I2C_ADDRESS
        self.__address = address

        # Finds the first FT232H device.
        if not ft232h:
            self.__ft232h = FT232H.FT232H()

        # Gets I2C instance from provided FT232H object
        self.__bus = self.__ft232h.get_i2c_device(self.__address)

        self.__bus.write8(PWR_MGMT_1, WAKE)
コード例 #23
0
def configMag(rate="100HZ", fullScale="4GAUSS"):
    #-set i2c to point at accelerometer & Mag
    i2c = FT232H.I2CDevice(ft232h, XM.ADDRESS)
    #set magnetometer to 100Hz
    i2c.write8(XM.CTRL_REG5_XM, 0xF4)
    #Range 4GAUSS
    i2c.write8(XM.CTRL_REG6_XM, 0x20)
    i2c.write8(XM.CTRL_REG7_XM, 0x00)
    #set the accel scale
    scaleVal = XM.RANGE_M[fullScale]
    regVal = 0x00 | scaleVal
    i2c.write8(XM.CTRL_REG2_XM, 0x00)
    return 0
コード例 #24
0
ファイル: girodicer.py プロジェクト: lasoren/ice-dam-drone
    def __init__(self, connection, baud, queue, debug=False):
        self.debug = debug
        self.eventQueue = queue
        self.eventQueue.addEventCallback(self.__roof_scan,EventHandler.SCAN_BORDER_FINISHED)
        print "Initializing vehicle"
        self.vehicle = connect(connection, baud=baud, wait_ready=True)
        self.vehicle.airspeed = self.flying_velocity
        self.vehicle.add_attribute_listener('battery', self.__battery_callback)
        print "Initializing lidar"
        FT232H.use_FT232H()
        self.ft232h = FT232H.FT232H()
        self.bus = FT232H.I2CDevice(self.ft232h, lidar.Lidar.DEF_ADDR)
        self.lidar = lidar.Lidar(self.bus)
        if not debug:
            print "Initializing bluetooth"
            self.blue = blue.Blue(self.eventQueue)
        else:
            print "Debug Mode On, No Bluetooth Running"
            self.blue = blue.Blue(self.eventQueue, debug)

        self.ft232h.setup(self.motor_pin, GPIO.OUT)
        self.ft232h.output(self.motor_pin, GPIO.LOW)
コード例 #25
0
	def __init__(self, num_pixels, num_rows):
		# Create a libftdi context.
		ctx = None
		ctx = ftdi.new()
		# Define USB vendor and product ID
		vid = 0x0403
		pid = 0x6014
		# Enumerate FTDI devices.
		self.serial = None
		device_list = None
		count, device_list = ftdi.usb_find_all(ctx, vid, pid)
		while device_list is not None:
			# Get USB device strings and add serial to list of devices.
			ret, manufacturer, description, serial = ftdi.usb_get_strings(ctx, device_list.dev, 256, 256, 256)
			print 'return: {0}, manufacturer: {1}, description: {2}, serial: |{3}|'.format(ret,manufacturer,description,serial)
			if 'FTDI' in manufacturer and 'Serial' in description and 'FT' in serial:
				self.serial = serial
			device_list = device_list.next
		# Make sure to clean up list and context when done.
		if device_list is not None:
			ftdi.list_free(device_list)
		if ctx is not None:
			ftdi.free(ctx)	
		
		# Create an FT232H object.
		self.ft232h = FT232H.FT232H(serial=self.serial)
		# Create an FT232H object.
		self.ft232h = FT232H.FT232H()
		# Create a SPI interface for the FT232H object.  Set the SPI bus to 6mhz.
		self.spi    = FT232H.SPI(self.ft232h, max_speed_hz=SPI_BAUD)
		# Create a pixel data buffer and lookup table.
		self.buffer = bytearray(num_pixels*BYTES_PER_PIXEL*3)
		self.lookup = self.build_byte_lookup()
		#print self.lookup
		self.set_brightness(MAX_INTENSITY/2) #set brightness to 25% by default
		self.num_pixels	= num_pixels
		self.rows 		= num_rows
		self.cols 		= num_pixels/num_rows
コード例 #26
0
ファイル: LoRa_main.py プロジェクト: njoubert/MaraudersMap
def main():
  log_to_stdout()

  FT232H.use_FT232H()
  ft232h = FT232H.FT232H()

  # Create a SPI interface from the FT232H using pin 8 (C0) as chip select.
  # Use a clock speed of 3mhz, SPI mode 0, and most significant bit first.
  spi = FT232H.SPI(ft232h, cs=8, max_speed_hz=3000000, mode=0, bitorder=FT232H.MSBFIRST)


  radio = LoRa(spi=spi, verbose=False)
  radio.set_freq(915)

  print radio

  a = raw_input("Transmit [T], Ping [P] or Receive [R]? ")

  if a == "P":
    try:
      while True:
        msg = "Ping: " + time.asctime()
        print msg
        transmit(radio, msg)
        time.sleep(1)
    except KeyboardInterrupt:
      pass
  elif a == "T":
    try:
      while True:
        msg = raw_input("Message:")
        transmit(radio, msg=msg)
    except KeyboardInterrupt:
      pass
  elif a == "R":
    receive_loop(radio)
  else:
    print "Unknown command:", a
コード例 #27
0
def getAccel(fullScale):
    i2c = FT232H.I2CDevice(ft232h, XM.ADDRESS)
    cal = XM.CAL_A[fullScale]
    ax_L = i2c.readU8(0x28)
    ax_H = i2c.readU8(0x29)
    ay_L = i2c.readU8(0x2A)
    ay_H = i2c.readU8(0x2B)
    az_L = i2c.readU8(0x2C)
    az_H = i2c.readU8(0x2D)

    ax = np.int16(ax_L | (ax_H << 8)) * cal
    ay = np.int16(ay_L | (ay_H << 8)) * cal
    az = np.int16(az_L | (az_H << 8)) * cal
    return (ax, ay, az)
コード例 #28
0
def getMag(fullScale):
    i2c = FT232H.I2CDevice(ft232h, XM.ADDRESS)
    cal = XM.CAL_M[fullScale]
    mx_L = i2c.readU8(0x08)
    mx_H = i2c.readU8(0x09)
    my_L = i2c.readU8(0x0A)
    my_H = i2c.readU8(0x0B)
    mz_L = i2c.readU8(0x0C)
    mz_H = i2c.readU8(0x0D)

    mx = np.int16(mx_L | (mx_H << 8)) * cal
    my = np.int16(my_L | (my_H << 8)) * cal
    mz = np.int16(mz_L | (mz_H << 8)) * cal
    return (mx, my, mz)
コード例 #29
0
def getRotation(fullScale):
    i2c = FT232H.I2CDevice(ft232h, GYRO.ADDRESS)
    cal = GYRO.CAL_G[fullScale]
    gx_L = i2c.readU8(0x28)
    gx_H = i2c.readU8(0x29)
    gy_L = i2c.readU8(0x2A)
    gy_H = i2c.readU8(0x2B)
    gz_L = i2c.readU8(0x2C)
    gz_H = i2c.readU8(0x2D)

    gx = np.int16(gx_L | (gx_H << 8)) * cal
    gy = np.int16(gy_L | (gy_H << 8)) * cal
    gz = np.int16(gz_L | (gz_H << 8)) * cal
    return (gx, gy, gz)
コード例 #30
0
ファイル: switch.py プロジェクト: kanyikanyingi/USB-switch
def switch(mode):
    #  FT232H.use_FT232H()

    ft232h = FT232H.FT232H()

    ft232h.setup(8, GPIO.IN)
    ft232h.setup(9, GPIO.OUT)
    ft232h.output(9, GPIO.HIGH)
    ft232h.setup(10, GPIO.OUT)
    ft232h.output(10, GPIO.LOW)

    if mode == "toggle":
        do_toggle(ft232h)
    else:
        do_clear(ft232h)
        if mode == "run":
            do_toggle(ft232h)
コード例 #31
0
ファイル: tester_v2.py プロジェクト: yazici/lmarv
    def __init__(self, serial_no=None):
        """Constructor.

    Args:
      serial_no: str. The serial number of the FTDI adapter.
    """

        # Temporarily disable FTDI serial drivers.
        FT232H.use_FT232H()

        # Find the first FT232H device.
        self.ft232h_ = FT232H.FT232H(serial=serial_no)

        # GPIO pin assignment.
        self.ft232h_.setup(self.OUTPUT_ENABLE_PIN, GPIO.OUT)
        self.ft232h_.setup(self.RESET_PIN, GPIO.OUT)

        self.Reset()

        # Create I2C devices for PCA9698.
        self.i2c0_ = FT232H.I2CDevice(self.ft232h_, 0x20)
        self.i2c1_ = FT232H.I2CDevice(self.ft232h_, 0x21)
        self.i2c2_ = FT232H.I2CDevice(self.ft232h_, 0x22)
        self.i2c3_ = FT232H.I2CDevice(self.ft232h_, 0x26)
        self.i2c_ = [self.i2c0_, self.i2c1_, self.i2c2_, self.i2c3_]

        self.booted = False

        # Set output pins
        self.i2c0_.write8(self.REG_IOC0, 0x00)  # rs1[7:0]
        self.i2c0_.write8(self.REG_IOC1, 0x00)  # rs1[15:8]
        self.i2c2_.write8(self.REG_IOC0, 0x00)  # rs1[23:16]
        self.i2c2_.write8(self.REG_IOC1, 0x00)  # rs1[31:24]
        self.i2c1_.write8(self.REG_IOC0, 0x00)  # rs2[7:0]
        self.i2c1_.write8(self.REG_IOC1, 0x00)  # rs2[15:8]
        self.i2c3_.write8(self.REG_IOC0, 0x00)  # rs2[23:16]
        self.i2c3_.write8(self.REG_IOC1, 0x00)  # rs2[31:24]

        # Set function pins.
        self.i2c1_.write8(self.REG_IOC4, 0xf0)  # f[3:0]
コード例 #32
0
ファイル: i2c_scan.py プロジェクト: youcantsee/smart_line
import Adafruit_GPIO.FT232H as FT232H
from Adafruit_GPIO import GPIO

# Temporarily disable FTDI serial drivers.
FT232H.use_FT232H()

# Find the first FT232H device.
ft232h = FT232H.FT232H()

ft232h.setup(12, GPIO.OUT)
ft232h.setup(13, GPIO.OUT)
ft232h.setup(14, GPIO.OUT)
ft232h.setup(15, GPIO.OUT)

ft232h.output(12, GPIO.HIGH)
ft232h.output(14, GPIO.HIGH)
ft232h.output(13, GPIO.LOW)
ft232h.output(15, GPIO.HIGH)

print 'Scanning all I2C bus addresses...'
# Enumerate all I2C addresses.
for address in range(127):
    # Skip I2C addresses which are reserved.
    if address <= 7 or address >= 120:
        continue
    # Create I2C object.
    i2c = FT232H.I2CDevice(ft232h, address)
    # Check if a device responds to this address.
    if i2c.ping():
        print 'Found I2C device at address 0x{0:02X}'.format(address)
print 'Done!'
コード例 #33
0
ファイル: gpio_work_stop.py プロジェクト: ZH8000/FlyCamera
#!/usr/bin/python

# Import standard Python time library.
import time

# Import GPIO and FT232H modules.
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H

# Temporarily disable the built-in FTDI serial driver on Mac &amp; Linux platforms.
FT232H.use_FT232H()

# Create an FT232H object that grabs the first available FT232H device found.
ft232h = FT232H.FT232H()

# Configure digital inputs and outputs using the setup function.
# Note that pin numbers 0 to 15 map to pins D0 to D7 then C0 to C7 on the board.
ft232h.setup(7, GPIO.IN)  # Make pin D7 a digital input.
ft232h.setup(8, GPIO.OUT)  # Make pin C0 a digital output.
ft232h.setup(11, GPIO.OUT)  # Make pin C3 a digital output.

# Loop turning the LED on and off and reading the input state.
print 'Press Ctrl-C to quit.'
while True:
    # Set pin C0 to a high level so the LED turns on.
    #ft232h.output(11, GPIO.HIGH)
    # Sleep for 1 second.
    #time.sleep(3)
    # Read the input on pin D7 and print out if it's high or low.
    #level = ft232h.input(7)
    #if level == GPIO.LOW:
コード例 #34
0
import time
import math
from collections import namedtuple
import struct
import Adafruit_GPIO.FT232H as FT232H
import Adafruit_GPIO as GPIO
from micropython import const
import lis3dh_deplib

FT232H.use_FT232H()
ft232h = FT232H.FT232H(serial='black')
address = 0x18
lis3dh = lis3dh_deplib.LIS3DH_I2C(ft232h, address)
lis3dh.range = lis3dh_deplib.RANGE_2_G
lis3dh.data_rate = lis3dh_deplib.DATARATE_1344_HZ
while True:
    x, y, z = [
        value / lis3dh_deplib.STANDARD_GRAVITY
        for value in lis3dh.acceleration()
    ]
    print("x = %0.3f G, y = %0.3f G, z = %0.3f G" % (x, y, z))
    time.sleep(0.1)