2022-04-14 06:16:24 +02:00
|
|
|
MCP3008 8-Channel 10-Bit A/D Converter
|
|
|
|
======================================
|
2020-06-15 03:42:42 +02:00
|
|
|
|
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up MCP3008 10 Bit Analog to Digital Converter in ESPHome.
|
2021-01-13 19:33:24 +01:00
|
|
|
:keywords: MCP3008
|
2021-11-16 03:19:33 +01:00
|
|
|
:image: mcp3008.jpg
|
2020-06-15 03:42:42 +02:00
|
|
|
|
|
|
|
The Microchip Technology Inc. MCP3008
|
2021-05-03 12:55:12 +02:00
|
|
|
devices are successive approximation 10-bit Analog-to-Digital (A/D) converters with on-board sample and
|
2021-02-20 22:02:46 +01:00
|
|
|
hold circuitry.
|
2021-01-13 19:33:24 +01:00
|
|
|
|
|
|
|
.. figure:: images/mcp3008.jpg
|
|
|
|
:align: center
|
|
|
|
:width: 50.0%
|
|
|
|
|
2021-05-04 04:19:59 +02:00
|
|
|
.. _mcp3008-component:
|
2020-06-15 03:42:42 +02:00
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
Component/Hub
|
|
|
|
-------------
|
2020-06-15 03:42:42 +02:00
|
|
|
|
|
|
|
The MCP3008 component allows you to use MCP3008 8-Channel 10-Bit A/D Converter
|
|
|
|
(`datasheet <http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf>`__,
|
|
|
|
`Adafruit <https://www.adafruit.com/product/856>`__) in ESPHome.
|
|
|
|
It uses the :ref:`SPI Bus <spi>` for communication.
|
|
|
|
|
|
|
|
Once configured, you can use any of the 8 pins as
|
|
|
|
sensors for your projects.
|
|
|
|
|
2021-01-13 19:33:24 +01:00
|
|
|
|
2024-01-22 21:25:36 +01:00
|
|
|
Each pin will respond with a voltage calculated off of the ``reference_voltage`` (default is 3.3V).
|
|
|
|
It calculates the voltage by multiplying the ``reference_voltage`` by the value on the pin (basically the percentage of VREF).
|
2021-01-13 19:33:24 +01:00
|
|
|
|
2024-01-22 21:25:36 +01:00
|
|
|
Most configurations will establish the reference voltage by assigning it the value of VREF, which is located at pin 13 on the chip.
|
|
|
|
|
|
|
|
If you want just the scaled value you can use the read_data function:
|
2021-01-13 19:33:24 +01:00
|
|
|
``float MCP3008::read_data(uint8_t pin)``
|
|
|
|
|
2020-06-15 03:42:42 +02:00
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
mcp3008:
|
|
|
|
cs_pin: D8
|
2022-06-27 20:13:13 +02:00
|
|
|
id: my_mcp
|
2020-06-15 03:42:42 +02:00
|
|
|
|
|
|
|
# Example config of sensors.
|
|
|
|
# This is a NTCB3950 10K thermocoupler attached to pin 0
|
|
|
|
# of the MCP3008 with a 10K resistor as a voltage divider.
|
|
|
|
# See `resistance` and `ntc` platorms for other options
|
|
|
|
sensor:
|
|
|
|
- platform: mcp3008 # Attached to pin 0 of the MCP3008.
|
2021-01-13 19:33:24 +01:00
|
|
|
reference_voltage: 3.19
|
2020-06-15 03:42:42 +02:00
|
|
|
update_interval: 1s
|
2022-06-27 20:13:13 +02:00
|
|
|
mcp3008_id: my_mcp
|
2020-06-15 03:42:42 +02:00
|
|
|
id: freezer_temp_source
|
2021-01-13 19:33:24 +01:00
|
|
|
number: 0 # MCP3008 pin number
|
2020-06-15 03:42:42 +02:00
|
|
|
- platform: resistance
|
|
|
|
id: freezer_resistance_sensor
|
|
|
|
sensor: freezer_temp_source
|
|
|
|
configuration: DOWNSTREAM
|
|
|
|
resistor: 10kOhm
|
|
|
|
- platform: ntc
|
|
|
|
id: freezer_temp
|
|
|
|
sensor: freezer_resistance_sensor
|
|
|
|
calibration:
|
|
|
|
b_constant: 3950
|
|
|
|
reference_temperature: 25°C
|
|
|
|
reference_resistance: 10kOhm
|
|
|
|
name: Freezer Temperature
|
|
|
|
|
|
|
|
Configuration variables:
|
2024-01-22 21:25:36 +01:00
|
|
|
|
2020-06-15 03:42:42 +02:00
|
|
|
- **id** (**Required**, :ref:`config-id`): The id to use for this MCP3008 component.
|
2024-01-22 21:25:36 +01:00
|
|
|
- **cs_pin** (**Required**, int): The SPI cable select pin to use.
|
2020-06-15 03:42:42 +02:00
|
|
|
|
2021-02-20 22:02:46 +01:00
|
|
|
|
|
|
|
Sensor
|
|
|
|
------
|
|
|
|
|
|
|
|
The ``mcp3008`` sensor allows you to use your MCP3008 10-Bit A/D Converter sensors with ESPHome.
|
|
|
|
First, setup a :ref:`MCP3008 Hub <mcp3008-component>` for your MCP3008 sensor and then use this
|
|
|
|
sensor platform to create individual sensors that will report the voltage to Home Assistant.
|
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
|
2022-06-27 20:13:13 +02:00
|
|
|
- **mcp3008_id** (**Required**, :ref:`config-id`): The id of the parent MCP3008 component.
|
2024-01-22 21:25:36 +01:00
|
|
|
- **number** (**Required**, int): The pin number of the MCP3008.
|
2021-01-13 19:33:24 +01:00
|
|
|
- **reference_voltage** (*Optional*, float): The reference voltage. Defaults to ``3.3V``.
|
|
|
|
- **update_interval** (*Optional*, :ref:`config-time`): The interval to check the sensor. Defaults to ``1s``.
|
|
|
|
|
2020-06-15 03:42:42 +02:00
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
|
|
|
- :ref:`spi`
|
|
|
|
- :apiref:`mcp3008/mcp3008.h`
|
|
|
|
- :ghedit:`Edit`
|