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

[TW#12146] ADC2 driver (IDFGH-845) #461

Open
FFtust opened this issue Mar 27, 2017 · 35 comments
Open

[TW#12146] ADC2 driver (IDFGH-845) #461

FFtust opened this issue Mar 27, 2017 · 35 comments
Labels
Type: Feature Request Feature request for IDF

Comments

@FFtust
Copy link

FFtust commented Mar 27, 2017

     The ADC driver API currently only supports ADC1 channels,but if I want to use ADC2 channels , how should I do?
@ESP32DE
Copy link
Contributor

ESP32DE commented Mar 28, 2017

@FFtust
recommend you this steps:
first, download the technical reference for esp32

study the register and compare the thing with adc1.

then check the header for adc

right, you see, there is just in time only support adc1

then look up in the c file for , where adc is at home
and right again, you see, that adc1 is only supported just in time.

if you can not wait for official support adc2 then you must do this steps:

  1. look up which pins are have adc2 supported function

  2. add in adc header file your enum for this as adc2 type pins , example for new adc2_channel_t

  3. add in adc header file 3 (api) function declaration

  • esp_err_t adc2_config_width(adc_bits_width_t width_bit);
  • esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten);
  • int adc2_get_voltage(adc2_channel_t channel);
  1. add in rtc_module.c the definition for this, a good example are the adc1 function'see

...
it looks like this then when finished

everything too much trouble?, then here you are welcome to test this repo

how should I do

like this - and in the followed PR is a demo code for you - and an output that the adc2 is working for you - how cool is that ? 👍

pullrequest is done.
#466

hope this helps
best wishes
rudi ;-)

@YanMinge
Copy link

Well done, just need it.

@OldCharter
Copy link

For me adc2 works fine until I enable wifi. adc2 stops working then. Same issue when using the esp32-arduino libraries. Could this be the reason why adc2 isn't available in esp-idf?

@igrr
Copy link
Member

igrr commented Apr 1, 2017

Exactly! WiFi driver uses some of the ADC2 circuitry. So the code in the PR can indeed be used when WiFi/BT are disabled, otherwise controlling ADC2 from software may interfere with WiFi.

Supporting simultaneous WiFi and ADC2 operation is not something we have plans to support, for now. We will however add an ADC2 driver which may be used if WiFi is not in use.

@CarlosGS
Copy link

CarlosGS commented Apr 1, 2017

Quoting @20leunam: "Then we will chop off the antenna, and plug an external bluetooth module to TX/RX!" :)
I agree it is a pity to discard so many analog pins. This will limit many applications of ESP32.

Do you think it may at least be possible to live-disable WiFi momentarily, in order to measure ADC2, and re-enable wireless it afterwards? Or is the adc2 locked at boot time?

@igrr
Copy link
Member

igrr commented Apr 1, 2017

Yes, this should be possible. We'll need to make sure that WiFi/PHY initialization code resets all the ADC2 registers into the expected state during initialization (this may not be the case now), but aside from that, disabling WiFi (using esp_wifi_stop/esp_wifi_deinit) to do the measurement should be possible.

@ESP32DE
Copy link
Contributor

ESP32DE commented Apr 1, 2017

Would like to do that very much, too.
Only we unfortunately do not know what exactly is done under the api commands, esp_wifi_stop/esp_wifi_deinit Since they are packed in the lib.
So sometimes we can only wait or do it ourselves.
or pack third party code now in libs too :)
honest: libs are bad if src is not available and counterproductive
It is my personal opinion

@negativekelvin
Copy link
Contributor

I agree it is a pity to discard so many analog pins. This will limit many applications of ESP32.

Yes possibly down to two if you use pre amp and 32khz. Would be nice to have even low rate async adc2 read possible in cooperation with the WiFi driver.

@igrr igrr added the Type: Feature Request Feature request for IDF label Apr 5, 2017
@igrr igrr changed the title ESP-IDF can not use ADC2 channels! ADC2 driver Apr 5, 2017
@CarlosGS
Copy link

I am trying to read from ADC2 after enabling and disabling wifi. So far I've tested multiple combinations of esp_wifi_stop, esp_wifi_deinit, esp_phy_rf_deinit to disable the wifi driver.
The test set up is a pull down resistor in ADC GPIO26, which properly reads as "0" until wifi is started.

