Giter Club home page Giter Club logo

adafruit_circuitpython_pca9685's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

Driver for the PCA9685, a 16-channel, 12-bit PWM chip

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-pca9685

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-pca9685

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-pca9685

Usage Example

See examples/pca9685_simpletest.py for a demo of the usage.

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

adafruit_circuitpython_pca9685's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_circuitpython_pca9685's Issues

Outdated tutorial?

I got a PCA9685 pwm board, and I want to control LEDs with it. But I can't find functions that are in the tutorial: set_pwm_freq(freq), set_pwm(channel, on, off). Are these outdated and removed, or am I searching in the wrong place? I looked at the servo library too, I couldn't find it there

The tutorial I followed:
https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/
https://learn.adafruit.com/adafruit-16-channel-servo-driver-with-raspberry-pi/library-reference

timing control not exposed

It is impossible to control relative phase between channels as LEDn_ON and LEDn_OFF registers are not exposed.

Please expose LEDn_ON and LEDn_OFF registers and let user customize their own timing instead of accepting a simple duty cycle value.

PCA9685 configured to take i2c commands from all addresses.

I'm combining my PCA9685 with HT16K33 8x8 matrix.
As soon as I send a command to the HT1633 the PCA stops responding and all my connected servos go limp.

The solution for this issue was identified here: rwaldron/johnny-five#1591 (comment)

