コード例 #1
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])
コード例 #2
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)
コード例 #3
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()
コード例 #4
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)
コード例 #5
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
コード例 #6
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
コード例 #7
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
コード例 #8
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
import time
import random
import Adafruit_GPIO as GPIO
import Adafruit_GPIO.FT232H as FT232H
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.
spi = FT232H.SPI(ft232h,
                 cs=3,
                 max_speed_hz=100000,
                 mode=0,
                 bitorder=FT232H.MSBFIRST)
# Write three bytes (0x01, 0x02, 0x03) out using the SPI protocol.

# generate from list of bytes, converting into string
'''import crc8
data = [0x00, 0x03, 0xe8, 0x91, 0x04]
hash = crc8.crc8()
hash.update("0x0491e80300")
print( hash.hexdigest() )'''


def bytes(integer):
    return divmod(integer, 0x100)


import crcmod.predefined
crc8 = crcmod.predefined.mkPredefinedCrcFun('crc-8-maxim')
print hex(crc8('\x04\x91\xe8\x03\x00'))
コード例 #10
0
    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)
コード例 #11
0
ファイル: shapes.py プロジェクト: SalvorinFex/raspi-testing
import Adafruit_Nokia_LCD as LCD
import Adafruit_FT232H as FT232H

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

# Temporarily disable FTDI serial drivers to use the FT232H device.
FT232H.use_FT232H()

# Create an FT232H device instance.
ft232h = FT232H.FT232H()

# Create an FT232H SPI object with the specified chip select pin.
ft232h_spi = FT232H.SPI(ft232h, cs=8)

# Create the Nokia display object.
disp = LCD.PCD8544(9, 10, spi=ft232h_spi, gpio=ft232h)

# The code below is exactly the same as the Nokia LCD library's shapes.py example:

# Initialize library.
disp.begin(contrast=60)

# Clear display.
disp.clear()
disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
コード例 #12
0
 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()
コード例 #13
0
ファイル: spi_sample.py プロジェクト: youcantsee/smart_line
# encoding:utf-8
from __future__ import absolute_import, division, print_function, with_statement
from Adafruit_GPIO import FT232H
from Adafruit_GPIO import GPIO

FT232H.use_FT232H()
ft232 = FT232H.FT232H()
ft232.setup(12, GPIO.OUT)
ft232.output(12, GPIO.LOW)

spi = FT232H.SPI(ft232, cs=3, mode=0, max_speed_hz=1000000)
spi.write([0x55])
print(spi.read(1))

with open('boot.hex', 'rb') as src:
    while True:
        data = src.read(2)
        if data == '':
            break
        hex_value = int(data, 16)
        i_list = [hex_value]
        spi.write(i_list)

print('write done')
コード例 #14
0
log.info('HERE WE GOOOO')

# Ensure that PIL is installed
import Image
import ImageDraw
import ImageFont

# 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.
spi = FT232H.SPI(ft232h, cs=8, mode=0, bitorder=FT232H.MSBFIRST)

# Initialize display
disp = SSD1306.SSD1306_128_64(9, 10, spi=spi, gpio=ft232h)

# Initialize library.
disp.begin()

# Clear display.
disp.clear()

disp.display()

# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
width = disp.width