If you provide a link to the source of this that would help.

But, basically in your own Python code you would first import the class

Ex:
  * from source_file import Pca9685*

The you could create an instance of this like:

  * my_servo_control =  Pca9685(bus_num, addr_val)*

You could need to know the value of bus_num and addr_val to set these.

Then you could call the methods as such:
   *my_servo_control.read_reg(reg_val)*

 Again, you would need to know what the value of reg_val is to set the
'reg' parameter for the 'read_reg' method.

You still need to know where it is getting the '*write_i2c_block_data*' and
*'read_i2c_block_data*' methods from though.
Perhaps 'import smbus' is missing?
https://learn.sparkfun.com/tutorials/python-programming-tutorial-getting-started-with-the-raspberry-pi/experiment-4-i2c-temperature-sensor


A course in Python wouldn't hurt.


Cheers,

Jon


On Tue, May 5, 2020 at 1:29 PM Mala Dies <fun...@gmail.com> wrote:

> Hello,
>
> I have a, to me, piece of complicated text in Python3 format.
>
> Anyway...
>
> I have been unable to make the conversion of the wrapper to another
> Python3 file.
>
> So, here is the source in case you are interested:
>
> from time import sleep
>
> # relevant registers
> MODE1       = 0x00
> MODE2       = 0x01
> LED         = 0x06
> ALL_LED     = 0xFA
> PRE_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 ] )
>
> Now...
>
> How would I actually use this source to promote a servo movement with the
> ServoCape?
>
> I have tried particular source from different tutorials, the python.org
> site, and examples of classes online.
>
> None really cover the BBB and expansion Capes like this source is listed.
> Anyway...
>
> What steps if any would you take to make a servo move w/ this Cape and
> source?
>
>
>    - Would I need a Adafruit_BBIO library for GPIO/PWM or a similar
>    library?
>
> Seth
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beagleboard/5e42131b-733f-413d-91e9-eb204e204f84%40googlegroups.com
> <https://groups.google.com/d/msgid/beagleboard/5e42131b-733f-413d-91e9-eb204e204f84%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/CAG99bkp%3Dx9QNdd_rfPWxhCxWJ9vFHzXjt3PtvsoLsrymO-WNwQ%40mail.gmail.com.

Reply via email to