Updated Mcp3008 to support reference_voltage and voltage_sampler::VoltageSampler (#874)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
SenexCrenshaw 2021-01-13 13:33:24 -05:00 committed by Jesse Hills
parent e44eb01685
commit 334ae67f81
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
6 changed files with 29 additions and 17 deletions

View File

@ -41,7 +41,7 @@ Changelog - Version 1.15.0 - September 13, 2020
PID Controller, components/climate/pid, function.svg
IR Remote Climate, components/climate/ir_climate, air-conditioner-ir.svg
HTTP Request, components/http_request, connection.svg
MCP3008 8-Channel 10-Bit A/D Converter, components/mcp3008, mcp3008.png
MCP3008 8-Channel 10-Bit A/D Converter, components/mcp3008, mcp3008.jpg
SN74HC595 I/O Expander, components/sn74hc595, sn74hc595.jpg
TM1651 Battery Display, components/tm1651, tm1651_battery_display.jpg
RF Bridge, components/rf_bridge, rf_bridge.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -3,20 +3,17 @@ MCP3008 I/O Expander
.. seo::
:description: Instructions for setting up MCP3008 10 Bit Analog to Digital Converter in ESPHome.
:image: mcp3008.png
.. note::
This page is incomplete and could some work. If you want to contribute, please read the
:doc:`contributing guide </guides/contributing>`. This page is missing:
- An image for the front page.
- Formal documentation of the mcp3008 sensor entry (parent, update_interval, number, etc.)
- See Dallas sensor for reference model
:keywords: MCP3008
:image: images/mcp3008.jpg
The Microchip Technology Inc. MCP3008
devices are successive approximation 10-bit Analogto-Digital (A/D) converters with on-board sample and
hold circuitry. Each pin will respond with a 0-1023 result depending on the voltage it is reading
hold circuitry.
.. figure:: images/mcp3008.jpg
:align: center
:width: 50.0%
MCP3008
-------
@ -29,6 +26,14 @@ It uses the :ref:`SPI Bus <spi>` for communication.
Once configured, you can use any of the 8 pins as
sensors for your projects.
Each pin will respond with a voltage calculated off of the reference_voltage (default is 3.3v).
It calculates the voltage by multplying the reference_voltage * value on the pin (basically the percentage of VREF)
Most configurations will set the reference_voltage = VREF (pin 13 on the chip)
If you want just the scaled value you can use the read_data function
``float MCP3008::read_data(uint8_t pin)``
.. code-block:: yaml
# Example configuration entry
@ -41,10 +46,10 @@ sensors for your projects.
# See `resistance` and `ntc` platorms for other options
sensor:
- platform: mcp3008 # Attached to pin 0 of the MCP3008.
# The result will be a reading from 0-1023
reference_voltage: 3.19
update_interval: 1s
id: freezer_temp_source
number: 0 # pin number
number: 0 # MCP3008 pin number
- platform: resistance
id: freezer_resistance_sensor
sensor: freezer_temp_source
@ -61,14 +66,21 @@ sensors for your projects.
Configuration variables:
~~~~~~~~~~~~~~~~~~~~~~~~
MCP3008 Component
*****************
- **id** (**Required**, :ref:`config-id`): The id to use for this MCP3008 component.
- **cs_pin** (**Required**, int): The SPI cable select pin to use
MCP3008 Sensor Component
************************
- **id** (**Required**, :ref:`config-id`): The id of the parent MCP3008 component.
- **number** (**Required**, int): The pin number of the MCP3008
- **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``.
See Also
--------
- :ref:`spi`
- :apiref:`mcp3008/mcp3008.h`
- :ghedit:`Edit`

BIN
images/mcp3008.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

View File

@ -133,6 +133,7 @@ Sensor Components
MAX31856, components/sensor/max31856, max31856.jpg
MAX31865, components/sensor/max31865, max31865.jpg
MAX6675, components/sensor/max6675, max6675.jpg
MCP3008, components/sensor/mcp3008, mcp3008.jpg
MCP9808, components/sensor/mcp9808, mcp9808.jpg
MH-Z19, components/sensor/mhz19, mhz19.jpg
MPU6050, components/sensor/mpu6050, mpu6050.jpg
@ -356,7 +357,6 @@ Misc Components
PCF8574 I/O Expander, components/pcf8574, pcf8574.jpg
MCP230XX I/O Expander - I²C Bus, components/mcp230xx, mcp230xx.svg
MCP23SXX I/O Expander - SPI Bus, components/mcp23Sxx, mcp230xx.svg
MCP3008 8-Channel 10-Bit A/D Converter, components/mcp3008, mcp3008.png
SX1509 I/O Expander, components/sx1509, sx1509.jpg
SN74HC595 I/O Expander, components/sn74hc595, sn74hc595.jpg
SIM800L, components/sim800l, sim800l.jpg