2025-02-14 17:01:22 +03:00
2025-02-14 17:01:22 +03:00
2025-02-11 12:28:32 +03:00
2025-02-11 12:28:32 +03:00
2025-02-11 10:59:15 +03:00
2025-02-11 12:29:44 +03:00

relay_chn - Relay Channel Controller

An ESP-IDF component for controlling relay channels, specifically designed for driving bipolar motors through relay pairs.

Features

  • Controls multiple relay channel pairs (up to 8 channels)
  • Built-in direction change inertia protection
  • Automatic command sequencing and timing
  • Event-driven architecture for reliable operation
  • Forward/Reverse direction control
  • Direction flipping capability
  • State monitoring and reporting

Description

Each relay channel consists of 2 output relays controlled by 2 GPIO pins. The component provides APIs to control these relay pairs while ensuring safe operation, particularly for driving bipolar motors. It prevents short-circuits by automatically managing direction changes with configurable inertia timing.

Configuration

Configure the component through menuconfig under "Relay Channel Driver Configuration":

  • CONFIG_RELAY_CHN_OPPOSITE_INERTIA_MS: Time to wait before changing direction (200-1500ms, default: 800ms)
  • CONFIG_RELAY_CHN_COUNT: Number of relay channels (1-8, default: 1)

Installation

  1. Copy the component to your project's components directory
  2. Add dependency to your project's idf_component.yml:
dependencies:
  relay_chn:
    version: "^0.1.0"

Usage

1. Initialize relay channels

// Define GPIO pins for relay channels
const gpio_num_t gpio_map[] = {GPIO_NUM_4, GPIO_NUM_5};  // One channel example
const uint8_t gpio_count = sizeof(gpio_map) / sizeof(gpio_map[0]);

// Create and initialize relay channels
esp_err_t ret = relay_chn_create(gpio_map, gpio_count);
if (ret != ESP_OK) {
    // Handle error
}

2. Control relay channels

// Run channel 0 forward
relay_chn_run_forward(0);

// Run channel 0 reverse
relay_chn_run_reverse(0);

// Stop channel 0
relay_chn_stop(0);

// Flip direction of channel 0
relay_chn_flip_direction(0);

3. Monitor channel state

// Get channel state
relay_chn_state_t state = relay_chn_get_state(0);
char *state_str = relay_chn_get_state_str(0);

// Get channel direction
relay_chn_direction_t direction = relay_chn_get_direction(0);

License

MIT License - Copyright (c) 2025 kozmotronik.

Description
A custom ESP-IDF component for controlling up to 8 relay channels.
Readme MIT 1.7 MiB
1.0.0 Latest
2025-09-13 11:00:56 +02:00
Languages
C 96.8%
Shell 2.2%
CMake 1%