Since @igrr mentioned restoring back ADC registers to default state, I've also force re-run the ADC initialization routines in Arduino-ESP32, after wifi had been disabled.
This did not help: reading back from ADC2 pins always returns 4095. Maybe I'm missing other ADC registers?
Using rtc_gpio_init had no effect either.

I've run out of ideas. Please let me know if you think of other ways to achieve this. I'd be happy to test them!

@FayeY FayeY changed the title ADC2 driver [TW#12146] ADC2 driver May 1, 2017
@CarlosGS
Copy link

CarlosGS commented May 5, 2017

I'm making a connected sensor that uses most of the ADC pins, and for the moment my approach is going to consist in:

  • Read from the ADC.
  • Then turn wifi ON to send the values.
  • Finally self-restart the board, with wifi disabled (restoring the possibility to read from ADC2).

This is very ugly. So I am hoping it will be possible to achieve it in a clean way at some point :)

@HardwireIO
Copy link

Can we have a clarification about ADC2, please?

Is it a matter of an hardware limitation and WiFi cannot work together with ADC2, or simply there's no support for ADC2 right now?

Can we expect to have ADC2 available in the future or it's simply impossible?

@igrr
Copy link
Member

igrr commented May 11, 2017

ADC2 can be used together with WiFi on a time sharing basis. I.e. WiFi stack uses ADC2 for its own purposes, but also allows the application to poll ADC2 using some API. Such scheme is not implemented yet, and will not be part of the upcoming release.

@CarlosGS
Copy link

What about using esp_wifi_stop/esp_wifi_deinit to do the measurement, do you advise to wait until the proper driver is ready?

@frax84
Copy link

frax84 commented Jun 5, 2017

Hello,
i would like to know if the same limitation is valid for BT too or just WiFi. I'm asking this because of a similar issue:

Fyi, we're a bit hesitant to make ADC2 available because it is also used for pretty important control loops inside the WiFi (and maybe BT, I don't remember) drivers. We want to make sure there's no chance of these and the user ADC calls to interfere with each other.

The answer will influence my project design. Waiting for a feedback!

@adrianM27
Copy link

adrianM27 commented Jul 19, 2017

Hello,
@igrr could you specify which ADC2 channels are used by WiFi. On our custom board, we met with a problem of establishing a connection with AP (APs scan is working fine). At the same time, we are using pins with ADC2 func for other purposes like uart, digital out and in. We tried wifi example on our board (is not working) and Esp Wroom (is working). I know there might be several other reasons, but it will help to cut off ADC2 related suspicions. Thanks in advance!

@igrr
Copy link
Member

igrr commented Jul 19, 2017

None of the ADC2 channels connected to external pads are used by WiFi driver. There is a mux which is used to connect other internal signals to ADC2 input. Digital pins connected to ADC2 pins should not have any effect on WiFi.

@enitalp
Copy link

enitalp commented Aug 30, 2017

"Such scheme is not implemented yet, and will not be part of the upcoming release."
So igrr, any hope it will be implemented any time soon. It's really, really important for us. Thanks

@krzychb krzychb mentioned this issue Sep 7, 2017
@Yuggo1
Copy link

Yuggo1 commented Oct 3, 2017

Hi, i want to use the adc1 and adc2 channels from esp32 integrated with the bluetooth, i'm using the spp_counter from bluekitchen as a base code, this is the repo with the code:
https://github.com/Yuggo1/ESP_Gloves
The code to support the adc2 i've got from here ESP32DE/esp-idf@f467f68
and it works when using it without the bluetooth, but i'm getting the same problem from this issue using the bluetooth, does anyone know if ADC2 conflicts with bluetooth using spp?

Best Regards

@igrr igrr closed this as completed in d30f3e7 Oct 30, 2017
@whizkid79
Copy link

Sorry if this is a stupid question, but d30f3e7 only contains test code as far as I see. Are there further changes to use adc2 in connection with wifi?

@negativekelvin
Copy link
Contributor

Doesn't seem like what would expected from coexistence

@igrr
Copy link
Member

igrr commented Oct 31, 2017 via email

@whizkid79
Copy link

Is there another issue I can watch to get notified on coexistence?
Couldn't find one.

@igrr igrr reopened this Oct 31, 2017
@igrr
Copy link
Member

igrr commented Oct 31, 2017

