def initPCA9685(self): """ @description configure Jetson Nano GPIO for communication with PCA9685 @return a PCA9685 Device object to communicate with PCA9685 chip """ GPIO.setmode(GPIO.BOARD) mode = GPIO.getmode() print("Jetson Nano GPIO Mode: {}".format(mode)) # discover I2C devices i2c_devs = Device.get_i2c_bus_numbers() print("The following /dev/i2c-* devices were found:\n{}".format( i2c_devs)) # Create I2C device """ working_devs = list() print("Looking out which /dev/i2c-* devices is connected to PCA9685") for dev in i2c_devs: try: pca9685 = Device(0x40,dev) # Set duty cycle pca9685.set_pwm(5, 2047) # set pwm freq pca9685.set_pwm_frequency(1000) print("Device {} works!".format(dev)) working_devs.append(dev) except: print("Device {} does not work.".format(dev)) # Select any working device, for example, the first one print("Configuring PCA9685 connected to /dev/i2c-{} device.".format(working_devs[0])) pca9685 = Device(0x40, working_devs[0]) """ pca9685 = Device( 0x40, 1 ) # Immediately set a working device, this assumes PCA9685 is connected to I2C channel 1 # ESC work at 50Hz pca9685.set_pwm_frequency(50) # Set slow speed duty cycles self.set_channel_duty_cycle(pca9685, 0, 5.0) self.set_channel_duty_cycle(pca9685, 1, 5.0) self.set_channel_duty_cycle(pca9685, 2, 5.0) self.set_channel_duty_cycle(pca9685, 3, 5.0) # configure rest of channels to 0 duty cycle rest = np.arange(4, 16, 1) for channel in rest: self.set_channel_duty_cycle(pca9685, channel, 0.0) return pca9685
""" @pwmdev a Device class object already configured @channel Channel or PIN number in PCA9685 to configure 0-15 @dt desired duty cycle """ val = (dt * 4095) // 100 pwmdev.set_pwm(channel, val) # SET GPIO mode to BOARD GPIO.setmode(GPIO.BOARD) mode = GPIO.getmode() print(mode) # discover I2C devices i2c_devs = Device.get_i2c_bus_numbers() print("The following /dev/i2c-* devices were found:\n{}".format(i2c_devs)) # Create I2C device working_devs = list() print("Looking out which /dev/i2c-* devices is connected to PCA9685") for dev in i2c_devs: try: pca9685 = Device(0x40, dev) # Set duty cycle pca9685.set_pwm(5, 2047) # set pwm freq pca9685.set_pwm_frequency(1000) print("Device {} works!".format(dev)) working_devs.append(dev)