Giter VIP home page Giter VIP logo

adafruit_circuitpython_pcf8591's Introduction

Introduction

Documentation Status

Discord

Build Status

Code Style: Black

ADC+DAC Combo

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-pcf8591

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

sudo pip3 install adafruit-circuitpython-pcf8591

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-pcf8591

Usage Example

import time
import board

import adafruit_pcf8591.pcf8591 as PCF
from adafruit_pcf8591.analog_in import AnalogIn
from adafruit_pcf8591.analog_out import AnalogOut

############# AnalogOut & AnalogIn Example ##########################
#
# This example shows how to use the included AnalogIn and AnalogOut
# classes to set the internal DAC to output a voltage and then measure
# it with the first ADC channel.
#
# Wiring:
# Connect the DAC output to the first ADC channel, in addition to the
# normal power and I2C connections
#
#####################################################################
i2c = board.I2C()
pcf = PCF.PCF8591(i2c)

pcf_in_0 = AnalogIn(pcf, PCF.A0)
pcf_out = AnalogOut(pcf, PCF.OUT)

while True:

    print("Setting out to ", 65535)
    pcf_out.value = 65535
    raw_value = pcf_in_0.value
    scaled_value = (raw_value / 65535) * pcf_in_0.reference_voltage

    print("Pin 0: %0.2fV" % (scaled_value))
    print("")
    time.sleep(1)

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_pcf8591's People

Contributors

dhalbert avatar evaherrada avatar foamyguy avatar kattni avatar keiththeee avatar siddacious avatar tannewt avatar tcfranks avatar techwolfy avatar tekktrik avatar

Stargazers

 avatar  avatar  avatar

Watchers

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

adafruit_circuitpython_pcf8591's Issues

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_pcf8591/analog_out.py:34
  • adafruit_pcf8591/analog_out.py:53
  • adafruit_pcf8591/analog_in.py:34
  • adafruit_pcf8591/pcf8591.py:56
  • adafruit_pcf8591/pcf8591.py:75
  • adafruit_pcf8591/pcf8591.py:88
  • adafruit_pcf8591/pcf8591.py:109
  • adafruit_pcf8591/pcf8591.py:114

AnalogIn not loading on Ubuntu 22.04.2.LTS

Had to downgrade to adafruit-circuitpython-pcf8591-1.0.9.

With adafruit-circuitpython-pcf8591-1.0.15 get following error:

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> import adafruit_pcf8591.pcf8591 as PCF
>>> from adafruit_pcf8591.analog_in import AnalogIn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/adafruit_pcf8591/analog_in.py", line 37, in <module>
    class AnalogIn:
  File "/usr/local/lib/python3.10/dist-packages/adafruit_pcf8591/analog_in.py", line 40, in AnalogIn
    def __init__(self, pcf: PCF8591, pin: int) -> None:
NameError: name 'PCF8591' is not defined
>>> 

