SPRING SALE up to 20% OFF! (excludes trade customers)   •   FREE Standard Delivery for orders over £35 (ex VAT)
Knowledge Base

The AB Electronics UK Knowledge Base provides support solutions, tutorials and troubleshooting guides.

Knowledge Base

Using the ADC Differential Pi with Home Assistant on the Raspberry Pi

Adding up to 32 analogue channels to Home Assistant on your Raspberry Pi

Created 11/11/2023 | Last Updated: 30/07/2024

YOU WILL NEED THIS BOARD

42 available
Order a ADC Differential Pi Photo of ADC Differential Pi

ADC Differential Pi

8 Channel 18-bit Differential Analogue to Digital converter development board for the Raspberry Pi

£13.59 ex VAT

This tutorial will setup the ADC Differential Pi to use with Home Assistant Operation System on your Raspberry Pi.

This custom component is designed to run the ADC Differential Pi Raspberry Pi development boards from AB Electronics UK with Home Assistant Operating System to add up to 32 analogue sensor inputs Home Assistant.

The ADC Differential Pi is an 8 channel 17 bit analogue to digital converter designed to work with the Raspberry Pi. The ADC Differential Pi is based on two Microchip MCP3424 A/D converters each containing 4 analogue inputs. This library uses our own ADC Differential Pi Python library from abelectronics.co.uk/kb/article/23/python-library-and-demos

This component will add a sensor with eight input voltages returned as attributes.

I2C Support Required

First you will need to enable I2C support in the Home Assistant Operating System, we have a tutorial to enable I2C.

Installation and Configuration

To be able to install the custom components for the ADC Differential Pi you need to be able to edit files in your configuration directory / folder.

We recommend using either the Samba add on or Studio Code Server which allows you to use Visual Code within Home Assistant.

Download the custom component from GitHub and extract to a directory on your computer.

  1. Using your tool of choice, open the directory (folder) for your HA configuration (where you find configuration.yaml).
  2. If you do not have a custom_components directory (folder) there, you need to create it.
  3. In the custom_components directory (folder) create a new folder called abelectronicsadcdifferentialpi.
  4. Copy all the files from the custom_components/abelectronicsadcdifferentialpi/ directory (folder) to the new abelectronicsadcdifferentialpi directory (folder).
  5. Restart Home Assistant

Using your HA configuration directory (folder) as a starting point you should now also have this:

custom_components/abelectronicsadcdifferentialpi/__init__.py
custom_components/abelectronicsadcdifferentialpi/sensor.py
custom_components/abelectronicsadcdifferentialpi/ADCDifferentialPi.py
custom_components/abelectronicsadcdifferentialpi/manifest.json

Example configuration.yaml

sensor:
  - platform: abelectronicsadcdifferentialpi
    name: ADCDifferentialPi
    i2c_address: 0x68
    i2c_address2: 0x69
    pga: 1
    bitrate: 18
    scan_interval: 5

Usage

Sensor Configuration Variables

The sensor component uses the following variables to configure the ADC sensor

Key Type Required Description
i2c_address Hex True This contains the I2C address of the ADC Differential Pi device. The default I2C addresses on the ADC Differential Pi are 0x68 and 0x69. This address selects inputs 1 to 4.
i2c_address2 Hex True This contains the I2C address of the ADC Differential Pi device. The default I2C addresses on the ADC Differential Pi are 0x68 and 0x69. This address selects inputs 5 to 8.
pga Integer True Set the gain of the PGA on the chip. 1, 2, 4 or 8.
bitrate Integer True This contains the selected bitrate for samples, this can be 12, 14, 16 or 18. Sample speeds for selected bit rate: 12 = 12 bit (240SPS max) 14 = 14 bit (60SPS max) 16 = 16 bit (15SPS max) 18 = 18 bit (3.75SPS max).
scan_interval Integer True This contains the scan interval in seconds between reading the device in seconds.

Editing the configuration.yaml file to add the binary sensor

Using the text editor of choice open the configuration.yaml for your HA configuration.

Add a new sensor with the following code:

