How to receive signals from multiple IR LEDs ?

Hello everyone, I have a project related to IR LEDs. I have implemented signal transmission through IR LEDs, and my transmitting IR LED is working fine. However, when it comes to receiving with 4 IR LEDs, I encounter the error: (76442) gptimer: gptimer_start(348): timer is not enabled yet. What should I do to resolve this issue? I am using the ESP32-S2 Mini and the VS1838B as the IR receiver. Apologies for my poor English, and thank you for using ChatGPT to help me with the translation. Thank you.

#include <IRL_Decode.h>
#include <IRL_Hash.h>
#include <IRL_Keycodes.h>
#include <IRL_Nec.h>
#include <IRL_NecAPI.h>
#include <IRL_Panasonic.h>
#include <IRL_Platform.h>
#include <IRL_Protocol.h>
#include <IRL_Receive.h>
#include <IRL_Time.h>
#include <IRLremote.h>

#include <Arduino.h>
#include <IRremote.hpp>

#define RECEIVERS 4 // Số lượng cảm biến
const uint8_t IR_RECEIVE_PIN[] = {3, 4, 5, 6}; // Chân IR receivers

decode_results results;

void setup() {
    Serial.begin(115200,SERIAL_8N1,16,18);
    Serial.println("IR Receiver Ready");
    // Khởi tạo tất cả các chân cảm biến làm đầu vào
    for (uint8_t i = 0; i < RECEIVERS; i++) {
        pinMode(IR_RECEIVE_PIN[i], INPUT);
    }

    // Bắt đầu nhận trên chân đầu tiên
    
    IrReceiver.begin(IR_RECEIVE_PIN[0]); 
    IrReceiver.enableIRIn();
    Serial.println("IR Receiver Ready");
}

void loop() {
    for (uint8_t i = 0; i < RECEIVERS; i++) {
        IrReceiver.begin(IR_RECEIVE_PIN[i]); 
        if (IrReceiver.decode()) {
            Serial.print("Receiver ");
            Serial.print(i);
            Serial.print(": ");
            Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
            IrReceiver.resume(); // Tiếp tục nhận tín hiệu
        }
        delay(200);
    }

    delay(100); // Đợi trước khi chuyển sang receiver tiếp theo
}

Please explain how you think this program should work, given that it can listen to only one channel at a time.

Please also explain how are the receive channels distinguished from each other, and how the IR transmitters are distinguished from each other.

I am using multiple IR LEDs to transmit signals, with each LED assigned a specific code from LED0 to LED11 corresponding to ABC0 to ABC11, based on the following code:

#include <Arduino.h>
#define DECODE_DISTANCE_WIDTH
#include <IRremote.hpp>

// Các chân sử dụng để truyền tín hiệu
const uint8_t sendPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13}; 
#define NUM_LEDS 12 // Số LED cần truyền tín hiệu

// Cấu trúc NEC timing
DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = {2400, 600, 600, 1200, 600};
uint8_t sNumberOfBits = 16; // Dữ liệu cần truyền có 16 bit

// Hàm tạo mã dữ liệu ghép 0xABC với số LED
IRRawDataType createLedData(uint8_t ledIndex) {
    return (0xABC << 4) | ledIndex; // Ghép 0xABC (12 bit) với số LED (4 bit)
}

void setup() {
    Serial.begin(115200, SERIAL_8N1, 17, 15);
    // Khởi tạo tất cả chân là OUTPUT
    pinMatrixOutDetach(9, false, false); // Tách GPIO9 khỏi FSPI
    pinMatrixOutDetach(10, false, false); // Tách GPIO10 khỏi FSPI
    pinMatrixOutDetach(11, false, false); // Tách GPIO9 khỏi FSPI
    pinMatrixOutDetach(13, false, false); // Tách GPIO10 khỏi FSPI

    for (uint8_t i = 0; i < NUM_LEDS; i++) {
        pinMode(sendPins[i], OUTPUT);
    }


    Serial.println("System initialized!");
}

void loop() {
    for (uint8_t i = 0; i < NUM_LEDS; i++) {
        // Khởi tạo lại IrSender cho mỗi chân IR
        IrSender.begin(sendPins[i]);

        // Tạo dữ liệu cho LED hiện tại
        IRRawDataType ledData = createLedData(i);

        // Gửi tín hiệu IR
        Serial.print("Sending to LED ");
        Serial.print(i);
        Serial.print(": 0x");
        Serial.println(ledData, HEX);

        IrSender.sendPulseDistanceWidthFromArray(
            38, &sDistanceWidthTimingInfo, &ledData,
            sNumberOfBits, PROTOCOL_IS_LSB_FIRST, 100, 0
        );
        delay(50);
    }
}

I want the receiving IR LEDs to decode and match the transmitted signals to their corresponding codes. To achieve this, I programmed the receiver to read one signal at a time. However, in my receiver code, whenever I use the line IrReceiver.enableIRIn();, I encounter the following error displayed on the serial monitor: (21942) gptimer:
gptimer_start(348): timer is not enabled yet
. Does this error have anything to do with my ESP32 S2 Mini?

