nopnop2002 / esp-idf-mirf

nRF24L01 Driver for esp-idf
MIT License
59 stars 10 forks source link

How can I use this library to transmit audio sampled with i2s_read ? #7

Closed avidadearthur closed 1 year ago

avidadearthur commented 1 year ago

I am aware that here is not StackOverflow but I'm having a hard time finding resources online about this topic since most of the audio+nRF24 content is targeted to the Arduino IDE. Here's what I'm trying to do:

#if CONFIG_TRANSMITTER
void transmitter(void *pvParameters)
{
    size_t bytes_read;
    ESP_LOGI(pcTaskGetName(0), "Start");
    int i2s_read_len = (16 * 1024);
    char *i2s_read_buff = (char *)calloc(i2s_read_len, sizeof(char));
    uint8_t *i2s_write_buff = (uint8_t *)calloc(i2s_read_len, sizeof(char));
    i2s_adc_enable(I2S_CHANNEL_NUM);
    NRF24_t dev;
    Nrf24_init(&dev);
    uint8_t payload = sizeof(i2s_read_buff);
    uint8_t channel = 90;
    Nrf24_config(&dev, channel, payload);
    // Set the receiver address using 5 characters
    esp_err_t ret = Nrf24_setTADDR(&dev, (uint8_t *)"FGHIJ");
    if (ret != ESP_OK)
    {
        ESP_LOGE(pcTaskGetName(0), "nrf24l01 not installed");
        while (1)
        {
            vTaskDelay(1);
        }
    }

#if CONFIG_ADVANCED
    AdvancedSettings(&dev);
#endif // CONFIG_ADVANCED

    // Print settings
    Nrf24_printDetails(&dev);
    // Start ADC
    while (1)
    {
        // Read data from I2S bus, in this case, from ADC. //
        i2s_read(I2S_CHANNEL_NUM, (void *)i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
        // process data and scale to 8bit for I2S DAC.
        i2s_adc_data_scale(i2s_write_buff, (uint8_t *)i2s_read_buff, i2s_read_len);
        // i2s_write_buff needs to be the buffer that is sent via nr24l01.
        Nrf24_send(&dev, i2s_write_buff);
        vTaskDelay(10);
        if (Nrf24_isSend(&dev, 1000))
        {
            ESP_LOGI(pcTaskGetName(0), "sending audio data ...");
        }
        else
        {
            ESP_LOGW(pcTaskGetName(0), "sending failed ...");
        }
    }
}
#endif // CONFIG_TRANSMITTER

I'm getting the following output:

...
W (19498) NRF24: Maximum number of TX retries interrupt
W (19498) TRANSMITTER: sending failed ...
...

Do you have any suggestions for potential solutions/resources?

nopnop2002 commented 1 year ago

uint8_t payload = sizeof(i2s_read_buff);

The maximum payload of the nRF24L01 is 32 bytes.

avidadearthur commented 1 year ago

Even if I try to send one byte it doesn't work. Could I have broken something trying to send too much data too fast? I also posted the question here.

nopnop2002 commented 1 year ago
    uint8_t payload = 1;
    uint8_t channel = 90;

Payload size and channel must match between sender and receiver.

And the nRF24L01 needs a lot of current.

And it doesn't work properly with Chinese clone Si24R1.

Carefully look at the chip markings.

avidadearthur commented 1 year ago

I'm indeed using the Chinese clone and I might have mismatched the payload size at some point during my tests. Regarding the current requirements, I wasn't aware of that. Hopefully, this didn't mess up the dev board.