2

I am using a Texas Instruments DRV2605 to drive some haptic motors. I am using the Adafruit library here to communicate with the DRV through Python. I need to set some bit registers of the chip but am getting the exception in the title.

I am subclassing the DRV2605 class to overwrite a couple of bits.

Here is a sample of my code:

import adafruit_drv2605
from adafruit_drv2605 import DRV2605 as Old_DRV2506
class MY_DRV2605(Old_DRV2506):
    def __init__(self, *args, **kwargs):
        print('that')
        super().__init__(self, *args, **kwargs)
        print('other')
        # turn on ERM_OPEN_LOOP
        control3 = self._read_u8(_DRV2605_REG_CONTROL3)
        # self._write_u8(_DRV2605_REG_CONTROL3, control3 | 0x20 | 0x01)
        self._write_u8(_DRV2605_REG_CONTROL3, control3 | 0x01)
        # self._write_u8(0x17, 0x40) # Overdrive voltage
        # self._write_u8(0x16, 0x20) # rated voltage
        # x17 = self._read_u8(0x17)
        # y16 = self._read_u8(0x16)
        print('this', x16, y17)

i2c = busio.I2C(board.SCL, board.SDA)

create haptic object on I2C bus

drv = adafruit_drv2605.DRV2605(i2c)

drv = MY_DRV2605(i2c)

And the exception trace:

    that
Traceback (most recent call last):
  File "force_haptic_test_4.py", line 60, in <module>
    drv = MY_DRV2605(i2c)
  File "force_haptic_test_4.py", line 34, in __init__
    super().__init__(self, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_drv2605.py", line 100, in __init__
    self._device = I2CDevice(i2c, address)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 68, in __init__
    self.__probe_for_device()
  File "/usr/local/lib/python3.7/dist-packages/adafruit_bus_device/i2c_device.py", line 169, in __probe_for_device
    while not self.i2c.try_lock():
AttributeError: 'MY_DRV2605' object has no attribute 'try_lock'

Does anyone know how to fix this exception please?

Bassline Soup
  • 115
  • 1
  • 10

0 Answers0