Let's keep this one open until coexistence with WiFi is available.

@whizkid79
Copy link

Thanks a lot @igrr

@surumadurum
Copy link

I know it's annoying, but: Is there a time-estimate on when coexistence will be available?
Are we talking about weeks or months?
Thanks!

@MichaelEL65
Copy link

I'm finding my use limited by this issue too. I wasn't using WiFi for my project but BLE, and apparently it runs into the same problem.

@whizkid79
Copy link

Anything new here? Would be a nice christmas present ;)

@Ellipsis753
Copy link

Ellipsis753 commented Jan 15, 2018

I'm also very interested in an estimated release date of this feature (ADC2 and WiFi at once).

Additionally, I don't think this limitation is documented in the datasheet at the moment. It would be great if it could be! I've got an otherwise production ready design on my desk that I'm going to have to re-route as I didn't notice this limitation ahead of time.

EDIT: As per this forum post: https://www.esp32.com/viewtopic.php?f=2&t=4220&p=19084 it's likely to be supported in version 3.1, releasing around early/mid March. Hurrah!

@dubkov
Copy link

dubkov commented May 21, 2018

Hi! I've just got stuck with exactly the same problem with BLE. I have 16 ADCs running from ADC1 and ADC2 banks. They all work as expected till the moment when I initialize BLE - then suddenly all 10 ADCs from bank ADC2 stop working but ADCs from 1st bank work as usual. It is crucial to me to have 16 ADCs and BLE to function alltogether. Is there any chance to get them work simultaniously?

@whizkid79
Copy link

Anything new on this topic?

@superman13
Copy link

Hi, I have a problem like this one...
When I power up my module i receive valid data from ADC2.
After data was received I start wifi and send them via wifi and going to deep sleep.
After waking up I read permanently 4095 till I trigger an reset...
ULP is also working
PS. Before going to deep sleep I call esp_wifi_stop();

@Alvin1Zhang
Copy link
Collaborator

@liuzfesp Hi, would you help share if any updates? Thanks.

@github-actions github-actions bot changed the title [TW#12146] ADC2 driver [TW#12146] ADC2 driver (IDFGH-845) Mar 22, 2019
0xFEEDC0DE64 pushed a commit to 0xFEEDC0DE64/esp-idf that referenced this issue May 5, 2021
@CarlosGS
Copy link

In order to fix espressif/arduino-esp32#102 (comment) we would just need a method that allows to reset the ADC2 without having to reset the whole board. Any chance to achieve this, or is it a silicon bug?

@joko2020
Copy link

The Issue ** still exist until 2021 ** more than 4 year..
today i implemented suggestion from https://github.com/espressif/arduino-esp32/issues/102#issuecomment-611307887 but still did not worked
`
#include <WiFi.h>
#include "soc/sens_reg.h" // needed for manipulating ADC2 control register
uint64_t reg_b; // Used to store ADC2 control register
#define PIN 27 // Substitute xx with your ADC2 Pin number
int value;
int adc2[]={25,26,27,14,12,13,15,2,4};
const char* ssid = "private";
const char* password = "private";

void setup() {
// Save ADC2 control register value : Do this before begin Wifi/Bluetooth
reg_b = READ_PERI_REG(SENS_SAR_READ_CTRL2_REG);
//Wifi.Begin(); // or similar wifi init function or Bluetooth begin()
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}

void loop() {
for(int i=0;i<8;i++)
{
WRITE_PERI_REG(SENS_SAR_READ_CTRL2_REG, reg_b);
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV);
value = analogRead(adc2[i]);
Serial.print(adc2[i]);
Serial.print("=");
Serial.print(value);
Serial.print(",");
}
Serial.println("");
delay(500);
}

`

@NRollo
Copy link

NRollo commented Dec 13, 2022

As this issue is still open and the fact that I needed both the wifi and the ADC2 on my ESP32 project, I started testing on some of the ESP-IDF examples. I wanted to sample on the ADC2, start and communicate on the wifi, close and cleanup the wifi and then start all over. The aim was not having to re-boot the system when switching from analog to digital conversion, on ADC2, to communicating on wifi and vice versa.
The demo example is build around the 'wifi station' example and the 'ADC2' example. Have a look at WiFi and ADC2 if you can live with ADC2 and wifi working, not side by side, but sequentially (I could).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests