2025-05-11 08:21:18 +03:00
2025-05-11 08:21:18 +03:00
2025-05-11 08:21:18 +03:00
2025-05-11 08:21:18 +03:00
2025-05-10 07:39:27 +03:00
2025-05-10 07:39:27 +03:00
2025-05-11 08:21:18 +03:00
2025-05-18 15:39:47 +03:00
2025-05-18 15:39:47 +03:00

ESP32 ESP-IDF and ESP8266 RTOS SDK component for CD74HC4067 16-channel analog multiplexer/demultiplexer

Tested on

  1. ESP8266 RTOS_SDK v3.4
  2. ESP32 ESP-IDF v5.4

Features

  1. Just an electronic galette switch between one of the 16 multiplexer GPIO and one ESP GPIO.
  2. Support of all standard operations (digital read/write, interrupt, ADC, PWM, etc).

Attention

  1. EN GPIO on CD74HC4067 must be connected to ESP.

Using

In an existing project, run the following command to install the components:

cd ../your_project/components
git clone http://git.zh.com.ru/alexey.zholtikov/zh_cd74hc4067

In the application, add the component:

#include "zh_cd74hc4067.h"

Examples

Digital read and write:

#include "zh_cd74hc4067.h"

void app_main(void)
{
    esp_log_level_set("zh_cd74hc4067", ESP_LOG_NONE); // For ESP8266 first enable "Component config -> Log output -> Enable log set level" via menuconfig.
    gpio_config_t pin_config = {
        .pin_bit_mask = (1ULL << GPIO_NUM_4)}; // Set control GPIO on ESP.
    gpio_config(&pin_config);
    zh_cd74hc4067_init_config_t init_config = {
        .control_gpio_number = GPIO_NUM_4,
        .en_gpio_number = GPIO_NUM_18,
        .s0_gpio_number = GPIO_NUM_19,
        .s1_gpio_number = GPIO_NUM_20,
        .s2_gpio_number = GPIO_NUM_21,
        .s3_gpio_number = GPIO_NUM_22,
    };
    zh_cd74hc4067_init(&init_config);
    gpio_set_direction(zh_cd74hc4067_pin(), GPIO_MODE_OUTPUT); // Set control GPIO on ESP to output.
    gpio_set_level(zh_cd74hc4067_set(10), 1);                  // Connect 10 GPIO on CD74HC4067 and set it to HIGH.
    zh_cd74hc4067_set(12);                                     // Connect 12 GPIO on CD74HC4067.
    gpio_set_direction(zh_cd74hc4067_pin(), GPIO_MODE_INPUT);  // Set control GPIO on ESP to input.
    bool level = gpio_get_level(zh_cd74hc4067_set(11));        // Connect 11 GPIO on CD74HC4067 and get it status.
    level = gpio_get_level(zh_cd74hc4067_pin());               // Get status of currently connected GPIO on CD74HC4067.
    uint8_t gpio = zh_cd74hc4067_get();                        // Get currently connected GPIO number on CD74HC4067.
}
Description
ESP32 ESP-IDF and ESP8266 RTOS SDK component for CD74HC4067 16-channel analog multiplexer/demultiplexer.
Readme Apache-2.0 297 KiB
Languages
C 98.8%
CMake 1.2%