{"id":15532887,"url":"https://github.com/matham/pi_waveshare_adc","last_synced_at":"2025-04-09T10:14:40.873Z","repository":{"id":74806625,"uuid":"291892018","full_name":"matham/pi_waveshare_adc","owner":"matham","description":"A performant Python library to read the RPi Waveshare ADC expansion board.","archived":false,"fork":false,"pushed_at":"2021-05-08T16:42:26.000Z","size":5866,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-15T04:26:11.759Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matham.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-01T04:04:15.000Z","updated_at":"2021-05-08T16:32:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b1630f3-1671-48fc-812d-f85025335856","html_url":"https://github.com/matham/pi_waveshare_adc","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"8220d6627e3ba6e74bc4304063f75f65ee76459a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matham%2Fpi_waveshare_adc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matham%2Fpi_waveshare_adc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matham%2Fpi_waveshare_adc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matham%2Fpi_waveshare_adc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matham","download_url":"https://codeload.github.com/matham/pi_waveshare_adc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248018070,"owners_count":21034048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T11:33:43.051Z","updated_at":"2025-04-09T10:14:40.846Z","avatar_url":"https://github.com/matham.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"pi_waveshare_adc\n================\n\nA performant Python library to read the Raspberry Pi Waveshare ADC expansion board.\n\nComplete documentation is `here \u003chttps://matham.github.io/pi_waveshare_adc/index.html\u003e`_\n\n.. image:: https://img.shields.io/pypi/pyversions/pi_waveshare_adc.svg\n    :target: https://pypi.python.org/pypi/pi_waveshare_adc/\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/v/pi_waveshare_adc.svg\n    :target: https://pypi.python.org/pypi/pi_waveshare_adc/\n    :alt: Latest Version on PyPI\n\n.. image:: https://coveralls.io/repos/github/matham/pi_waveshare_adc/badge.svg?branch=master\n    :target: https://coveralls.io/github/matham/pi_waveshare_adc?branch=master\n    :alt: Coverage status\n\n.. image:: https://github.com/matham/pi_waveshare_adc/workflows/Python%20application/badge.svg\n    :target: https://github.com/matham/pi_waveshare_adc/actions\n    :alt: Github action status\n\nIntroduction\n-------------\n\n``pi_waveshare_adc`` is a Python 3+ library for controlling and sampling the Raspberry Pi\n`Waveshare High-Precision AD/DA Expansion Board \u003chttps://www.waveshare.com/wiki/High-Precision_AD/DA_Board\u003e`_\nbuilt around the 8-channel 24 bit 30Khz `ADS1256 \u003chttps://www.ti.com/product/ADS1256\u003e`_ ADC.\n\nIt is based on the `PiPyADC \u003chttps://github.com/ul-gh/PiPyADC/\u003e`_ library, but has been internally converted\nto Cython for C performance to achieve full 30Khz sampling. Additionally, it supports\neither the `WiringPi \u003chttps://github.com/WiringPi/WiringPi\u003e`_ or a new\n`PiGPIO \u003chttps://github.com/joan2937/pigpio\u003e`_ backend, now that WiringPi has been deprecated.\nFinally, it has a more Pythonic API and has been better proofed against reading corrupted\nsamples (although it's still impossible to fully guarantee since the RPi is not a real-time system).\n\nThis library has been tested on the RPi4 and should similarly work on the RPi3. It relies on the\nmultiple cores to be able to sample at full 30kHz. Because at sustained 30kHz, one core is fully\nengaged. So on older RPis will less cores it may not function well. However, sampling at lower\nfrequencies (``\u003c 1kHz``) is much gentler on the CPU (see class docs for CPU sleep details).\n\nInstallation\n-------------\n\n* To install ``pi_waveshare_adc``, ensure python and pigpio is installed properly with\n  (WiringPi should be pre-installed, otherwise please install it from source)::\n\n      sudo apt install python3 python3-dev python3-pip python3-pigpio pigpio\n\n* Install ``pi_waveshare_adc`` with::\n\n      python3 -m pip install pi_waveshare_adc\n      # or until the next release to pypi you can get it directly from github with\n      python3 -m pip install https://github.com/matham/pi_waveshare_adc/archive/refs/heads/master.zip\n\n* Ensure the SPI interface is enabled on the RPi by running ``sudo raspi-config`` and enabling it\n  in the interfaces option.\n\nBackends\n--------\n\nThere are two backends ``pigpio`` or ``wiringpi`` selected by instantiating the ``WiringPiADS1256``\nor ``PiGPIOADS1256`` class, respectively.\n\nIn testing on the RPI4, the ``pigpio`` was significantly faster than the ``wiringpi`` backend (more than\n3x faster on SPI, slightly slower reading the GPIO). Consequently, it is able to sample at higher\nfrequencies and more consistently achieve ``30kHz``.\n\nUnfortunately, to use ``pigpio``, Python needs to be run with ``sudo`` permissions because we\nuse ``pigpio`` directly for better performance rather than the daemon. If you get the following\nerror::\n\n    2020-09-02 01:44:41 initCheckPermitted:\n    +---------------------------------------------------------+\n    |Sorry, you don't have permission to run this program.    |\n    |Try running as root, e.g. precede the command with sudo. |\n    +---------------------------------------------------------+\n\nIt means you forgot to use sudo. So use e.g.::\n\n    sudo python3 example.py\n\nUsage\n-----\n\nHardware pin configuration must be\nset up before initialization phase and can not be changed later.\n\nRegister/Configuration Flag settings are initialized, but these\ncan be changed during runtime via class properties.\n\nHigher performance chunked sampling\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSee.\n\nPerformance and Data Corruption Considerations\n----------------------------------------------\n\nData could be corrupt if it's taking too long to read e.g. if the pi\nhiccups and sampling rate is too large and we read while data is updated.\nThis is especially the case when muxing.\n\nOur sleep has minimum about 100 us resolution. So e.g. at 30kHz, we can't\nafford to sleep while waiting for the input to change, because the time\nbetween samples is 1 / 30kHz = 33us so if we sleep we'll miss samples.\nEven at 1kHz sampling, we only have 1000us between samples or about 8-9\nsleep cycles. So if we sleep too long, by the time we finish reading the\nsample the next sample may already be converted and our read value would be\ncorrupted.\n\nConsequently, we only sleep if the sampling rate is less than 500Hz.\nBecause with 2000 us between samples we have 15-20 sleep cycles available,\nso the risk is much much less.\n\nThe consequence is that when sampling above 500Hz, the CPU will not get\nany sleep if we do e.g. chunked reading. This is not a problem on e.g. a pi\n4 with 4 cores. :attr:`do_data_ready_delay` controls this behavior.\nIf the rate is less than or equal to 500Hz and :attr:`do_data_ready_delay`\nis True (the default) then we do a minimum sleep while waiting. Otherwise,\nwe never sleep.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatham%2Fpi_waveshare_adc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatham%2Fpi_waveshare_adc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatham%2Fpi_waveshare_adc/lists"}