Pip3 Freeze:
Adafruit-Blinka==8.19.0
adafruit-circuitpython-bme280==2.6.21
adafruit-circuitpython-busdevice==5.2.5
adafruit-circuitpython-mlx90614==1.2.15
adafruit-circuitpython-pcf8591==1.0.15
adafruit-circuitpython-register==1.9.15
adafruit-circuitpython-requests==1.13.3
adafruit-circuitpython-typing==1.9.3
Adafruit-PlatformDetect==3.46.0
Adafruit-PureIO==1.1.10
aiohttp==3.8.1
aiosignal==1.3.1
aniso8601==9.0.1
astroalign==2.4.1
astroplan==0.8
astropy==5.0
astroquery==0.4.6
async-timeout==4.0.2
asyncio==3.4.3
attrs==21.2.0
Automat==20.2.0
Babel==2.8.0
bcrypt==3.2.0
beautifulsoup4==4.11.1
bidict==0.22.1
blinker==1.4
certifi==2020.6.20
chardet==4.0.0
charset-normalizer==2.1.1
click==8.0.3
cloud-init==23.1.2
colorama==0.4.4
colorzero==2.0
command-not-found==0.3
configobj==5.0.6
constantly==15.1.0
contourpy==1.0.7
cryptography==3.4.8
cycler==0.11.0
dbus-python==1.2.18
distro==1.7.0
distro-info===1.1build1
dnspython==2.1.0
dominate==2.7.0
email-validator==1.2.1
eventlet==0.33.1
Flask==2.1.2
Flask-Admin==1.6.0
Flask-Bcrypt==1.0.1
Flask-Bootstrap==3.3.7.1
Flask-Login==0.6.1
Flask-Mail==0.9.1
flask-nav==0.6
flask-restx==0.5.1
Flask-SocketIO==5.2.0
Flask-SQLAlchemy==2.5.1
Flask-WTF==1.0.1
fonttools==4.39.4
frozenlist==1.3.3
gpiozero==1.6.2
greenlet==1.1.2
html5lib==1.1
httplib2==0.20.2
hyperlink==21.0.0
idna==3.3
imageio==2.28.1
importlib-metadata==4.6.4
incremental==21.3.0
itsdangerous==2.0.0
jeepney==0.7.1
Jinja2==3.0.3
jsonpatch==1.32
jsonpointer==2.0
jsonschema==3.2.0
keyring==23.5.0
kiwisolver==1.4.4
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
lazy_loader==0.2
lgpio==0.1.0.1
MarkupSafe==2.1.2
matplotlib==3.5.2
metar==1.10.0
more-itertools==8.10.0
multidict==6.0.4
multiprocessing-logging==0.3.3
netifaces==0.11.0
networkx==3.1
numpy==1.21.5
oauthlib==3.2.0
opencv-python==4.6.0.66
packaging==23.1
pandas==1.5.3
pexpect==4.8.0
photutils==1.4.0
Pillow==9.1.1
plotly==5.8.2
psutil==5.9.1
ptyprocess==0.7.0
pyasn1==0.4.8
pyasn1-modules==0.2.1
pyerfa==2.0.0.3
pyftdi==0.54.0
PyGObject==3.42.1
PyHamcrest==2.0.2
PyJWT==2.3.0
pynws==1.4.1
pyOpenSSL==21.0.0
pyparsing==2.4.7
pyrsistent==0.18.1
pyserial==3.5
python-apt==2.4.0+ubuntu1
python-dateutil==2.8.2
python-debian===0.1.43ubuntu1
python-engineio==4.4.1
python-magic==0.4.24
python-socketio==5.8.0
pytz==2022.1
pyusb==1.2.1
pyvo==1.4.1
PyWavelets==1.4.1
PyYAML==5.4.1
requests==2.25.1
RPi.GPIO==0.7.1a4
schedule==1.2.0
scikit-image==0.19.3
scipy==1.8.1
SecretStorage==3.3.1
sep==1.2.1
service-identity==18.1.0
six==1.16.0
sos==4.4
soupsieve==2.4.1
spidev==3.5
SQLAlchemy==1.4.37
ssh-import-id==5.11
systemd-python==234
tenacity==8.2.2
tifffile==2023.4.12
Twisted==22.1.0
typing_extensions==4.5.0
tzdata==2023.3
ubuntu-advantage-tools==8001
ufw==0.36.1
unattended-upgrades==0.1
urllib3==1.26.5
visitor==0.1.3
wadllib==1.3.6
webencodings==0.5.1
Werkzeug==2.1.2
WTForms==3.0.1
yarl==1.9.2
zipp==1.0.0
zope.interface==5.4.0
zwoasi==0.1.0.1

PyPI package is broken

The PyPI package for this library doesn't install any source files.

From a fresh virtualenv:

(env) pi@raspberrypi:~ $ pip3 install adafruit-circuitpython-pcf8591
<snip>
Installing collected packages: adafruit-circuitpython-pcf8591
Successfully installed adafruit-circuitpython-pcf8591-1.0.1

(env) pi@raspberrypi:~ $ python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import adafruit_pcf8591
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'adafruit_pcf8591'

DAC disabled after reading values from ADC

I'm trying to keep the DAC active while reading values from two of the ADC channels but the DAC is disabled after each read.
Is it possible to keep the DAC active while reading values from the ADC with the PCF8591 ?

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.