from time import sleep
# relevant registersMODE1 = 0x00MODE2 = 0x01LED = 0x06ALL_LED = 0xFAPRE_SCALE = 0xFE
class Pca9685: def __init__( self, bus, addr ): self.addr = 0b10000000 | addr self.bus = bus self.write_reg( MODE1, 1 << 5 ) # initialize MODE1 register sleep( 500e-6 ) # wait 500us to allow oscillator to power up
def read_reg( self, reg ) return self.read_regs( reg, 1 )[0]
def write_reg( self, reg, value ): return self.write_regs( reg, [ value ] )
def read_regs( self, reg, count ): assert reg in range( 0, 256 ) assert count in range( 1, 257-reg ) return self.bus.read_i2c_block_data( self.addr, reg, count )
def write_regs( self, reg, values ): assert reg in range( 0, 256 ) return self.bus.write_i2c_block_data( self.addr, reg, values )
def get_pwm( self, output ): assert output in range( 0, 16 ) reg = LED + 4 * output
[ on_l, on_h, off_l, off_h ] = self.read_regs( reg, 4 ) on = on_l | on_h << 8 off = off_l | off_h << 8
phase = on duty = ( off - on ) & 0xfff if off & 0x1000: duty = 0 elif on & 0x1000: duty = 4096
return ( duty, phase )
def set_pwm( self, output, duty, phase=0 ): assert duty in range( 0, 4097 ) assert phase in range( 0, 4096 )
if output == 'all': reg = ALL_LED else: assert output in range( 0, 16 ) reg = LED + 4 * output
on = phase off = ( duty + phase ) & 0xfff if duty == 0: off |= 0x1000 elif duty == 4096: on |= 0x1000
on_l = on & 0xff on_h = on >> 8 off_l = off & 0xff off_h = off >> 8 self.write_regs( reg, [ on_l, on_h, off_l, off_h ] )
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/5e42131b-733f-413d-91e9-eb204e204f84%40googlegroups.com.
from smbus2 import SMBus
from ServoLib import Pca9685
from time import sleep
i2c2 = SMBus("/dev/i2c-2")
x = Pca9685(i2c2, 0b111111)
x.__init__
x.read_reg
x.write_reg
x.read_regs
x.write_regs
x.get_pwm
x.set_pwm
To unsubscribe from this group and stop receiving emails from it, send an email to beagl...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/5e42131b-733f-413d-91e9-eb204e204f84%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to beagl...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
from smbus2 import SMBusfrom ServoLib import Pca9685from time import sleep
i2c2 = SMBus("/dev/i2c-2")x = Pca9685(i2c2, 0b111111)
x.read_reg(2)x.write_reg(2, 1)x.read_regs(2, 5)x.write_regs(2, len(int(0))
angle = int(input("What would your favorite angle be now? ")if angle <= 180 or angle >=0: angle = x.get_pwm(1) f = angle + x.set_pwm(0, 2000, 0) print("Your angle is " + angle)
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/0a7798ae-13f3-453b-9963-78290a9c005f%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/415f46f3-ff25-4da9-b12d-904b7bceb3e3%40googlegroups.com.
from smbus2 import SMBusfrom ServoLib import Pca9685from time import sleep
i2c2 = SMBus("/dev/i2c-2")x = Pca9685(i2c2, 0b111111)
x.read_reg = 0x.write_reg = 0x.read_regs = (0, 5)x.write_regs = (0, 0, 5)x.pwm_get = (1)x.pwm_set = (45, 2000, 0)sleep(5)
angle = int(input("What would your favorite angle be now? "))
if angle <= 180 or angle >=0:
angle = x.pwm_get print("Your angle is ", angle)
angleOne = int(input("What shall the angle be? ")) if angle >= 45: angleOne = x.pwm_set print("The sustained angle is ", angleOne) sleep(5)
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/415f46f3-ff25-4da9-b12d-904b7bceb3e3%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/415f46f3-ff25-4da9-b12d-904b7bceb3e3%40googlegroups.com.