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)
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])
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
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()
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 = []
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
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
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))
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
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
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 }
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)
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
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)
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]
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
#!/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 & 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:
def __init__(self, slave_addr=0x27): FT232H.use_FT232H() self.ft232h = FT232H.FT232H() self.init_gpio() self.i2c = FT232H.I2CDevice(self.ft232h, slave_addr) self.lcd_init()
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)
def __init__(self, slave_addr=0x50): FT232H.use_FT232H() self.ft232h = FT232H.FT232H() self.init_gpio() self.i2c = MyI2C(self.ft232h, slave_addr)
def __init__(self): ## In the init function, we create variables, create action servers ## create publishers and initialize SPI communication ### Initialize and create SPI ### # Uncomment the following graph if you are using real hardware # Temporarily disable FTDI serial drivers. FT232H.use_FT232H() # Find the first FT232H device. # the device has to be attached to /dev/ttyUSB0 in Linux 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) self.spi = spi ### Define and initialize ROS action servers and ROS topic publishers ### # define arm action server, of type FollowJointTrajectoryAction # using a callback function of execute_cb_arm # communicating in the namespace of /arm_controller/follow_joint_trajectory # notice this namespace cannot be changed, because its being determined # by MoveIt, as can be seen here: http://docs.ros.org/kinetic/api/moveit_tutorials/html/doc/controller_configuration/controller_configuration_tutorial.html self._as_arm = actionlib.SimpleActionServer( '/arm_controller/follow_joint_trajectory', FollowJointTrajectoryAction, execute_cb=self.execute_cb_arm, auto_start=False) self._as_arm.start() # define hand action server, of type GripperCommandAction # using a callback function of self.execute_cb_hand # communicating in the namespace of /hand_controller/gripper_action # notice this namespace cannot be changed, because its being determined # by MoveIt, as can be seen here: http://docs.ros.org/kinetic/api/moveit_tutorials/html/doc/controller_configuration/controller_configuration_tutorial.html self._as_hand = actionlib.SimpleActionServer( '/hand_controller/gripper_action', GripperCommandAction, execute_cb=self.execute_cb_hand, auto_start=False) self._as_hand.start() ### declare some variables that are stored in this class ### # joint_names defined in the URDF file, in the order of from # joint 1 to joint 6 self.joint_names = [ 'link_1_a_to_base', 'link_2_to_link_1', 'link_3_to_link_2', 'link_4_to_link_3', 'link_4_c_to_b', 'finger_1_to_link_5' ] # during initialization, all jointStates are set to 0, the defalt position # the corresponding PWMs are all 1500us. self.jointStates = [0, 0, 0, 0, 0, 0] self.jointPWMs = [1500, 1500, 1500, 1500, 1500, 1500] self.k = [ -1300.0 / pi, -1400.0 / pi, 1350.0 / pi, 1350.0 / pi, 1350.0 / pi, 1100.0 / pi ] self.b = [1450, 1500, 1475, 1525, 1525, 1350] # we then send the initialization default PWMs to SPI to drive # the robotic arm. Uncomment this if you are using real hardware. self.spi_send_PWM() ### define joint state publisher ### # since our robot servos move to the exact joint angles as what # they told to, so our joint state publisher just echo the goal # that is being sent from MoveIt self.pub_PWM = rospy.Publisher( '/summer_robotic_arm/jointPWMs', JointState, queue_size=10 ) ## we use ros's built-in joint state message type for our jointPWMs self.joint_PWM_msg = JointState() self.joint_PWM_msg.name = self.joint_names self.joint_PWM_msg.position = self.jointPWMs self.pub_PWM.publish(self.joint_PWM_msg) ''' self.pub_state = rospy.Publisher('/summer_robotic_arm/jointStates', JointState, queue_size=10) ## we use ros's built-in joint state message type for our jointPWMs ''' # notice that the name space /joint_states namespace also controls # the rViz visualization, which makes our simulation the same # as the real robot self.pub_state = rospy.Publisher( '/joint_states', JointState, queue_size=10 ) ## we use ros's built-in joint state message type for our jointPWMs self.joint_state_msg = JointState() self.joint_state_msg.name = self.joint_names self.joint_state_msg.header.stamp = rospy.Time.now() self.joint_state_msg.position = self.jointStates self.pub_state.publish(self.joint_state_msg)
# Import standard Python time library. import time # Import GPIO and FT232H modules. import Adafruit_GPIO as GPIO import Adafruit_GPIO.FT232H as FT232H print "A" # Temporarily disable the built-in FTDI serial driver on Mac & Linux platforms. FT232H.use_FT232H() print "B" # Create an FT232H object that grabs the first available FT232H device found. ft232h = FT232H.FT232H(0x263d, 0x4001) dir = { 0: GPIO.OUT, 1: GPIO.OUT, 2: GPIO.OUT, 3: GPIO.OUT, 4: GPIO.OUT, 5: GPIO.OUT, 6: GPIO.OUT, 7: GPIO.OUT, } val0 = { 0: 0, 1: 0,
humid_setpoint = int(hum_sp) logging.info("Humidity period set to " + str(humidity_period) + " seconds") humchan_list = [ 2, 4, ] print("Attempt to access sensors on multiplexor channels " + str(humchan_list) + " - change code to update") hum_filename = today.isoformat() + "/HumiditySensorOutput_" + runNum + ".txt" recflag = 0 # Initialise I2C bus ft.use_FT232H() ft_I2C = ft.FT232H() # Set up TCA device instance tca = ft_TCA.TCA9548A(ft_I2C, 0x70) # Set up humidity controller pins control_pin = 8 ft_I2C.setup(control_pin, GPIO.OUT) # Check relay operation, NO/NC status and pulse order ft_I2C.output(control_pin, GPIO.LOW) humFlag = False with pyrs.Service() as serv: with serv.Device() as dev:
# encoding:utf-8 from __future__ import absolute_import, division, print_function, with_statement from Adafruit_GPIO import GPIO from Adafruit_GPIO import FT232H from time import sleep FT232H.use_FT232H() ft232 = FT232H.FT232H() ft232.setup(12, GPIO.OUT) ft232.setup(13, GPIO.OUT) ft232.setup(14, GPIO.OUT) ft232.setup(15, GPIO.OUT) while True: ft232.output(12, GPIO.LOW) ft232.output(13, GPIO.LOW) ft232.output(14, GPIO.LOW) ft232.output(15, GPIO.LOW) sleep(3) ft232.output(12, GPIO.HIGH) ft232.output(13, GPIO.HIGH) ft232.output(14, GPIO.HIGH) ft232.output(15, GPIO.HIGH) sleep(3)
def __init__(self, n): self.ft232h = FT232H.FT232H() self.spi = FT232H.SPI(self.ft232h, max_speed_hz=8000000) self.buffer = bytearray(n * 24) self.lookup = self.build_byte_lookup()
MAX2484_REG_READ_DATA = 0xE1 MAX2484_REG_PORT_CONFIG = 0xB4 #configuration values for device configuration DEV_CONFIG_1WS = 0x08 DEV_CONFIG_SPU = 0x04 DEV_CONFIG_PDN = 0x02 DEV_CONFIG_APU = 0x01 #configuration values for port configuration PORT_CONFIG_1 = 0x0 import Adafruit_GPIO.FT232H as FT232H FT232H.use_FT232H() ft232H = FT232H.FT232H() class MAX2484(object): """class to represent a MAX2484 i2c to 1 wire bridge chip """ 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 = [] def begin(self):