class platypush.plugins.gpio.sensor.mcp3008.GpioSensorMcp3008Plugin(CLK=None, MISO=None, MOSI=None, CS=None, spi_port=None, spi_device=None, channels=None, Vdd=3.3, *args, **kwargs)[source]

Plugin to read analog sensor values from an MCP3008 chipset. The MCP3008 chipset is a circuit that allows you to read measuremnts from multiple analog sources (e.g. sensors) and multiplex them to a digital device like a Raspberry Pi or a regular laptop. See for more info.


  • adafruit-mcp3008 (pip install adafruit-mcp3008)
__init__(CLK=None, MISO=None, MOSI=None, CS=None, spi_port=None, spi_device=None, channels=None, Vdd=3.3, *args, **kwargs)[source]

The MCP3008 can be connected in two modes:

  • Hardware SPI mode: advised if you have enough GPIO pins available
    (and slightly faster)
  • Software SPI mode: useful if you don’t have all the required GPIO
    PINs for hardware SPI available. Slightly slower, as the conversion is done via software, but still relatively performant.

See for info

  • CLK (int) – (software SPI mode) CLK GPIO PIN
  • MISO (int) – (software SPI mode) MISO GPIO PIN
  • MOSI (int) – (software SPI mode) MOSI GPIO PIN
  • CS (int) – (software SPI mode) CS GPIO PIN
  • spi_port (int) – (hardware SPI mode) SPI port
  • spi_device (str) – (hardware SPI mode) SPI device name
  • channels (dict) –

    name-value mapping between MCP3008 output PINs and sensor names. This mapping will be used when you get values through get_measurement(). Example:

    channels = {
        "0": {
            "name": "temperature",
            "conv_function": 'round(x*100.0, 2)'  # T = Vout / (10 [mV/C])
        "1": {
            "name": "light",  # ALS-PT9
            "conv_function": 'round(x*1000.0, 6)'  # ALS-PT9 has a 10 kOhm resistor

    Note that you can also pass a conversion function as conv_function that will convert the output voltage to whichever human-readable value you wish. In the case above I connected a simple temperature sensor to the channel 0 and a simple ALS-PT9 light sensor to the channel 1, and passed the appropriate conversion functions to convert from voltage to, respectively, temperature in Celsius degrees and light intensity in lumen. Note that we reference the current voltage as x in conv_function.

  • Vdd (float) – Input voltage provided to the circuit (default: 3.3V, Raspberry Pi default power source)

Returns a measurement from the sensors connected to the MCP3008 device. If channels were passed to the configuration, the appropriate sensor names will be used and the voltage will be converted through the appropriate conversion function. Example:

output = {
    "temperature": 21.0,  # Celsius
    "humidity": 45.1    # %

Otherwise, the output dictionary will contain the channel numbers as key and the row voltage (between 0 and 255) will be returned. Example:

output = {
    "0": 145,
    "1": 130
class platypush.plugins.gpio.sensor.mcp3008.MCP3008Mode[source]

An enumeration.