It appears the issue was fixed in the arduino library but not corrected in circuit python (see adafruit/Adafruit-PWM-Servo-Driver-Library@9f8e1dd#diff-5d1e3a5213c0ef6dedb2baf5cc323727L106-R110)

I confirmed the fix below works for me:
Change line 163 of adafruit_pca9685 in frequency(self, freq) from
self.mode1_reg = old_mode | 0xa1 # Mode 1, autoincrement on
to
self.mode1_reg = old_mode | 0xa0 # Mode 1, autoincrement on, fix to stop pca9685 from accepting commands at all addresses

I will submit a pull request with this change.

RTD showing double colons in fields

image
According to my preliminary investigation..

I checked the conf.py file of this library and the displayio_layout, where it shows correclty and I could see that this library has not the napoleon theme installed. However I do not think this is the issue, as the MCP4728 had it installed but showed the same problem wiith the double colons in RTD
https://github.com/adafruit/Adafruit_CircuitPython_MCP4728/blob/d907e3e0baa15cd50cc647d80261dac77aeb68fe/docs/conf.py#L104

I found this source online, that this was present in a previous version of sphinx:
https://stackoverflow.com/questions/70426337/sphinx-documentation-showing-double-colon-in-fields

When I built the documentation locally the two double colons does not shown, so not really sure what is hapenning. Maybe we patch sphinx and we did not built the documenation... not sure :(

Switch to properties instead of weird functions.

This driver has the MicroPython-ism of a setter/getter function where its a getter when values are None and setter when they are not. This is not Pythonic and confusing.

Instead, this API should be changed so that it has a number of channels that act like pulseio.PWMOut with frequency and duty_cycle as properties. frequency of each channel would be read only because its shared amongst all channels. The outer class can have an adjustable frequency property.

maximum recursion depth exceeded error

I'm trying to wire up a PCA9685 controller board to a Adafruit STM32F405 using CircuitPython 5.3.0.

The code I'm using to test things out is based on the example code you provide.

import  board
import  busio

from adafruit_pca9685 import  PCA9685
from adafruit_motor import  servo

i2c_bus = busio.I2C(board.SCL, board.SDA)
pca_board = PCA9685(i2c_bus)
pca_board.frequency = 50

print(pca_board.channels[0])

# the following line triggers the error
servo0 = servo.Servo(pwm_out=pca_board.channels[0])

for i in range(180):
    servo0.angle = i

I'm getting the following:

Traceback (most recent call last):
  File "code.py", line 20, in <module>
  File "adafruit_motor/servo.py", line 106, in __init__
  File "adafruit_motor/servo.py", line 46, in __init__
  File "adafruit_motor/servo.py", line 50, in set_pulse_width_range
  File "adafruit_pca9685.py", line 73, in frequency
  File "adafruit_pca9685.py", line 151, in frequency
  File "adafruit_register/i2c_struct.py", line 86, in __get__
RuntimeError: maximum recursion depth exceeded

Hopefully, I'm just being dumb, but even after chasing the error into the libraries I'm having a hard time spotting what's triggering the recursion.

Example not running on Raspberry Pi 5

When I run any of the examples on a Raspberry Pi 5, I get this:

ImportError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/moritz/pwm2/test.py", line 8, in <module>
    import board
  File "/home/moritz/pwm2/.venv/lib/python3.11/site-packages/board.py", line 50, in <module>
    from adafruit_blinka.board.raspberrypi.raspi_5b import *
  File "/home/moritz/pwm2/.venv/lib/python3.11/site-packages/adafruit_blinka/board/raspberrypi/raspi_5b.py", line 6, in <module>
    from adafruit_blinka.microcontroller.bcm2712 import pin
  File "/home/moritz/pwm2/.venv/lib/python3.11/site-packages/adafruit_blinka/microcontroller/bcm2712/pin.py", line 5, in <module>
    from adafruit_blinka.microcontroller.generic_linux.libgpiod_pin import Pin
  File "/home/moritz/pwm2/.venv/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/libgpiod_pin.py", line 8, in <module>
    raise ImportError(
ImportError: libgpiod Python bindings not found, please install and try again! See https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/main/libgpiod.py

Any ideas?

Is there a way to manually turn Pins on/off?

I'm trying to control an RC car and i#ve run into a road block so to say. The cars speed controller needs an activation signal before accepting any PWM signal. That activation signal isn't PWM, but a specific pattern.
So my question is, is there any way to turn a Channel on and off manually, so i can put together the activation signal i need?

It does not work although everything looks ok.

It doesn't work on my device, Raspberry Pi 4B. Everything looks OK, no errors, no warnings, but nothing happened, the PWM light is not blinking, it seems like there is no message sent to pca9685.

Finishing Touches For PyPI

Needs some finishing touches for PyPI:

  • Add PyPI install directions to README
  • Add Blinka to setup.py->install_requires

Jetson AGX I2C problem

Hello,

We connected the PWM 16 ch board to pin 3 & 5 from Nvidia Jetson Xavier AGX Dev Board and we get Remote I/O error

jetson@agx:~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from board import SCL, SDA
WARNING: Carrier board is not from a Jetson Developer Kit.
WARNNIG: Jetson.GPIO library has not been verified with this carrier board,
WARNING: and in fact is unlikely to work correctly.
>>> import busio
>>> from adafruit_pca9685 import PCA9685
>>> from adafruit_motor import servo
>>> i2c = busio.I2C(SCL, SDA)
>>> pca = PCA9685(i2c, address = 0x40)
>>> pca.frequency = 50
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_pca9685.py", line 144, in frequency
    self.mode1_reg = old_mode  # Mode 1
  File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_register/i2c_struct.py", line 78, in __set__
    i2c.write(buf)
  File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_bus_device/i2c_device.py", line 84, in write
    self.i2c.writeto(self.device_address, buf, start=start, end=end)
  File "/home/jetson/.local/lib/python3.6/site-packages/busio.py", line 115, in writeto
    return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=stop)
  File "/home/jetson/.local/lib/python3.6/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 49, in writeto
    self._i2c_bus.write_bytes(address, buffer[start:end])
  File "/home/jetson/.local/lib/python3.6/site-packages/Adafruit_PureIO/smbus.py", line 308, in write_bytes
    self._device.write(buf)
OSError: [Errno 121] Remote I/O error
>>>

We understand it might be a hardware issue, but the device is detected on i2c-tools:

jetson@agx:~$ sudo i2cdetect -y -r 8
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: 70 -- -- -- -- -- -- --

I also asked in NVIDIA/jetson-gpio#50 in regards to board SCL & SDA pins, but so far we are stuck with the investigation.

The code works on other jetson nano/nx.

Any idea into how to debug this further?

Thank you!
R

Docs build failing.

Running Sphinx v2.4.4
making output directory... done
loading intersphinx inventory from https://docs.python.org/3.4/objects.inv...
loading intersphinx inventory from https://circuitpython.readthedocs.io/projects/busdevice/en/latest/objects.inv...
loading intersphinx inventory from https://circuitpython.readthedocs.io/en/latest/objects.inv...

Warning, treated as error:
failed to reach any of the inventories with the following issues:
intersphinx inventory 'https://circuitpython.readthedocs.io/projects/busdevice/en/latest/objects.inv' not fetchable due to <class 'requests.exceptions.HTTPError'>: 502 Server Error: Bad Gateway for url: https://circuitpython.readthedocs.io/projects/busdevice/en/latest/objects.inv
##[error]Process completed with exit code 2.```

duty_cycle getter doesn't return what setter was given

Hi, why does the setter have value + 1 in line 91?:

value = (value + 1) >> 4

There isn't a corresponding adjustment in the getter, so for example if I set duty_cycle to 0x7fff and then read it back I get 0x8000.

Thanks!
Rob.

Mpy file needs to be refreshed

I was trying to use this module as released in a 2.0.0 version of CircuitPython but the module says it's incompatible with the version.

I asked in Discord an was suggested to open an incident to ask the module to be "refreshed" so it can work with the latest version.

Following the error message, I did tried the module released in the Bundle and it is now working perfectly. I also noted the message in the module release notes that it is compatible with CircuitPython 0.9.4.

Thanks.

Examples need updated formats

import time

from board import SCL, SDA
import busio

# Import the PCA9685 module. Available in the bundle and here:
#   https://github.com/adafruit/Adafruit_CircuitPython_PCA9685
from adafruit_motor import servo
from adafruit_pca9685 import PCA9685

i2c = busio.I2C(SCL, SDA)

should look more like this

import time
import board
import busio
from adafruit_motor import servo
from adafruit_pca9685 import PCA9685

i2c = busio.I2C(board.SCL, board.SDA)
# i2c = busio.I2C(board.GP1, board.GP0)    # Pi Pico RP2040

I don't have the board to test the initializations and ensure the formatting works. Just ran across these outdated looking library discrepancies while fielding a support question. Could be a good first issue for anyone having this board to update the formatting.

Friendly error message to catch and avoid ZeroDivisionError

This library can end up throwing a ZeroDivisionError in

@property
def frequency(self):
"""The overall PWM frequency in Hertz."""
return self.reference_clock_speed / 4096 / self.prescale_reg
- this is probably occuring around issues with i2c communications but I'm not really sure. This is a confusing error especially for programmers not used to reading stack traces who may think it's a division problem in their code.

Users who have bumped into this (and reported it):

I'm finding some of the code in the PCA9685 class a bit puzzling but I'll put another issue in for that.

Missing Type Annotations

There are missing type annotations for some functions in this library.

The typing module does not exist on CircuitPython devices so the import needs to be wrapped in try/except to catch the error for missing import. There is an example of how that is done here:

try:
    from typing import List, Tuple
except ImportError:
    pass

Once imported the typing annotations for the argument type(s), and return type(s) can be added to the function signature. Here is an example of a function that has had this done already:

def wrap_text_to_pixels(
    string: str, max_width: int, font=None, indent0: str = "", indent1: str = ""
) -> List[str]:

If you are new to Git or Github we have a guide about contributing to our projects here: https://learn.adafruit.com/contribute-to-circuitpython-with-git-and-github

There is also a guide that covers our CI utilities and how to run them locally to ensure they will pass in Github Actions here: https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/check-your-code In particular the pages: Sharing docs on ReadTheDocs and Check your code with pre-commit contain the tools to install and commands to run locally to run the checks.

If you are attempting to resolve this issue and need help, you can post a comment on this issue and tag both @FoamyGuy and @kattni or reach out to us on Discord: https://adafru.it/discord in the #circuitpython-dev channel.

The following locations are reported by mypy to be missing type annotations:

  • adafruit_pca9685.py:47
  • adafruit_pca9685.py:59
  • adafruit_pca9685.py:72
  • adafruit_pca9685.py:87
  • adafruit_pca9685.py:94
  • adafruit_pca9685.py:119
  • adafruit_pca9685.py:137
  • adafruit_pca9685.py:152

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.