def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): super(I2CThread, self).__init__(group=group, target=target, name=name) self._running = True self.args = args self.kwargs = kwargs self.queue = kwargs['queue'] print("I2CThread: initializing I2C") self.i2c = busio.I2C(board.SCL, board.SDA) print('I2CThread: Initializing I2C mux') self.tca = adafruit_tca9548a.TCA9548A(self.i2c) self.drv = [] for i in range(8): print('I2CThread: Initializing driver {}'.format(i)) self.drv.append(adafruit_drv2605.DRV2605(self.tca[i])) self.drv[i].use_LRM() self.drv[i].library = adafruit_drv2605.LIBRARY_LRA return
def __init__(self, name, args={}, debug_pref=False): super().__init__(name, args, debug_pref) self._type = 'haptic' if 'source_bus' not in args: raise AttributeError("Source bus required for {} {}".format(self.type, self.name)) self._connection = adafruit_drv2605.DRV2605(self._i2c) self._motor = 'erm' if 'motor' in args: if type(args['motor']) is not str: raise TypeError("motor in output {} must be type str".format(self.name)) args['motor'] = args['motor'].lower() if args['motor'] not in ['erm', 'lra']: raise AttributeError("Invalid motor in output {}".format(self.name)) self._motor = args['motor'] if self._motor == 'lra': self._connection.use_LRM() self._effect = None if 'effect' in args: if type(args['effect']) is not str and type(args['effect']) is not int and type(args['effect']) is not float: raise TypeError("effect in output {} must be type int".format(self.name)) effect = int(args['effect']) if effect < 1 or effect > 123: raise ValueError("Invalid effect value for {}".format(self.name)) self._effect = effect
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None): super(I2CThread, self).__init__(group=group, target=target, name=name) self._running = True self.args = args self.kwargs = kwargs self.queue = kwargs['queue'] print("I2CThread: initializing I2C") # communicating to DRV2605 self.i2c = busio.I2C(board.SCL, board.SDA) # access to hardware print('I2CThread: Initializing I2C mux' ) # enabling multiple motor control self.tca = adafruit_tca9548a.TCA9548A(self.i2c) self.drv = [] # drive multiple motors and link Queue protocol to DRV for i in range(8): print('I2CThread: Initializing driver {}'.format(i)) self.drv.append(adafruit_drv2605.DRV2605(self.tca[i])) #self.drv[i].use_LRA() #adafruit-DRV #print('DRV2605: Auto-Calibrating driver {}'.format(i)) #self.drv[i].mode = 7 #MODE_AUTOCAL #self.drv[i].autocal() #print('2x auto-cal driver {}'.format(i)) #self.drv[i].autocal() print('DRV2605: driver {} ready for use'.format(i)) self.drv[i].mode = 1 #MODE_INTTRIG self.drv[i].library = 6 #LIBRARY_LRA return
def adafruit(): import board import busio import adafruit_drv2605 i2c = busio.I2C(board.SCL, board.SDA) drv = adafruit_drv2605.DRV2605(i2c) for i in range(123): drv.sequence[i] = adafruit_drv2605.Effect(i) drv.play() time.sleep(0.5) drv.stop()
def __init__(self): self.IMU_ADDRESS = 0x29 self.DRV_ADDRESS = 0x5A self.METER_ADDRESS = '0x40' self.DACL_ADDRESS = 0x62 self.DACR_ADDRESS = 0x63 self.i2c = busio.I2C(board.SCL, board.SDA) devices = self.scan_bus() print(devices) if len(devices) == 0: print('* No I/O device found') if str(self.IMU_ADDRESS) in devices: print('* Motion sensor detected') self.motion = adafruit_bno055.BNO055_I2C(self.i2c, self.IMU_ADDRESS) else: self.motion = None if str(self.DRV_ADDRESS) in devices: haptic = adafruit_drv2605.DRV2605(self.i2c, self.DRV_ADDRESS) haptic.mode(0x03) # Analog/PWM Mode haptic.use_LRM() print('* Haptic driver detected (and set to analog mode)') else: self.haptic = None if str(self.METER_ADDRESS) in devices: self.meter = INA219(0.1, 3) self.meter.configure(self.meter.RANGE_16V) print('* Current sensor detected') else: self.meter = None if str(self.DACL_ADDRESS) in devices: self.leftDAC = adafruit_mcp4725.MCP4725(self.i2c, self.DACL_ADDRESS) print('* Left DAC detected') else: self.leftDAC = None if str(self.DACL_ADDRESS) in devices: self.rightDAC = adafruit_mcp4725.MCP4725(self.i2c, self.DACR_ADDRESS) print('* Left DAC detected') else: self.rightDAC = None
def playHeartBeat(heartRate): # Initialize I2C bus and DRV2605 module. i2c = busio.I2C(board.SCL, board.SDA) drv = adafruit_drv2605.DRV2605(i2c) # Main loop runs forever trying each effect (1-123). # See table 11.2 in the datasheet for a list of all the effect names and IDs. # http://www.ti.com/lit/ds/symlink/drv2605.pdf softPulse = 21 hardPulse = 17 beatLength = 0.5 # heartRate = 68 if heartRate > 0 and heartRate < 120: heartRate = 68 pauseLength = (60 / heartRate) - beatLength if pauseLength < 0: pauseLength = 0.1 counter = 0 while True: # print('Playing effect #{0}'.format("softPulse: " + str(softPulse))) drv.sequence[0] = adafruit_drv2605.Effect( softPulse) # Set the effect on slot 0. # print('Playing effect #{0}'.format("hardPulse: " + str(hardPulse))) drv.sequence[1] = adafruit_drv2605.Effect( hardPulse) # Set the effect on slot 0. # You can assign effects to up to 7 different slots to combine # them in interesting ways. Index the sequence property with a # slot number 0 to 6. # Optionally, you can assign a pause to a slot. E.g. # drv.sequence[1] = adafruit_drv2605.Pause(0.5) # Pause for half a second drv.play() # play the effect time.sleep(beatLength) # for 0.5 seconds drv.stop() # and then stop (if it's still running) time.sleep(pauseLength)
# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries # SPDX-License-Identifier: MIT # Simple demo of the DRV2605 haptic feedback motor driver. # Will play all 123 effects in order for about a half second each. import time import board import busio import adafruit_drv2605 # Initialize I2C bus and DRV2605 module. i2c = busio.I2C(board.SCL, board.SDA) drv = adafruit_drv2605.DRV2605(i2c) # Main loop runs forever trying each effect (1-123). # See table 11.2 in the datasheet for a list of all the effect names and IDs. # http://www.ti.com/lit/ds/symlink/drv2605.pdf effect_id = 1 while True: print("Playing effect #{0}".format(effect_id)) drv.sequence[0] = adafruit_drv2605.Effect( effect_id) # Set the effect on slot 0. # You can assign effects to up to 7 different slots to combine # them in interesting ways. Index the sequence property with a # slot number 0 to 6. # Optionally, you can assign a pause to a slot. E.g. # drv.sequence[1] = adafruit_drv2605.Pause(0.5) # Pause for half a second drv.play() # play the effect time.sleep(0.5) # for 0.5 seconds
def __init__(self): i2c = busio.I2C(board.SCL, board.SDA) self._drv = adafruit_drv2605.DRV2605(i2c) print ("DRV2605 haptic feedback motor driver initialized.")
def handler(signal_received, frame): for i in range(8): drv[i].stop() exit(0) # Create I2C bus as normal i2c = busio.I2C(board.SCL, board.SDA) # Create the TCA9548A object and give it the I2C bus print("Initializing I2C Mux") tca = adafruit_tca9548a.TCA9548A(i2c) for i in range(8): print("Initializing driver {}".format(i)) drv.append(adafruit_drv2605.DRV2605(tca[i])) drv[i].use_LRM() signal(SIGINT, handler) # Main loop runs forever trying each effect (1-123). # See table 11.2 in the datasheet for a list of all the effect names and IDs. # http://www.ti.com/lit/ds/symlink/drv2605.pdf effect_id = 118 while True: print('Playing effect #{0}'.format(effect_id)) for i in range(8): print('Using channel #{0}'.format(i)) drv[i].sequence[0] = adafruit_drv2605.Effect( effect_id) # Set the effect on slot 0. drv[i].sequence[1] = adafruit_drv2605.Pause(
#!/usr/bin/env python import board import busio import adafruit_tca9548a import adafruit_drv2605 i2c = busio.I2C(board.SCL, board.SDA) tca = adafruit_tca9548a.TCA9548A(i2c) drvs = [adafruit_drv2605.DRV2605(tca[i]) for i in range(5)] def multi_vib(levels): """ given [Int], vibrate each motor based on input """ for level, drv in zip(levels, drvs): vibrate(level, drv) print("vibrate at:", level) def vibrate(level, drv): # control vibration level at 20 60 and 100 if level <= 100 and level > 60: drv.sequence[0] = adafruit_drv2605.Effect(47) elif level >= 60: drv.sequence[0] = adafruit_drv2605.Effect(49) else: drv.sequence[0] = adafruit_drv2605.Effect(51) drv.play()