def __init__(self, bus, cs_pin, slave_select_pin, reset_pin): print('setting up dspin interface on pins: ', bus, cs_pin, slave_select_pin, reset_pin) Dspin_motor.init_toggle_reset_pin(reset_pin) self.reset_gpio = LED(reset_pin) self.reset_gpio.on() time.sleep(0.1) self.reset_gpio.off() time.sleep(0.1) self.reset_gpio.on() time.sleep(0.1) self.slave_select_gpio = LED(slave_select_pin) self.spi = SpiDev() self.slave_select_gpio.on() self.spi.open(bus, cs_pin) self.spi.max_speed_hz = 10000 self.spi.mode = 3 self.spi.lsbfirst = False #spi.no_cs = True #spi.loop = False self.connect_l6470() self.last_steps_count_time = datetime.datetime.now() self.current_speed = 0 self.absolute_pos_manual_count = 0
def __init__(self, bus = 0, device = 0): self.bus, self.device = bus, device self.spi = SpiDev() self.open() self.spi.max_speed_hz = 1000000 # 1MHz self.myLogger = MyLogger(self.__class__.__name__) self.myLogger.info('Init MCP3008')
def __init__(self, dev): self.dev = SpiDev() try: self.dev.open(4, dev) except IOError as e: print("Error opening /dev/spidev4.%d: %s" % (dev, e)) raise
def __init__(self, address, direction, bitrate=976000, theta_max=0.15): """ Initialize and open an SPI connection with a CUI AMT20 encoder. :param bus: SPI address in the bus (e.g. 0 or 1). :type bus: int :param direction: Direction of rotation of the encoder, must be either 'ccw' or 'cw'. :type direction: string :param bitrate: Frequency of the SPI bus. The encoder defaults to 976[kHz]. :type bitrate: int :param theta_max: Max angle variation between samples, in radians. Defaults to 0.15[rad/sample]. :type theta_max: float """ assert address == 0 or address == 1, "SPI address must be 0 or 1" assert direction == "ccw" or direction == "cw", "Direction must be either 'ccw' or 'cw'" self.RESOLUTION = 4096 self.direction = direction self.theta_max = theta_max self.encoder = SpiDev() self.encoder.open(0, address) self.encoder.max_speed_hz = bitrate self._warm_up() self.last = {"angle": self.angle(), "time": datetime.now()}
def setup(keymap=FULL): global _is_setup, spi, callbacks, pins, leds, buf, states if _is_setup: return _is_setup = True callbacks = [None for key in keymap] pins = [key[0] for key in keymap] leds = [key[1] for key in keymap] buf = [[0, 0, 0, 1.0] for key in keymap] states = [True for key in keymap] GPIO.setmode(GPIO.BCM) GPIO.setup(pins, GPIO.IN, pull_up_down=GPIO.PUD_UP) for pin in pins: GPIO.add_event_detect(pin, GPIO.BOTH, callback=_handle_keypress, bouncetime=1) spi = SpiDev() spi.open(0, 0) spi.max_speed_hz = 1000000 atexit.register(_on_exit)
def _open(self): if not self._spi: self._spi = SpiDev() try: self._spi.open(self.bus, self.dev) except FileNotFoundError: raise SPIError(self.bus, self.dev) self._spi.max_speed_hz = self.freq
def __init__(self): self.__spi = SpiDev() self.__spi.open(0, 0) self.__sensors = [] self.__thread = Thread(target=self.__run, daemon=True) self.__stop = Event() self.__lock = Lock() self.__thread.start()
def __init__(self, bus=0, device=0): """ Initialize SPI device :param bus: SPI bus (usually 0) :param device: SPI slave (SS/CS/CE) """ self.spi = SpiDev() ...
def open(self): """Open an SPI connection to a slave""" self._spi_port = SpiDev() self._spi_port.open(0, 0) self._spi_port.max_speed_hz = int(3E6) self._spi_port.mode = 0b00 GPIO.setup(self.DC_PIN, GPIO.OUT) GPIO.setup(self.RESET_PIN, GPIO.OUT) GPIO.setup(self.BUSY_PIN, GPIO.IN)
def __init__(self, bus=0, device=0): """initializes the SPI bus for the ADS1293 """ self.bus, self.device = bus, device self.spi = SpiDev() self.open() self.inax_max = [0, 0, 0] self.inax_min = [0, 0, 0] self.inax_zero = [0, 0, 0]
def __init__(self, bus=0, device=0): """ Initialize SPI device for MCP3008 :param bus: SPI bus (usually 0) :param device: SPI slave (SS/CS/CE) """ self.spi = SpiDev() self.spi.open(bus, device) self.spi.max_speed_hz = 100000
def __init__(self, port, device): self._port = port self._device = device self._interface = None if SpiDev is None: raise ImportError('failed to import spidev') self._interface = SpiDev() self._interface.open(port, device) self._interface.max_speed_hz = 1000000
def setup_spi(): logger.debug("SPI setup") spi = SpiDev() spi.open(bus=0, device=0) spi.max_speed_hz = 1000000 spi.bits_per_word = 8 spi.loop = False spi.mode = 3 spi.no_cs = True return spi
def __init__(self, device=0, bits=None): if bits is None: raise InputDeviceError('you must specify the bit resolution of the device') if device not in (0, 1): raise InputDeviceError('device must be 0 or 1') self._device = device self._bits = bits self._spi = SpiDev() self._spi.open(0, self.device) super(AnalogInputDevice, self).__init__()
def __init__(self, spinum, sipmpins, chippins): self.spi = SpiDev(spinum, 0) self.spi.mode = 3 self.spi.max_speed_hz = 1000000 self.sipmpins = ['P9_%i' % num for num in sipmpins] self.chippins = ['P9_%i' % num for num in chippins] for pin in self.sipmpins + self.chippins: GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.LOW)
def _setup_spi(self): if self.spi is None: from spidev import SpiDev self.spi = SpiDev() self.spi.open(0, 1) self.spi.max_speed_hz = 9600 self.spi.mode = 0b00 self.spi.bits_per_word = 8 self.spi.cshigh = True self.spi.lsbfirst = False
def __init__(self, DO_DIRECTION_PIN, DO_RESET_PIN, DI_FAULT_PIN, ARGS): self.REG = { # AMIS-30543 Registers 'WR': 0x00, 'CR0': 0x01, 'CR1': 0x02, 'CR2': 0x03, 'CR3': 0x09, 'SR0': 0x04, 'SR1': 0x05, 'SR2': 0x06, 'SR3': 0x07, 'SR4': 0x0A } self.CMD = { # AMIS-30543 Command constants 'READ': 0x00, 'WRITE': 0x80 } self.dirctrl = ARGS[0] self.pwmf = ARGS[1] self.pwmj = ARGS[2] self.sm = ARGS[3] self.mult = ARGS[4] self.dist = ARGS[5] self.step = ARGS[6] self.VAL = { 'WR': 0b00000000, # no watchdog 'CR0': 0b00010111 | self.sm, # & 2.7 A current limit 'CR1': 0b00000000 | self.dirctrl | self.pwmf | self.pwmj, # & step on rising edge & fast slopes 'CR2': 0b00000000, # motor off & no sleep & SLA gain @ 0.5 & SLA no transparent 'CR3': 0b00000000 #, # no extended step mode #'dist': self.dist, #'step': self.step } # InitGPIO PWM.setup(5, 0) # 5 us pulse_incr, 0 delay_hw PWM.init_channel(0, 3000) # DMA channel 0, 3000 us subcycle time self.DO_RESET = gpiozero.DigitalOutputDevice(DO_RESET_PIN) self.DO_DIRECTION = gpiozero.DigitalOutputDevice(DO_DIRECTION_PIN) self.DI_NO_FAULT = gpiozero.DigitalInputDevice(DI_FAULT_PIN) self.spi = SpiDev() self.spi.open(0, 0) self.spi.max_speed_hz = 1000000 self.RegisterSet()
def open(self): if self.__connection: return self.acquire_lock() self.__connection = SpiDev() self.__connection.open(self.__bus, self.__device) self.__connection.mode = self.__mode self.__connection.max_speed_hz = self.__max_speed
def __init__( self, bus=1, channel=0, device=1, ): """Define which SPI device is the A/D Converter on.""" self.bus = bus self.device = device self.channel = channel self.spi = SpiDev()
def __init__(self, device, ce, config): """ Args: device (int): the number of SPI device ce (int): the number of chip select of SPI device config (SPIConfig): """ self._device = device self._ce = ce self._config = config self._spi = SpiDev()
def __init__(self, bus=0, device=0, log=None): self.log = log self.console = None self.bus, self.device = bus, device try: self.spi = SpiDev() self.open() self.spi.max_speed_hz = 250000 # 250kHz except Exception as e1: self.LogErrorLine("Error in MPC308 init: " + str(e1)) self.FatalError( "Error on opening SPI device: enable SPI or install CT HAT")
def __init__(self, bus_num, device_num, max_speed_hz=DEFAULT_SPI_CLOCK_FREQUENCY, clock_polarity=DEFAULT_CLOCK_POLARITY, clock_phase=DEFAULT_CLOCK_PHASE): self.spi_instance = SpiDev() self.bus_num = bus_num self.device_num = device_num self.clk_speed = max_speed_hz self.clk_polarity = clock_polarity self.clk_phase = clock_phase
def __init__(self, factory, port, device): self._port = port self._device = device self._interface = None if SpiDev is None: raise ImportError('failed to import spidev') super(LocalPiHardwareSPI, self).__init__() pins = SPI_HARDWARE_PINS[port] self.pin_factory.reserve_pins(self, pins['clock'], pins['mosi'], pins['miso'], pins['select'][device]) self._interface = SpiDev() self._interface.open(port, device) self._interface.max_speed_hz = 500000
def handle_signal(sig, frame): """Deal with signals during Signal.""" ch0.close_spi() ch1.close_spi() ch7.close_spi() SpiDev().close() SOCK.close() os.remove(SOCKET_PATH) virtual_mouse.__exit__() virtual_touchscreen.__exit__() virtual_keyboard.__exit__() print("Input driver killed. Restart to handle HackPack.") sys.exit(-sig)
def __init__(self): AbstractSensor.__init__(self) self.measurements = { "O2": [-1, "%"], "O2voltage": [-1, "V"], } self._spi = SpiDev(0, 0) self._CS = gpiozero.DigitalOutputDevice(5, initial_value=True) #self._MISO = gpiozero.DigitalInputDevice(9) self._spi.open(0, 0) self._spi.max_speed_hz = 500 self._spi.no_cs = True self.generateCalibCurve()
def __init__(self, device=0, chipselect=0, debug=False): self.device = device self.chipselect = chipselect self.debug = debug try: try: # Initialize GPIOs GPIO.setmode(GPIO.BCM) # Use Broadcom numbers GPIO.setwarnings(False) GPIO.setup(self.GPIO_RESET, GPIO.OUT, initial=GPIO.LOW) GPIO.setup(self.GPIO_IRQ, GPIO.IN, pull_up_down=GPIO.PUD_OFF) GPIO.add_event_detect(self.GPIO_IRQ, GPIO.RISING) time.sleep(0.05) except RuntimeError as e: raise PhyError("Failed to initialize GPIOs: %s" %\ str(e)) # Initialize SPI try: self.spi = SpiDev() self.spi.open(device, chipselect) except IOError as e: raise PhyError("Failed to open SPI device %d.%d: %s" %\ (device, chipselect, str(e))) try: self.spi.mode = 0 self.spi.bits_per_word = 8 self.spi.cshigh = False self.spi.lsbfirst = False self.spi.max_speed_hz = 200000 except IOError as e: try: self.spi.close() self.spi = None except: pass raise PhyError("Failed to configure SPI device %d.%d: %s" %\ (device, chipselect, str(e))) # Get the controller out of hardware reset GPIO.output(self.GPIO_RESET, GPIO.HIGH) time.sleep(0.2) # Send a software reset self.sendReset() # Upload default config self.profibusSetPhyConfig() except: GPIO.cleanup() raise
def __init__(self, led_indexes): """ Create the LED controller. :param led_indexes: physical -> logical LED mapping: led_indexes[n] = LED number """ self.spi = SpiDev() self.spi.open(0, 0) self.spi.max_speed_hz = 1000000 self.pixels = [Pixel(n) for n in range(len(led_indexes))] self.mapping = led_indexes atexit.register(self._on_exit)
def __init__(self, bus=0, device=0): """ The constructor for the MCP3008 class. Arguments: bus (int): The number of the SPI bus that is used. device (int): The number of the client device that is used. """ self.bus, self.device = bus, device self.spi = SpiDev() self.spi.open(self.bus, self.device) # Necessary for Kernel 4.9 self.spi.max_speed_hz = 5000
def read_touch_screen(channel): """Read the HackPack touchscreen coordinates.""" spi = SpiDev() spi.open(1, 0) spi.no_cs = True spi.max_speed_hz = 2000000 # Manual chip select GPIO.output(CS_TOUCH, 1) GPIO.output(CS_TOUCH, 0) responseData = spi.xfer([channel, 0, 0]) GPIO.output(CS_TOUCH, 1) spi.close() return (responseData[1] << 5) | (responseData[2] >> 3)
def __init__(self, bus = 0, device = 0, pins = 24): self.bus = bus self.device = device self.spi = SpiDev() self.spi.open(bus, device) self.MAX = 0xfff self.MIN = 0x000 self.pins = pins self.light_values = [0 for _ in range(36)] self.send() self.scanning = 0 self.map = {0:1, 1:2, 2:4, 3:5, 4:7, 5:8, 6:10, 7:11, 8:13, 9:14, 10:16, 11:17, 12:19, 13:20, 14:22, 15:23, 16:25, 17:26, 18:28, 19:29, 20:31, 21:32, 22:34, 23:35} self.clear()