First, make sure that basic code works with one receiver and any of the transmitters.

You still haven't explained why having four receivers is important, or how they should work.

Initially, I have been able to transmit using multiple IR LEDs and a single IR receiver, but I have not yet managed to transmit using multiple IR LEDs and multiple IR receivers.

Why Four Receivers?
The use of 4 IR receivers in the automatic can dispenser allows the system to accurately identify cans, even if they are off-center or misaligned, and prevents dispensing errors caused by limited coverage or missed signals.

How They Work in This Code?
Each receiver is connected to a specific pin defined in the IR_RECEIVE_PIN array.
In the loop() function, the code sequentially activates each receiver using IrReceiver.begin() and checks if it has decoded an IR signal. If a signal is detected, it is printed along with the index of the receiver (Receiver 0, Receiver 1, etc.). A small delay (delay(200)) is added after processing each receiver to ensure the system is ready to handle the next receiver.

Please post the code that works correctly, so forum members can see what you might have done wrong in adding the other receivers.

Sounds like break beam/retroreflective IR approach.
What's the point of using IRremote, library for remote controls sending and receiving parameters?

This is the code for transmitting using an IR LED:

#include <Arduino.h>
#define DECODE_DISTANCE_WIDTH
#include <IRremote.hpp>

// Các chân sử dụng để truyền tín hiệu
const uint8_t sendPins[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13}; 
#define NUM_LEDS 12 // Số LED cần truyền tín hiệu

// Cấu trúc NEC timing
DistanceWidthTimingInfoStruct sDistanceWidthTimingInfo = {2400, 600, 600, 1200, 600};
uint8_t sNumberOfBits = 16; // Dữ liệu cần truyền có 16 bit

// Hàm tạo mã dữ liệu ghép 0xABC với số LED
IRRawDataType createLedData(uint8_t ledIndex) {
    return (0xABC << 4) | ledIndex; // Ghép 0xABC (12 bit) với số LED (4 bit)
}

void setup() {
    Serial.begin(115200, SERIAL_8N1, 17, 15);
    // Khởi tạo tất cả chân là OUTPUT
    pinMatrixOutDetach(9, false, false); // Tách GPIO9 khỏi FSPI
    pinMatrixOutDetach(10, false, false); // Tách GPIO10 khỏi FSPI
    pinMatrixOutDetach(11, false, false); // Tách GPIO9 khỏi FSPI
    pinMatrixOutDetach(13, false, false); // Tách GPIO10 khỏi FSPI

    for (uint8_t i = 0; i < NUM_LEDS; i++) {
        pinMode(sendPins[i], OUTPUT);
    }


    Serial.println("System initialized!");
}

void loop() {
    for (uint8_t i = 0; i < NUM_LEDS; i++) {
        // Khởi tạo lại IrSender cho mỗi chân IR
        IrSender.begin(sendPins[i]);

        // Tạo dữ liệu cho LED hiện tại
        IRRawDataType ledData = createLedData(i);

        // Gửi tín hiệu IR
        Serial.print("Sending to LED ");
        Serial.print(i);
        Serial.print(": 0x");
        Serial.println(ledData, HEX);

        IrSender.sendPulseDistanceWidthFromArray(
            38, &sDistanceWidthTimingInfo, &ledData,
            sNumberOfBits, PROTOCOL_IS_LSB_FIRST, 100, 0
        );
        delay(50);
    }
}

This is the code for receiving:

#include <Arduino.h>
#include <IRremote.hpp>

const uint8_t IR_RECEIVE_PIN = 3;

void setup() {
    Serial.begin(115200,SERIAL_8N1,16,18);
    IrReceiver.begin(IR_RECEIVE_PIN); 
    IrReceiver.enableIRIn();
    Serial.println("IR Receiver Ready");
}

void loop() {
        if (IrReceiver.decode()) {
            Serial.print("Receiver ");          
            Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
            IrReceiver.resume(); // Tiếp tục nhận tín hiệu
        }
    }

Currently, the code works only when there is a single IR receiver. I want to add multiple IR receivers. How can I implement this?

@buithanhtai Would you mind answering this question? So far, nothing about your project makes much sense.

The boss's requirements. :=)

OK, have fun.

No library supports more than 1 receiver simultaneously.
Tell your boss, that you have to extent a library manually to cover his requirements, and that this will cost...

THANK YOU FOR YOUR HELP.

IR receivers are generally very sensitive not very directional. How are you intending to shield these so only the correct receiver is matched to a transmitter ?
If the transmitter(s) is/are so designed that, at any one time, only one transmission is in progress, then only one IR receiver is necessary. That should be simple if the transmitter sends also its ID in the payload.
If you have multiple instances of a transmitter, then you have to synchronise these so that two transmissions cannot clash with each other.