Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFi affects ADC1 raw data (IDFGH-6623) #8266

Closed
dizcza opened this issue Jan 20, 2022 · 6 comments
Closed

WiFi affects ADC1 raw data (IDFGH-6623) #8266

dizcza opened this issue Jan 20, 2022 · 6 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@dizcza
Copy link
Contributor

dizcza commented Jan 20, 2022

Environment

  • Development Kit: TTGO-T8-ESP32
  • Kit version: v1.7
  • Module or chip used: ESP32
  • IDF version: v5.0-dev tag (master branch has a websocket client example broken - I haven't bothered reporting this; that's why I've stuck to v5.0-dev; master branch has the same problem)
  • Build System: idf.py
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2) 8.4.0
  • Operating System: Ubuntu 20.04
  • Using an IDE?: Only to edit the code. The program was flashed from a terminal with the idf.py flash command.
  • Power Supply: USB

Problem Description

When WiFi is active, in particular, an ESP32 websocket client is sending data to a server, adc1_get_raw() returns wrong unrealistic values. ADC values are read from an analog SDP806 differential pressure sensor. Without the Wifi running, the ADC1 values are correct - near zero. When Wifi is active, I see outliers with huge (>1k) ADC1 raw values.

The analog sensor is connected to pin 35, ADC1 channel 7.

I'm aware of ADC limitations but they concert ADC2 only - I've read this part of the documentation carefully and intentionally chosen ADC1 to avoid WiFi-related conflicts. If there are limitations to ADC1, please add them to the docs.

Related issues

I first thought it's related to #7781, but Bluetooth, to my surprise, does NOT affect ADC1 readings. Only Wifi does.

This issue supplements #6682 though in my case the wifi does not get disconnected when I call adc1_get_raw() periodically.

Expected Behavior

adc1_get_raw() returns small values around zero when the WiFi is running.

Actual Behavior

adc1_get_raw() returns unrealistically large values when the WiFi is running.

Code to reproduce this issue

websocket_app_start() is taken from the websocket example https://github.com/espressif/esp-idf/tree/master/examples/protocols/websocket.

void task_send() {
     char data[512];
     
     while (1) {
            esp_websocket_client_send_bin(client, data, sizeof(data), portMAX_DELAY);
            vTaskDelay(pdMS_TO_TICKS(100));
     }
}


void app_main() {
    ...
    websocket_app_start()

    ESP_ERROR_CHECK(adc1_config_channel_atten(board->sdp.adc.channel, ADC_ATTEN_DB_11));
    adc1_config_width(ADC_WIDTH_BIT_12);
    esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, &m_adc_chars);

    xTaskCreatePinnedToCore(task_send, "task_send", 4096, NULL, 0, NULL, PRO_CPU_NUM);

    ...

    // A periodic timer is set up to poll ADC1 at 1000 Hz freq
    int adc_raw = adc1_get_raw(board->sdp.adc.channel);
    int aout_v = (int) esp_adc_cal_raw_to_voltage((uint32_t) adc_raw, &m_adc_chars);
    // aout_v values are printed

Full code:

  1. ADC1 readings: https://github.com/dizcza/esp32-sdpsensor/blob/dc6edd0b88562a05a875bffb4dbd0ddb8ff043cf/main/sdpsensor_adc.c#L66
  2. A websocket client sending data in another thread: https://github.com/dizcza/esp32-sdpsensor/blob/dc6edd0b88562a05a875bffb4dbd0ddb8ff043cf/main/record_sdp.c#L243

Other items if possible

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jan 20, 2022
@github-actions github-actions bot changed the title WiFi affects ADC1 raw data WiFi affects ADC1 raw data (IDFGH-6623) Jan 20, 2022
@jack0c
Copy link
Collaborator

jack0c commented May 20, 2022

@dizcza Can you try commit after f3adbf9

@dizcza
Copy link
Contributor Author

dizcza commented May 20, 2022

I don't have the module with me at the moment.
You are free to close the issue and if I find it's unresolved I could reopen it.
Thanks.

@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting and updates, feel free to reopen.

@clemrdh
Copy link

clemrdh commented Dec 5, 2024

I am having the exact same issue ATM

@piemanau
Copy link

@dizcza Have you tested it after this change? As discussed on this issue esp-rs/esp-idf-hal#468, I am still struggling.

@dizcza
Copy link
Contributor Author

dizcza commented Jan 15, 2025

@piemanau I haven't tested it in years. I no longer use WiFi + ADC1 in conjunction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

7 participants