herosdevices.hardware.raspberrypi.waveshare
===========================================

.. py:module:: herosdevices.hardware.raspberrypi.waveshare

.. autoapi-nested-parse::

   Driver for Waveshare SBC/microcontroller extension boards.





Module Contents
---------------

.. py:class:: WaveshareADS1256(spi_bus: int = 0, spi_device: int = 0, rst_pin: int = 18, drdy_pin: int = 17, gain: int = 1, drate: str = '2000SPS', vref: float = 5.0, channel_name_map: dict[str, str] | None = None)

   Bases: :py:obj:`herosdevices.interfaces.atomiq.ADC`


   This class represents one channel of the Waveshare ADS1256 ADC board.

   .. note::
       Concurrent access to the SPI device is not possible. This means only one object with a given spi_bus
       and spi_device can exist.

   If you would like to access individual channels of this ADC consider creating objects of
   :class:WaveshareADS1256Channel in addition to an object of this class.

   :param spi_bus: number of the SPI bus
   :param spi_device: number of the SPI device in bus.
   :param gain: gain to set in the PGIA
   :param drate: conversion rate of the ADS1256. See .ads1256.ADS1256_DRATE for valid values
   :param vref: Reference voltage given to the ADC. Usually 3.3V or 5V
   :param samples: number of samples to average when sending out measured values as heros datasource
   :param channel_name_map: dict to map the internal names of the pin (AIN0...AIN7) to user-definable names. The names
                            are used if the operated as HEROS datasource. Example: {"AIN0": "my_voltage", "AIN2": "custom_sensor_3"}


   .. py:attribute:: gain


   .. py:attribute:: drate


   .. py:attribute:: vref
      :value: 5.0



   .. py:attribute:: channel_name_map


   .. py:attribute:: channel_name_map_reverse


   .. py:method:: get_samples(samples: int = 1, channel: str = '', neg_pin: str = 'AINCOM') -> list[float]

      Measure the given number of samples from the given channel.

      :param samples: Number of samples.
      :type samples: int
      :param channel: Name of the pin where the positive end of the voltage is applied
      :type channel: str
      :param neg_pin: Name of the pin where the negative end of the voltage is applied
      :type neg_pin: str

      :returns: Measured voltage in volts.
      :rtype: float



   .. py:method:: measure(samples: int = 1, channel: str = '', neg_pin: str = 'AINCOM') -> float

      Measure the voltage by averaging multiple ADC samples.

      :param samples: Number of samples to average.
      :type samples: int
      :param channel: Name of the pin where the positive end of the voltage is applied
      :type channel: str
      :param neg_pin: Name of the pin where the negative end of the voltage is applied
      :type neg_pin: str

      :returns: Measured voltage in volts.
      :rtype: float



.. py:class:: WaveshareADS1256Channel(waveshare_ads1256: WaveshareADS1256, pos_pin: str, neg_pin: str = 'AINCOM', samples: int = 1)

   Bases: :py:obj:`herosdevices.interfaces.atomiq.ADCChannel`


   A Single Channel of the Waveshare ADS1256 ADC board.

   :param waveshare_ads1256: Object or HERO of class WaveshareADS1256
   :param posPin: Name of the pin receiving the positive voltage. I.e. AIN0 ... AIN7 or AINCOM
   :param negPin: Name of the pin receiving the negative voltage. I.e. AIN0 ... AIN7 or AINCOM. For non-differential
                  measurements this is usually AINCOM.


   .. py:attribute:: adc


   .. py:attribute:: pos_pin


   .. py:attribute:: neg_pin
      :value: 'AINCOM'



   .. py:attribute:: samples
      :value: 1



   .. py:method:: measure(samples: int | None = None, cached: bool = False, channel: str = '') -> float

      Measure voltage at the current channel.

      :param samples: Number of samples to average.
      :param cached: not used
      :param channel: not used