sensor:
   - platform: abelectronicsadcdifferentialpi

Add the following attributes to setup the component:

name: ADCDifferentialPi
i2c_address: 0x68
i2c_address2: 0x69
pga: 1
bitrate: 18
scan_interval: 5

Add the template sensor for the component to access the attributes:

- platform: template
  sensors:
    adcdiffinput1:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input1}}"
      friendly_name: "ADC Differential Pi input 1"
      unit_of_measurement: "Volts"
    adcdiffinput2:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input2}}"
      friendly_name: "ADC Differential Pi input 2"
      unit_of_measurement: "Volts"
    adcdiffinput3:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input3}}"
      friendly_name: "ADC Differential Pi input 3"
      unit_of_measurement: "Volts"
    adcdiffinput4:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input4}}"
      friendly_name: "ADC Differential Pi input 4"
      unit_of_measurement: "Volts"
    adcdiffinput5:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input5}}"
      friendly_name: "ADC Differential Pi input 5"
      unit_of_measurement: "Volts"
    adcdiffinput6:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input6}}"
      friendly_name: "ADC Differential Pi input 6"
      unit_of_measurement: "Volts"
    adcdiffinput7:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input7}}"
      friendly_name: "ADC Differential Pi input 7"
      unit_of_measurement: "Volts"
    adcdiffinput8:
      value_template: "{{states.sensor.adcdifferentialpi.attributes.input8}}"
      friendly_name: "ADC Differential Pi input 8"
      unit_of_measurement: "Volts"

The completed YMAL code should look like this:

sensor:
  - platform: abelectronicsadcdifferentialpi
    name: ADCDifferentialPi
    i2c_address: 0x68
    i2c_address2: 0x69
    pga: 1
    bitrate: 18
    scan_interval: 5

  - platform: template
    sensors:
      adcdiffinput1:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input1}}"
        friendly_name: "ADC Differential Pi input 1"
        unit_of_measurement: "Volts"
      adcdiffinput2:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input2}}"
        friendly_name: "ADC Differential Pi input 2"
        unit_of_measurement: "Volts"
      adcdiffinput3:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input3}}"
        friendly_name: "ADC Differential Pi input 3"
        unit_of_measurement: "Volts"
      adcdiffinput4:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input4}}"
        friendly_name: "ADC input 4"
        unit_of_measurement: "Volts"
      adcdiffinput5:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input5}}"
        friendly_name: "ADC Differential Pi input 5"
        unit_of_measurement: "Volts"
      adcdiffinput6:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input6}}"
        friendly_name: "ADC Differential Pi input 6"
        unit_of_measurement: "Volts"
      adcdiffinput7:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input7}}"
        friendly_name: "ADC Differential Pi input 7"
        unit_of_measurement: "Volts"
      adcdiffinput8:
        value_template: "{{states.sensor.adcdifferentialpi.attributes.input8}}"
        friendly_name: "ADC Differential Pi input 8"
        unit_of_measurement: "Volts"

After a restart you can now add the sensor into the user interface.

Demo UI Cards

type: entities
entities:
  - entity: sensor.adcdiffinput1
  - entity: sensor.adcdiffinput2
  - entity: sensor.adcdiffinput3
  - entity: sensor.adcdiffinput4
  - entity: sensor.adcdiffinput5
  - entity: sensor.adcdiffinput6
  - entity: sensor.adcdiffinput7
  - entity: sensor.adcdiffinput8

Also useful for your Raspberry Pi project

Temperature & Sensing

1 Wire Pi Plus

Connect dozens of 1-Wire sensors - temperature, iButtons, EEPROMs - via a single GPIO pin. Stacks directly on the 40-pin header.

£9.59 ex VAT

Analogue I/O

ADC Pi

Read up to 8 analogue inputs - perfect for pairing with your temperature sensors or other analogue-output devices.

£14.39 ex VAT

All-in-one

Expander Pi

Combines ADC, DAC, 32 GPIO ports and a real-time clock on one board. The most versatile board for complex Raspberry Pi projects.

£15.99 ex VAT