Tech Note 069 - Using the ESP32 ADC and some of its more advanced functions

  Рет қаралды 72,135

G6EJD - David

G6EJD - David

Күн бұрын

Пікірлер: 215
@shahryarpasyar1481
@shahryarpasyar1481 Жыл бұрын
Your training videos are excellent with sufficient explanations and details. Dear friend, thank you very much for preparing these tutorials.
@deangreenhough3479
@deangreenhough3479 6 жыл бұрын
I have to say, I did enjoy this video. clear & concise explanation once again, a big thank you
@epiendless1128
@epiendless1128 2 жыл бұрын
Thanks for this. I must say I found the ADC pretty non-linear even in the allegedly linear region. The polynomial helped a lot, although it was still inaccurate below 0.5V. Fortunately I only need to measure battery voltage, and the polynomial greatly improved that.
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
Sir! You genius and great explanation and commments 🎉
@arifindobson
@arifindobson 5 жыл бұрын
Fantastic, super great! Thank you very much
@elektron2kim666
@elektron2kim666 4 ай бұрын
Quite helpful. On a battery voltage indicator code part and figuring out the graphics and the numbers. I do a whole battery drain and it's 6 hours now. Then I try to charge it up to 100%. When I can get a range of almost 100 units it goes into "a battery" picture of all, half or quarters (pixels). This makes it realistic. The last battery indicator (another device) gave a percentage from somewhere which didn't show in real life. By caring for the details it becomes useful. The "100 units" is from around 4.20v --> 3.20v as 3.00-3.20v is unreliable by turning up something like brightness, so a red warning thing can come a bit before that. I'm not even sure, if this device is turning off at 3.00v like the other device.
@paulpkae
@paulpkae Жыл бұрын
Just tried your code example and its certainly way more accurate. However it maxes out at 3.14V with one function or 3.17V with the other. I need to measure just over a 3.17V threshold, is there any simple tweak I can do?
@G6EJD
@G6EJD Жыл бұрын
It really, the ADC maximum input voltage is Vdd - 0.2v = 3.1v so you’d need to a voltage divider, then multiply the resultant reading by the multiplier. So say two resistors of 100K that would divide the input by 2 then simply multiply the result by 2. Input -100K-ADC-100K--Gnd
@paulpkae
@paulpkae Жыл бұрын
@@G6EJD thanks. I'm already using a voltage divider as my source signal is actually 0 to 5v range. I used a 100K and 200K to give me 2/3rds and then I multiply back up in my code. The device I'm monitoring is said to be in a fault state if the signal 4.8v. I didn't realise the ADC range is constrained by -0.2 as you say. I have an idea on how to fudge the code. Thanks again for the video and great advice.
@Darktron
@Darktron Жыл бұрын
Thanks for the video! I'm wondering how can I store or display the max/peak value from a voltage measurement just like the "Hold" function in a multimeter?
@G6EJD
@G6EJD Жыл бұрын
You can create a variable or two, one for max and one for min, then every time you take a reading test if (voltage > max) max = voltage; then for min, if (voltage < min) min = voltage; if you define the min, max variables in static ram then they remain until reset to repeat the process. To reset max = -100000; and min = 100000; you can then display the values with Serial.print(max) and repeat for min.
@Darktron
@Darktron Жыл бұрын
@G6EJD - David Thank you! My project looks so much better I've used alot of information from your videos they are very helpful🫡
@Darktron
@Darktron Жыл бұрын
@G6EJD - David You should revisit this with ESP32-S3 also have a look at analogReadMilliVolts function 🤝🏽
@freedom2000
@freedom2000 6 жыл бұрын
Thank you for this very clear video. However I am still unclear on the exact behavior of function "analogSetSamples". If we increase the number will the output be more "precise" with a kind of average done on several samples ? Thanks JP
@G6EJD
@G6EJD 6 жыл бұрын
This might help you out: en.m.wikipedia.org/wiki/Sampling_(signal_processing) What the setting does is increase the number of samples taken for any given readADC activity, but what I don't know and is not adequately explained by Espressif is what value is returned, but it is most likely to be the average of the samples taken. Let's say a signal being read during a reading activity and it fluctuates like this 1.200v, 1.201v then 1.195v then when analogsetsamples = 1 it would return 1.2v, then when analogsetsamples = 2, it would take 2 samples in the example 1.200 and 1.201 and return (with some quantisation error) (1.2+1.201)/2=1.2005v and then when increased to 3, the result returned would be (1.2+1.201+1.195)/3=1.198v. This effectively increases the sensitivity as it is more likely to detect small perturbations in the signal, that a single sample would not see, but don't confuse this with increased accuracy, it's just an increase in the sample size of the average value returned. The correct result is still 1.2 with one sample set and the result when 3 is set is a better result that is representative of all 3 samples. I find it is useful to test these concepts with extreme values, lets say a waveform, perhaps a sine wave is being sampled, but every so often the signal drops to zero, giving a spike in the waveform, sampling the waveform at discreet points could occur when the spike happens and give a zero result, but actually, a better result would be the average value around the spike say a sample before the spike and a sample after it, using setanalogsample = 3 would likely give a better result if the waveform value before the spike was 1.2v, then followed by a 0v spike then followed by 1.25v, the returned value would be 0.816v, it should have been somewhere between 1.2 and 1.25v on a sinewave, but it's better than 0v.Hope this helps.
@freedom2000
@freedom2000 6 жыл бұрын
@@G6EJD for sure it helps ! Thanks again for your help
@G6EJD
@G6EJD 6 жыл бұрын
You need to study signal processing techniques to get a full understanding.
@freedom2000
@freedom2000 6 жыл бұрын
@@G6EJD I do know these Technics. But as you said expressif is not clear on what they do with the various samples acquired !
@a.h.z2830
@a.h.z2830 3 жыл бұрын
Can you tell me where you found all these ADC value to input voltage graphs please? I couldn't manage to find any decent documentation about the adcs in the documentations.
@G6EJD
@G6EJD 3 жыл бұрын
They were all measured by me using my Fluke 87 by setting the input voltage and then reading the ADC value, all graphs were produced with excel.
@a.h.z2830
@a.h.z2830 3 жыл бұрын
@@G6EJD thank you for the reply
@HakAtIt
@HakAtIt 3 жыл бұрын
Excellent explanation, and super helpful. I'm a little confused on the attenuation. In the chart you show that ADC_0db @1v will read 1088, with a max range of 3v and 11db has 1v reading almost maxed out at 3959. However in the graph it shows the opposite, 0db with a max voltage of 1v.
@G6EJD
@G6EJD 3 жыл бұрын
I see what you mean, but at the time those tables were copied from the Espressif variants and it looks like they have been updated and this might cause the confusion. It’s 12-bit ADC so the count will be 0-4095 on the 0dB attenuation and 0-1023 on the 11dB attenuation range, I don’t know why they didn’t allow the full 12-but resolution on the 11dB range! Maybe it’s not attenuation at all and just a rescaling of the same 0dB input.
@electromaniaworld3179
@electromaniaworld3179 7 жыл бұрын
Hi David. thanks for beautiful introduction to adc concept of esp32. especially improving accuracy equation. i would like to know- 1) what is the background theory behind your polynomial equation? is there any literature i can read about it? 2) can we oversample ADC to improve resolution? i heard atmel ics have this possibility.. 3) have you tried to experiment the low noise differential amplifier (svp,svn pins) with programmable gain? the datasheet has very vague info and drivers not yet released by espressif. 4) i am trying for OTA- wireless update of sketch but no success yet-any thoughts on that.
@G6EJD
@G6EJD 7 жыл бұрын
Glad you like it. Regarding your questions: 1. There is lots of information around on polynomials, it's a 600-year old concept, what I would do is search google for 'how do I construct a polynomial'. For me I have been educated to 2nd degree level and it is a fairly normal activity, but if you need any help just ask. Essentially what I did was to find the approximate equation to the data using a straight line equation let's say y = 1.5x and then by inspection looked at the deviation from the straight line at each major point, let's say at x=1 y should = 1.5 but actually it was 1.49 and at x = 2, y was 3.05, but should have been 3, then I can add an element to the equation to correct it, now the equation looks like y = 1.5x + (1.49-x).(3.05-2) and so onto build the final polynomial. What's really important though is accuracy and resolution to get the correct result, if you look at the source code you can see how much resolution of the numbers I had to use, it's no good using 0.01 when it has to be 0.00987234345. Also search for 'table based approach to solving polynomials' 2. Yes you can oversample, but all that does is average out the results, it can never improve accuracy, what's happening by oversampling is the statistical mode is being found, which in general is a smoother result than a single reading. Whether the result is accurate or not depends on the raw accuracy of the ADC. If the ADC always gives a different result then what we see is the standard deviation away form some mean value that the oversampling technique gradually provides. If your seeing a lot of noise e.g. each time you take a reading then either the input is varying or the power supply is not as stable as it needs to be for stable ADC readings. Hope this helps you.
@electromaniaworld3179
@electromaniaworld3179 7 жыл бұрын
Thanks alot for detailed reply. 1) Thanks about polynomial, if i understood correctly , so it is a LUT based polynomial fitting ? 2) by oversampling, surely we are not improving accuracy, i wanted to increase the resolution ( increased resolution will just help measure accurate differences between two successive measurements - irrespective of whether measurements are accurate or inaccurate). i thought by your polynomial fitting based approach and oversampling - i can have ADC with increased resolution and better accuracy both.
@G6EJD
@G6EJD 7 жыл бұрын
1) The use of the term 'table' was the table based approach to generating a polynomial. There is no look-up table involved. Although you could use a simple table, but with a 10-bit ADC you'd need a lot of table entries. 2) Resolution and accuracy. Resolution is the precision to which a number can be determined or shown, e.g. 1.56 is low resolution and 1.5654321 is a higher resolution result. IF we read an ADC and get the result of 1.56 when in reality the voltage being measured is 1.50 volts, then the ADC result is inaccurate. By using a polynomial and if we assume the ADC conversion should be linear then we can correct for inaccuracies. Oversampling can increase the effective resolution from say 8-bit to 10-bit but it can never improve accuracy. 3.) You can use the polynomial approach to improving accuracy together with over-sampling to gain a little more resolution, but I doubt you'd notice the difference in practice unless your going to display all of the resolution. e.g. 1.5654321 instead of 1.56. 4) you can implement over-sampling like this: value = 0; for (int r = 0;r
@_GB84
@_GB84 Жыл бұрын
Hi, this is brilliant. Thank you. How would I go about combining this with the votage divider equation in your other video? Thanks in advance :)
@G6EJD
@G6EJD Жыл бұрын
Just follow the wiring examples I give in the video.
@_GB84
@_GB84 Жыл бұрын
@@G6EJD Thank you for replying so quickly. What I meant was, would I have to include the divider adjustement equation too? Eg at the end of the polynomial? For example voltage = analogRead(33); (then on the next line) voltage = (your polynomial equation) / 4096 * 30 * 247.191 / 220; (this last bit being the ajustment to take into account the resistor sizes I'm using) Thats the best I can explain I think Thank you
@G6EJD
@G6EJD Жыл бұрын
@@_GB84 ok understand, the polynomial corrects for ADC non-linearities, it assumes an unconnected ADC input. So you can connect your voltage divider resistors to the ADC input and then the polynomial will correct for ESP ADC shortcomings. All you need to do is size your divider values to give a 3v input at the maximum input voltage to the divider.
@_GB84
@_GB84 Жыл бұрын
@@G6EJD thanks for your help. I'll have an experiment 😊
@_GB84
@_GB84 Жыл бұрын
@@G6EJD Hi again, I think I've solved what I wastrying to do. What I was looking for is the voltage output from my 10w PV. So using your adjusted voltage, I then converted that back into the equivilent analoge value, then applied the equation to adjust the analoge value into the equivilent voltage the PV is currently outputting. The number looks about right, it was looking low until I applied this adjustment. I'll measure it later with a multimeter. voltage = analogRead(33); //Voltage at pin as analoge value voltage = (-0.000000000000016 * pow(voltage, 4) + 0.000000000118171 * pow(voltage, 3) - 0.000000301211691 * pow(voltage, 2) + 0.001109019271794 * voltage + 0.034143524634089); // Voltage at pin using polynomial equation to adjust ESP32 ADC linearity for better accuracy voltage = (4095/3.3) * voltage; //Convert adjusted voltage back to analoge value voltage = (voltage) / 4095 * 30 * 247.191 / 220; //Convert to PV voltage
@YigalBZ
@YigalBZ 4 жыл бұрын
Thank you for a focused and clear video. If I may: I am reading pot values from pins 34 & 35, one after the another. while the readings from 34 are accurate, 35 doesnt respond well. Is there a limitation of number of pins actual usage at a time?
@G6EJD
@G6EJD 4 жыл бұрын
I am not aware of any limitations when using any pins, however using ADC2 will create problems if your also using WiFI, apart from that I have no explanations, it is most likely input noise from the source being measured. For example do you get the same inaccuracies when you swap the inputs around. Output impedance is also a factor do are you measuring particularly high resistance on one channel verses the other. You can add a capacitor to the noisy input of say value 0.1uF but the value depends on impedance being measured, the time constant should ideally be longer than your measurement cycle time, for example if the output impedance was 100R then use a very high value of C perhaps 100uF or if 100K then 0.1uF the time constant is R x C in seconds.
@YigalBZ
@YigalBZ 4 жыл бұрын
@@G6EJD Thanks for answering. ESPnow is used to transmit the reading - working well. Pins 34-35 belong to ADC1, so there should be no contention. Swapping the pins swaps the problem, so the connectivity is correct. Perhaps the joystick is damaged.
@G6EJD
@G6EJD 4 жыл бұрын
@@YigalBZ ESPnow is still using the radio and the TCP/IP stack. But it does seem to be a hardware or noise issue.
@YigalBZ
@YigalBZ 4 жыл бұрын
@@G6EJD I found the root cause: the joystick itself is faulty - one axis is not working.
@G6EJD
@G6EJD 4 жыл бұрын
Ok, it’s always good to find the reason.
@michelebernasconi375
@michelebernasconi375 5 жыл бұрын
Dear G6EJD, I am new to this microcontroler world and fascinated by how one can blend different fields of engineering in weekend sized project :) Your material with those of Andreas Spiess (the guy with the swiss accent) are of great value to me! Now, I have problem implementing the ESP32 ADC battery level reading. My goal is to measure the voltage on the TTGO 32 Energy which relies on Li-On 3.7V Battery . I have 2 questions. From the sketch at around minute 1:00 of your video, the VP pin is pointing directly to the 10K resistor: Question #1: is the interpretation below, where VP is connected after the 10K resistor, correct? __ 3V | 10K | |__ VP (pin 36) | |__ GND If I connect 3V directly to VP, the esp32 (lolin 32 and TTGO 32 energy) stop working (they freezes) till I remove the 3V - VP connection. Can you please confirm the correctness of the sketch above? I got ADC readouts by implementing this schematic, without grounding, on the TTGO ESP32 Energy (board equiped with a LiOn battery charged) as shown below: __ 3V | 10K | |__ VP (pin 36) The ADC readout with a charged LiOn 3.7V is stuck at 4095 and it seems "saturated" (it doesn't go lower), I was assuming that the 3V pin delivers 3.3V and less depending on the battery charge level.. I managed to get reading lower than 4095 by increasing the resistance as shown in the following schematic: __ 3V | 67K (=47K + 10K + 10K) | |__ VP (pin 36) Question #2: Did I set up inadvertently a voltage divider as you showed in your video "Tech Note 115 - Using the ESP32 ADC for wide range DC voltage measurements"? Thanks in advance for the attention! Cheers, Mitch
@G6EJD
@G6EJD 5 жыл бұрын
Mitch, your nearly right, but your link from VP to Gnd creates a short circuit this is the correct wiring: 3v | | 10K | | +- VP | | 10K | | Gnd This gives a divide 2 voltage divider and 3v will now be measured as 4096/2 or 2048 allowing it to measure up to about 6v The voltage at VP = Vin x R2 / ( R1 + R2) Where R1 is the first resistor from 3V to VP and R2 is between VP and Gnd
@G6EJD
@G6EJD 5 жыл бұрын
BTW you can use any values you like, but not too high as the ESP32 requires adequate input current so the effective maximum for R1 is about 330K
@michelebernasconi375
@michelebernasconi375 5 жыл бұрын
G6EJD thank you very much for the quick reply! I’ll try it :)
@jdeg2000
@jdeg2000 6 жыл бұрын
Would there be a way to do the polynomial for just the ADC value, not the voltage it represents?
@G6EJD
@G6EJD 6 жыл бұрын
I'm not sure what your trying to do. The ADC value is the polynomial determinant and so you have the ADC value, there is no new value of ADC to be found that is more linear. The ADC value is an input voltage function. What are you trying to do?
@jdeg2000
@jdeg2000 6 жыл бұрын
G6EJD thanks for replying. I'm trying to correct the 12 bit curve for input into emonlib, (energy monitor with ct sensors, and an ac voltage sensor) which does it's own calculations and samples based on the ADC output value.
@G6EJD
@G6EJD 6 жыл бұрын
OK, I know the emonlib system. I have two thoughts, one is surely emonlib is expecting a 12-bit input resolution which is the compiler default for the ESP32 and using the polynomial gives you as nice linear reading that you need to scale to suit the range needed for emonlib, let's say it needed 0-5v range, then take the ESP32 poly reading and x 5/3.15 that will scale the 0-3.15v to 0-5v, or you can scale the 0-3.15v reading to 0-4096 (12-bit resolution) so you take the (poly reading) x 4096/3.15 e.g. 0 = 0 or 3.15v = 4096
@jdeg2000
@jdeg2000 6 жыл бұрын
Thank you so much! this has been driving me crazy! I'll give that a try.
@stevel7957
@stevel7957 Жыл бұрын
Thanks David for the work here. Very useful and concise! You have implemented this linearity improvement polynomial with the ADC at 12 bit resolution (0-4095) but what about when you reduce resolution to say 10 bit (0-1023)? I suppose that I could just multiply my ADC readings x 4 to scale up to 0 - 4095 but recognize some quantization error will be inherent. Is it that simple to adapt this for 10 bit mode or am I missing something?
@G6EJD
@G6EJD Жыл бұрын
The difference will be the voltage range of the ADC which changes to ~0-1v when using a lower resolution. The polynomial is for an input range of 0-3.3v so won’t scale easily and 10-bit readings will effectively have any errors magnified by the multiplier. Espressif have done a lot of measurements with noise so you can see the results here: docs.espressif.com/projects/esp-idf/en/v4.4/esp32/api-reference/peripherals/adc.html There’s a lot to using ADC’s as you’ll see. Don’t forget the ADC is very linear between about 0.2v and 2.8v
@stevel7957
@stevel7957 Жыл бұрын
@@G6EJD Roger that - thanks. I'm endeavoring to keep my input voltages to 0.25 > < 2.75 V in the region of interest of the sensor by picking appropriate voltage divider values.
@underwaterjunkie
@underwaterjunkie 7 жыл бұрын
Thanks for posting, I'm using Pocket32 clone which has built in 18650 Lipo battery and holder with no sensors connected. I ran your sketch without connecting anything to VP and VN. Whats the difference between doing this and having the resistor connected in inline?
@G6EJD
@G6EJD 7 жыл бұрын
That board has no connection to the battery at V2, but what you can do is use an inline resistor from one of the ADC inputs predesignated to a pin and it works because the ADC has an input impedance and so the external R and internal R form a voltage divider. The problem with doing it this way is device production variability will vary the reading, but nonetheless still works, just needs some experimentation with values. Unfortunately the input impedance is not published, but 100K might be a good starting point. To measure battery voltage route the end of the R to the battery + terminal, there is no pin for Vbat to make a convenient connection to.
@vishwamithrareddy3893
@vishwamithrareddy3893 4 жыл бұрын
Hi. Great video. Subscribed. Do you know what is the default ADC sampling rate on ESP32? I want to achieve at least 45Khz sampling rate but achieved only 1khz rate. So, do I need to do anything to achieve higher sampling rates?
@wei48221
@wei48221 6 жыл бұрын
Thanks for the great info..
@Rafaelguitarplayer
@Rafaelguitarplayer 4 жыл бұрын
do you think i can read a 3 wire PT100 using the ADC on the analog pins without using a external 4to20mA circuit? Thanks for your great job on youtube.
@G6EJD
@G6EJD 4 жыл бұрын
Rafaelguitarplayer, if it were a 2-wire device then yes, but as it’s a 3-wire rs485 type then no, the rs485 is a differential current communications standard that requires a A B and Gnd connection, therefore you will need an RS485 transceiver to read the values via an ESP serial port.
@HelmutTschemernjak
@HelmutTschemernjak 6 жыл бұрын
Can you explain the ReadVoltage formula, I basically need to use the 0dB voltage and I measure the internal vref (via routing on IO25) which I put into the fuse memory, so my boards are calibrated in terms of the vref, however I don’t understand the constants in your formula and how to adjust it to 0dB. Thank you for the great video. Helmut
@G6EJD
@G6EJD 6 жыл бұрын
When you quote 0dB you should always quote a reference for example 0-volts or 3-volts, dB is a ratio so has to have a reference. For further example 0dB could be at an input of 0.5volts or 0dB could be at an input of 1.414-volts and so-on. Next if you use analogread(36) versus my ReadVoltage(36) you will get a different result, ideally use ReadVoltage because when the input is 3 the ReadVoltage result will be 3, but the analogread will not ! Next to get to a reference value you simple need to use the ReadVoltage(pin) function in place of any analogread statements, then to adjust to your required reference simply add or subtract some constant value e.g. 2.5-Vref or whatever. That way you do not need to adjust the linearisation formula. To make the ADC reading linear I created a polynomial equation and it is not easy to simply add or subtract values without affecting it’s result, that’s why it’s best to leave the ReadVoltage function as is, knowing it returns a more accurate reading.
@fabiodametto4147
@fabiodametto4147 6 жыл бұрын
How did you put the vref value into the fuse memory?
@G6EJD
@G6EJD 6 жыл бұрын
The ADC reference voltage is about 1.1v and is factory trimmed during production- it’s fixed. There is no means of saving a new value. Adjust your readings in your code to simulate a different Vref. I think with a 12-bit ADC and ability to measure between 0 and Vcc+0.3 that’s as good as it gets. You can compensate for a low or high Vref by a simple subtraction/addition to your readings within the (Vcc+0.3)/4096 resolution limit so each step is 0.8mV and therefore you can effectively vary Vref in 0.8mV steps albeit in your code. As standard the ADC is quite accurate but for better performance you’d need to use an external ADC.
@OzonoCarbarsMexico
@OzonoCarbarsMexico 4 жыл бұрын
Thank you for the video. I'm trying to get +/- 1mv readings on the ADC, but readings are quite unstable. Is there a way to fix it?
@I_AM_A_TENT
@I_AM_A_TENT 3 жыл бұрын
have you tried like a lowpass filter? I dont know if the thing youre trying to read is also that stable
@VideoDetection
@VideoDetection 7 жыл бұрын
Great explanation and examples of how to use. Will definitely try out your equation to linearise the the slope. I too am using the Lolin32 board as it works well with just the right amount of features for a good price. Seems your videos are tracking my growing usage with this board and I'm loving the ESP32!
@G6EJD
@G6EJD 7 жыл бұрын
The Wemos boards are my favourites especially now in ESP32 guise and very versatile they have been designed by someone who thought about it and probably with some experience too. I’m glad your liking the videos, I’m trying to get a mix of basics where I think people get confused or are unclear through to a sprinkling of more advanced ideas / pointers to what else is available.
@solidfuel0
@solidfuel0 6 жыл бұрын
I did not get svp,svn pins. is this voltage divider? when are they needed? I looked up esp32 datasheet and no good info about them
@G6EJD
@G6EJD 6 жыл бұрын
solidfuel86, I’ve just pulled up the data sheet and: SENSOR_VP 5 I GPIO36, ADC1_CH0, RTC_GPIO0 SENSOR_CAPP 6 I GPIO37, ADC1_CH1, RTC_GPIO1 SENSOR_CAPN 7 I GPIO38, ADC1_CH2, RTC_GPIO2 SENSOR_VN 8 I GPIO39, ADC1_CH3, RTC_GPIO3 You can clearly see SVP sensor_VP etc are listed, I’m not sure what you mean. To measure voltages above the default ADC range of 0-3.3v you have to fit an external voltage divider made up of two series resistors one connected to the external voltage source the junction of the two resistors to an ADC input and the other end to ground. If the values are the same say 100k each then the division is 2 and the input range is 0-6.6. The compiler is preconfigured to convert the text VP to 36 and VN to 39.
@solidfuel0
@solidfuel0 6 жыл бұрын
@@G6EJD Thanks, yes they are mentioned in the data sheet, but I do not understand their purpose, what is special about them to be called SVP&SVN and the 10K resistor that SVP is connected to. I have read your other comment where you said : "You must take into account the ADC input impedance to ensure reasonable accuracy and one way to do this is to ensure the external voltage divider impedances are lower by say a factor of 2 than the nominal 10K ADC input impedance" But here you mentioned 100K. Is this just an example number or recommendation? I need to hook up a 5v analog current sensor. The current sensor does not need to be powered. It can generate 0-5v since it is around AC wire and act as transformer. but I assume that it cannot drive big resistors. I want to use those small blue potentiometer as voltage divider, but I have many of them and I need help picking the right value one.
@G6EJD
@G6EJD 6 жыл бұрын
solidfuel86 your current transformer needs a burden resistor usually a low value perhaps 10R. It will give you an AC waveform which will not be easy to measure, really you need to rectify the AC to DC and then apply some smoothing with a capacitor and then adjust your reading for RMS by multiplying by 0.707. The ADC input impedance must be higher than the voltage divider impedance otherwise it affects the readings. For example measure a voltage divider with a DVM and the reading results are accurate but measure the voltage with an old style moving coil meter and the results are inaccurate because of loading effects. Each ADC can be used without adjustments just analogread() the required GPIO pin. I don’t know why Espressif named them as they did other than Sensor Voltage N and the same for P, it does not matter what they are called.
@Q24H
@Q24H 7 жыл бұрын
Can the ADC channels be used to measure battery level of a 3.7v LiPo? And if so what's the current way of setting it up schematics wise?
@G6EJD
@G6EJD 7 жыл бұрын
Well it can but there is no internal method of doing this like there was with the ESP8266. You need to connect an external voltage divider to one of the ADC inputs and then measure voltage like that. In it's simplest form this is a series resistor from the ADC input to your battery +ve and another resistor from the ADC input to Ground. You must take into account the ADC input impedance to ensure reasonable accuracy and one way to do this is to ensure the external voltage divider impedances are lower by say a factor of 2 than the nominal 10K ADC input impedance, so suitable resistors would be: 2K7 from Battery to ADC (lets say pin 25) and then 4K7 from ADC to Gnd, that gives you a 5volt input range as 5/1.5744 = 3.1volts which is the ADC maximum reading, so your 4.2v Lipo max voltage = 2.66volts at the ADC, which you'd then need to increase again in the programme to read volts again, if that makes sense. So your battery voltage (nominally 4.2 when fully charged) is divided by the resistors down to 2.66v then take an ADC reading and then increase it by (4700+2700)/4700=1.5744 so that in the programme 2.66volts read is increased back to 4.2 volts. It may need a little calibration because none of the devices are calibrated, so just adjust the (4700+2700)/4700 values to make the final result 4.2volts. Let me know if that does not make sense or you need any help in doing this. ADC is best left at default 11dB attenuation for this to get maximum measurement range.
@Q24H
@Q24H 7 жыл бұрын
Thanks, that was very helpful, I am researching ways to collect battery info for my lipo powered project :)
@G6EJD
@G6EJD 7 жыл бұрын
One of the problems of using resistors is the quiescent current demand especially when this is many times more than the sleep current (6uA) of the ESP, it really needs an FET under control of the ESP to effectively disconnect the series resistance when not in use. Either that or just use a series resistor to the ADC input, but input impedance varies between devices so the results vary, ok if a one-off non production solution.
@Q24H
@Q24H 7 жыл бұрын
G6EJD thanks for the tip, I'll have a look into that for my next project, for now I decided to use some big 1MOhms resistors for the voltage divider, it's not the perfect solution but it works ok (draws 3uA) and I don't need high accuracy for my purposes
@TYGAMatt
@TYGAMatt 4 жыл бұрын
Trying to measure temp with an LM35 on VP pin but none of the calculation to get from the raw input reading to final temp in C seem to make any sense. Tried all the attenuation values but I have to pretty much make up the equation while using a 4096 constant. Using arduino IDE by the way. Must be something glaringly obvious but I can't figure it out. Any tips?
@TYGAMatt
@TYGAMatt 4 жыл бұрын
@glyn hodges I have 2 genuine LM35 and they work OK, but still not happy with ADC on ESP32 so using an ADS1115 ADC board. Works perfectly now. When measuring the MV output of the LM35 and comparing with the ESP32 readings, they differed. Also have 10 LM35DZ purchased from online cheapo store (China product) and they're useless. Readings all over the place. I just use them as little chocks for stopping things rolling around on the desk now.
@TYGAMatt
@TYGAMatt 4 жыл бұрын
Oh, and in answer to your first question, I tried 5v and also 3.3v. As it is now I'm running 5v
@TYGAMatt
@TYGAMatt 4 жыл бұрын
@glyn hodges yep, the ADS1115 is also a clone, but it works very well.
@MPElectronique
@MPElectronique 6 жыл бұрын
Dave im looking for the video u mad about baterry mesurement with esp32 u made?. Can u help me? Thanks.
@G6EJD
@G6EJD 6 жыл бұрын
In its simplest form use readanalog(35 or 36 or 39) the default is 0-3.3v range then add two identical resistors to the ADC input as a voltage diver, say 100k each then the range is 0-6.6v and still accurate for most purposes. Some more maths helps to focus in on a range of voltages, does that help.
@vladhristov2316
@vladhristov2316 6 жыл бұрын
Hi. I have a hydro growing lamp 12v 40W, and esp32. When I turn on the light, the analog readings of the capacitive soil moisture sensors jump by 1000+pts. Do you think your function will get them back to normal. I have used the following int readMoistureSensor_GPIO32(){ adc1_config_width(ADC_WIDTH_BIT_12); //Range 0-4095 adc1_config_channel_atten(ADC1_CHANNEL_4,ADC_ATTEN_DB_11); //ADC_ATTEN_DB_11 = 0-3,6V return adc1_get_raw( ADC1_CHANNEL_4 ); //Read analog GPIO32 } and tried to raise the voltage to clear the noise a little, but with no avail. That is happening also to a DS18B20 sensor waterproof.
@G6EJD
@G6EJD 6 жыл бұрын
Vlad, in short no, the function corrects small variations in ADC non-linearity. Almost certainly your problem is poor supply voltage regulation or incorrect earthing. 40W at 12v is about 3.5Amps so ideally check the supply voltage with the lamp on and off, it should be the same and run a separate earth from the ESP32 to the sensor. Similarly the sensor voltages need to be constant and the same with the light on and off. You can try to reduce the effect by putting a capacitor across the sensor say 47uF or more and if the variance improves then the problem is power supply regulation.
@vladhristov2316
@vladhristov2316 6 жыл бұрын
@@G6EJD Yes, it is short :) Thx for the lighting fast response. I enjoy your videos, especially those for ESP32 and sometime I watch them. just for fun. I would like if you can try to maintain your voice level consistent. It seems you lower the volume level if your thought are long. Friendly advise.
@anandsamdadiya8772
@anandsamdadiya8772 3 жыл бұрын
Can we sort non linear issue at lower end near .1v
@G6EJD
@G6EJD 3 жыл бұрын
Yes see my video on improving ADC accuracy - github.com/G6EJD/ESP32-ADC-Accuracy-Improvement-function
@roiefrati
@roiefrati 5 жыл бұрын
Hi Dave. If I only want to "correct" the ADC value. Not convert it into Voltage. Can you explain what need to be changed in the polynomial equation? (I'm Bad at Math)...
@G6EJD
@G6EJD 5 жыл бұрын
The polynomial has many determinants and it’s not easy to adjust one factor of it without affecting the others. It’s function is to take a non-linear 0-3v equivalent input to a linear variant. So it does need a voltage input, if you like. To correct the raw input from the readanalog line just modify the constants after the read statement, say you measure with your DVM an input voltage of 2.5v and the readanalog result is low increase the multiplier value e.g. voltage = readanalog(35) * 7 becomes * 7.05; or vice-versa if too big. The easy way to get straight to the correct value is input 1.5v measured with a DVM and then display the ESP32 voltage say it reports 1.45v with a multiplier of 7 then 7 becomes 7 * 1.5/1.45 or readanalog(35) * 7.24; then it will return 1.5v. It’s important to calibrate the ADC not at the low or high end of its input range because this is where its most non-linear. So the aim is to get an accurate input to the polynomial equation for the very best results. Uncalibrated the results are still well within acceptable limits as the ESP32 ADC reference is always within a given range, it just varies from device to device.
@roiefrati
@roiefrati 5 жыл бұрын
is there a way to mathematicaly convert a raw ADC value that was measurd using 11db attenuation to what it would have been if it was measurd let's say on 2.5db ? I know it will not be very acurate, but it might solve me a big problem...
@G6EJD
@G6EJD 5 жыл бұрын
Yes, in principle it is 11db / 2.5db which in gain terms is 1.33 / 2.55 and so multiply your readings by 1.92 (reciprocal of the gain values). The problem you’ll get is an increased range but no ability to interpolate between values as resolution cannot be increased unless you do this in software as a simulation.
@roiefrati
@roiefrati 5 жыл бұрын
My problem is, I calibrated several devices using 11db Att. (and sent them to client's. They are now in a shipping container heading to the new world. so recalibrating them is out of the question) I now understand that 2.5db works better for this specific application. and I'd like to use it for the next devices. I can update the old devices (OTA is implemented) but I need to, at least, recalculate the calibration values. I'm shooting in all directions, trying to figure the best corse of action.
@G6EJD
@G6EJD 5 жыл бұрын
Well it’s a linear relationship so easily fixed with a scaling factor.
@josegomez1956
@josegomez1956 4 жыл бұрын
Thank, good explanation....JOSE ARTURO GOMEZ : CALI, COLOMBIA
@zyghom
@zyghom 2 жыл бұрын
I have struggled with calibration of ADC of ESP32 and ESP32-S2 - many methods - and I ended up with 3 things: 1- install voltage divider calculated this way, that input voltage on GPIO is inside the most linear range. If you consider attenuation 11db then voltage shall not reach more than 2.1V on GPIO so for 4.2V max measured voltage the divider can be 50/50 - for battery operated devices I use resistor in the range of 200k Ohm each so that current drawn when devices sleeps is minimal - around 10uA due to the resistors - that should be ok considering that ESP32 consumes in deep sleep anything between 8uA (ESP32) and 22uA (ESP32-S2) - I am using only bare modules - not development modules with tons of components on them 2- CRUCIAL: add ceramic capacitor - range between 100nF - 1uF - if the voltage you measure is DC-like (i.e. battery or so) this will have no impact on the input signal (level) however the signal will be so linear that I completely abandoned the "in range" calibration (multi points) 3- the only calibration for my sensors I do is at 3.7V - the middle-like of the measured voltage - I use ADC to measure battery level, that is anything between 2.8V (minimum voltage for ESP32) and 4.2V (maximum voltage on charging battery) - ok, maybe 3.7V is not really in the middle but I rather stay with battery above this point. With this calibration at 3.7V the error in the whole measured range (2.8V-4.2V) is around +- 2mV - should be more than enough accuracy for my projects
@G6EJD
@G6EJD 2 жыл бұрын
Have you seen my video on how to read the ADC reference voltage (factory set) and from there improve ADC reading accuracy
@zyghom
@zyghom 2 жыл бұрын
@@G6EJD yes, not all ESP32 have this one burnt in - I checked mines and ESP32-S2 have and work ok but the ESP32 don't. Still: adding capacitor 100nF is recommended by Espressif. On top of that: Vref is not the only problem - it only shifting the reading. Problem is lack of linearity. Even with 2 points it is still blabla for the precise measurement. The most accurate would be LUT - but that one is seriously bringing lots of memory waste to the ESP
@G6EJD
@G6EJD 2 жыл бұрын
@@zyghom Well the polynomial I produces uses only a small amount of memory and makes the response linear from 0.1v to 3.3v
@babotvoj
@babotvoj 4 жыл бұрын
Can I sample audio signals with a sampling frequency of 80kHz
@nendhang
@nendhang 6 жыл бұрын
Why cant i use adc2 when wifi is on? And by the way I can push the adc reading into 9.3 uS per pin With 2 analog cycles And dual core
@G6EJD
@G6EJD 6 жыл бұрын
nendhang ngetz, you’d need to ask Espressif why you can’t use ADC2 while the WiFi is on! Yes maybe the ADC can run at 9.3uS, but I don’t understand what point your making
@glacian79
@glacian79 5 жыл бұрын
Adc2 doesn't work when WiFi is enabled and many development boards hide the adc1 pins. It's a very annoying "feature". Did you find a work around?
@G6EJD
@G6EJD 5 жыл бұрын
I’ve not aware of any development boards that hide ADC1 pins, ADC2 yes. I don’t see a need for multiple ADC channels (1&2) when for for nearly every real world measurement an inter-reading time of 10uS is near instantaneously the same time, plus ADC1 can be multiplexed onto a wide range of pins, so I’m not seeing the limitation.
@HienNguyen-wi2ni
@HienNguyen-wi2ni 2 жыл бұрын
hi bro, how to read adc with 9.3us, please give me the code
@G6EJD
@G6EJD 2 жыл бұрын
You have to reduce the number of cycles required to take a measurement in the settings. To be honest if you want high speed readings then the general purpose internal ADC is not the right tool for the job and you should use a high performance external type.
@NecoRuChannel
@NecoRuChannel 5 жыл бұрын
Good job!Thank you so much!
@chegewaras
@chegewaras 7 жыл бұрын
Im sorry but in Advanced controls table is an error. In attenuation description all attenuations are reversed, ie for 0dB 1V is giving readings about 3959 but in table is 1088, and 1088 is readings for 1V with attenuation 11dB. Beside nice info, very useful.
@G6EJD
@G6EJD 7 жыл бұрын
Yes it’s wrong, thanks for letting me know. All of the maximum count values are 4095. I think I rushed that bit and changed my mind on what was going to be displayed, but didn’t correct the table.
@ppe4dfw902
@ppe4dfw902 3 жыл бұрын
Hope this is still an active thread. I have been using the ESP32 WROOM-32U development board via the Arduino IDE and doing analogRead() on pin 36 every 100 microseconds until I accumulate 2000 values in an array. Configured for 10 bits. I now understand (I think) that the ADC takes about 400 microseconds to complete conversion. What do the numbers I've been writing to the array actually mean (or represent)?
@G6EJD
@G6EJD 3 жыл бұрын
They mean the ADC value read at that instant when the ADC completed its conversion sample so at worst real-time + ADC conversion time
@ppe4dfw902
@ppe4dfw902 3 жыл бұрын
@@G6EJD Thanks. So it buffers all these requests I'm sending it?
@G6EJD
@G6EJD 3 жыл бұрын
I wouldn’t say buffers as the requests are blocking cpu progress until completed, although of course there are two CPU’s in most ESP32 variants so processing can continue on the other cpu until the conversion is completed.
@ppe4dfw902
@ppe4dfw902 3 жыл бұрын
@@G6EJD Are you saying each analogRead is serviced before the next one is handled? Seems this puts the process 8 Reads behind each millisecond, and this goes on for 5 to 7 seconds. Actually have pinned Core 0 to WiFi activities and Core 1 to application processes. Pin 36 is connected to an axis of an ADXL335. I do these analog reads at 100 ms intervals and save the value to an array if the value is beyond a threshold value.
@hakamsingh868
@hakamsingh868 2 жыл бұрын
My adc value fluctuate a lot even on dc value ..how I can improve precision 🙏 thanks
@benfisher6085
@benfisher6085 Жыл бұрын
Many thanks for the video - very informative. I would really appreciate any help or input on the following situation which I cannot fathom, please: I am having an issue with the readings varying between reboots of the ESP32 - this means that I usually get a reading (with the standard 11db attenuation) of around 550 for an input voltage of .72v and of 430 for input .58v. However, I noticed that these values were not consistent over time - so if I continually reboot the esp32, then on some reboots I will get a consistent value of around 800 for the same .72v input and 680 for the .58v input. This will revert back to the old levels of 550 and 430 after rebooting (resetting) the esp32 again. I have a 1uF cap across the input to GND for noise reduction, and the (external) impedance from my voltage divider is around 3.3kOhms. The board is an ESP32-WROOM32E within an ESP32-DevKitC development board. I have tried three different boards with the same result - it just doesn’t seem to make any sense, and I would appreciate any thoughts or feedback. Thanks in advance.
@G6EJD
@G6EJD Жыл бұрын
Have you tried a much smaller smoothing capacitor say 0.1nF as the ESP32 input impedance is quite high. I have never seen irregular ADC readings, so I’m thinking this is an external component induced issue. I have produced another video that shows how to read the internal ADC reference voltage, which yields a much more accurate outcome, try implementing that.
@hakamsingh868
@hakamsingh868 2 жыл бұрын
My adc value fluctuate a lot even on dc value ..how I can improve precision 🙏 thanks
@G6EJD
@G6EJD 2 жыл бұрын
This ADC noise you can either add a 0.47 uF capacitor across the ADC pin and ground, but that will delay the reading speed somewhat but if speed is not an issue say a reading every minute then that will help. Or take say 10 readings add them all up and divide by 10 to get an average then you will remove sine or all of the quantisation errors. float average = 0; For (int I = 0; I < 10; I++) { average += readanologue(pin); average/=10; Now average is the result of 10 readings
@MPElectronique
@MPElectronique 6 жыл бұрын
Hi dave. Can i mesure the vin of the lipo battery connector and how ? Thanks. Marc.
@G6EJD
@G6EJD 6 жыл бұрын
Vbat | | 10K |--- to ADC input either VP or VN | 15K | | Gnd float voltage = map(analogueread(VP),0,1023,0,5000)/1000.0F; or float voltage = map(analogueread(VP),0,4095,0,5000)/1000.0F; // depends on ADC range/mode set if (voltage > 4.18) percentage = 100; else if (voltage < 3.0) percentage = 0; else percentage = (voltage - 3.0) * 100 / (4.18-3.0); gfx.drawRect(x,y,100,30); // Draw a battery symbol gfx.fillRect(x+2,y+2,percentage/100*96,26); // draw a black block that is sized in % Problems, let me know, I may have misspelt a few functions:)
@MPElectronique
@MPElectronique 6 жыл бұрын
Hello Dave. With this code i got 3.64v and my lipo is 4.17v, is it normal? unsigned int percentage = 0; unsigned long previousMillis = 0; const long interval = 1000; // setup void setup() { Serial.begin(115200); analogReadResolution(12); // Sets the sample bits and read resolution, default is 12-bit (0 - 4095), range is 9 - 12 bits analogSetWidth(12); // Sets the sample bits and read resolution, default is 12-bit (0 - 4095), range is 9 - 12 bits adcAttachPin(VP); analogSetClockDiv(255); // 1338mS } // loop void loop() { unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { // save the last time you blinked the LED previousMillis = currentMillis; float voltage = map(analogRead(VP), 0, 4095, 0, 5000) / 1000.0F; // depends on ADC range/mode set if (voltage > 4.18) percentage = 100; else if (voltage < 3.0) percentage = 0; else percentage = (voltage - 3.0) * 100 / (4.18 - 3.0); Serial.println("Voltage: " + String(voltage)); Serial.println(String(percentage) + " %"); } } Thanks. Marc.
@G6EJD
@G6EJD 6 жыл бұрын
OK Marc, looking good. If you have a 10K R from Vbat to a 15K to ground then the voltage (assuming no ADC) load and it looks like there is, will give an ADC input voltage of 2.5 volts, which then get mapped to 0-5v and should give an ADC count of ~3100 and so after mapping 3.7volts and % = 66% so not that far out.So your particular ADC input impedance is lower than expected. If you can adjust your 15K R to 20K (could us10K+10K in series) or say a 22K then adjust the volts down in software.Using 3.0 volts is destroying the lipo life IMO and is better set at 3.6 but maybe 3.2 absolute minimum.
@MPElectronique
@MPElectronique 6 жыл бұрын
WOW!!! you are the best!! :) 4.17v :) :D
@G6EJD
@G6EJD 6 жыл бұрын
I've seen this before, some ADC input impedances are relatively low, I've some that measure about 900K and others 50K, this lower end loads the voltage divider, it's not usually a problem and easy to recalculate the values. Actually you can use just about any two resistors of R and 2R ratios 10K and 20K or 100K 220K or 47K and 91K and get the same/similar results. If your running on batteries it's better to use the higher values. You can also use a single series R and limit the input current to the ADC but you'd need to experiment with values as every device seems to be different. Maybe 47K and print out the ADC value, ideally use a pot to get to the exact value then use a fixed R. Glad you got it running and measuring.
@zyghom
@zyghom 2 жыл бұрын
at 2:26 I still have a problem to understand: with ADC_0db meaning no attenuation, maximum voltage range should be no more than Vref (that is 1.1V on ESP32) while with ADC_11db the attenuation is so high that one can read up to 3.3V - but in this table all is mixed up.
@G6EJD
@G6EJD 2 жыл бұрын
The table came from Espressif and yes it is incorrect as at ADC_11db a 3.3v input gives a reading of 4095.
@KHIRD
@KHIRD 3 жыл бұрын
Good examples
@michaelpadovani9566
@michaelpadovani9566 7 жыл бұрын
New Sub here. Thank you for putting this video together. I was wrestling with this for a while (why the ESP32 adc doesn't line up but the uno/nano/mega do). I also notice the esp32 adc is a bit noisy. I fixed this problem by using an ADS1115 which gives perfect results but I'm a bit frustrated i needed to buy it. Now i see your formula and can give it a try. Again many thanks!
@G6EJD
@G6EJD 7 жыл бұрын
Happy to help. the ESP32 ADC is reasonably linear (factory trimmed) between the lower second quartile and upper first quartile so if the range in quartiles was 1 2 3 4 only 2 and 3 are linear, the polynomial helps to convert the actual output to an expected linear result. But using only that middle range is rarely any good for most applications. It's a very fast conversion, unquoted by the manufacturer, but seems to be about 10uS, I have not measured the actual time.
@michaelpadovani9566
@michaelpadovani9566 7 жыл бұрын
Just tested this out and your formula adjustment is much improved, nice work and look fwd to more videos
@edinfific2576
@edinfific2576 10 ай бұрын
@@G6EJD From what I can see on the attenuation curves, it seems that 0dB attenuation could give the most linear results all the way from zero to around 1.0 volts, which makes me suspect their attenuator's nonlinearity (something about ADC results being 0 until around 0.16V and 4095 above 3.10V, as well as the curve becoming non-linear above 2.6V, which is 3.3-0.7, makes me suspect those are bipolar transistor voltage drops at saturation and Vbe values, which they may be using in their attenuators, which may be bypassed by not using attenuation). Have you tried its ADC with 0dB attenuation, and what were the results? I will try it myself as well.
@G6EJD
@G6EJD 10 ай бұрын
Unfortunately Espressif don’t publish the input circuit details so that customers can understand the interfaces, they could be using fet switching of resistors or some form of varister to achieve the attenuation, who knows. I did trial the 0dB range and found little difference in the results, but don’t forget the resolution changes (lowers) on the less attenuated settings, so that’s why I opted for the 4096 variant to get the best resolution and fixed the non-linearity with a polynomial, a little slower to read but for the vast majority of applications it’s ok.
@paulmassoncantillo2937
@paulmassoncantillo2937 3 жыл бұрын
hello, i'm using the polynomial function to improve analog readings, however i'm only getting a maximum of 3.14 V
@G6EJD
@G6EJD 3 жыл бұрын
Well the maximum range of the ADC if set to 11dB of attenuation is 0-3.0 volts or Vcc -0.3, so are you using an input voltage divider?
@paulmassoncantillo2937
@paulmassoncantillo2937 3 жыл бұрын
@@G6EJD yes, i'm using a voltage divider.
@G6EJD
@G6EJD 3 жыл бұрын
Then you need to multiply your result by the voltage divider ratio, so if /2 then *2 then you get back to the actual voltage. Plus there is some leakage current into the ADC input so it will never be say * 2 and more likely * 2.3
@viktorhugo8252
@viktorhugo8252 Жыл бұрын
Thanks, attach to pin is😊 very good for flexibility
@raghavendrakarnad
@raghavendrakarnad 5 жыл бұрын
Has anyone tried to measure the differential signal between the SENSOR_VP and SENSOR_VN pins? Or is using an external ADC the only way out?
@G6EJD
@G6EJD 5 жыл бұрын
Raghavendra Padmanabha, I see no reason why it won’t work if you accept there will be small delay between readings and that the resolution will be limited to ~3/4096v or 0.73mv
@anandsamdadiya8772
@anandsamdadiya8772 3 жыл бұрын
Can I measure voltage upto .1
@G6EJD
@G6EJD 3 жыл бұрын
ESp32 ASDC maximum input voltage is 3.3v depending on which range you choose.
@sickvic3909
@sickvic3909 7 жыл бұрын
Still doing any quad flying?
@G6EJD
@G6EJD 7 жыл бұрын
Yes my F450 and F550 gets lots of use but I’m hankering after one of the now many racers on the market with camera for about £100, so many to chose from that I get bamboozled by it all 😊DJI are still making the best products in my opinion.
@sickvic3909
@sickvic3909 7 жыл бұрын
Good to hear. Racer, too much for me. I have grampa's big slow caddy :)
@avonfonds2567
@avonfonds2567 3 жыл бұрын
How to use the dig mode for faster readings of 2msps
@G6EJD
@G6EJD 3 жыл бұрын
What mode do you mean? The ADC there is no speed adjustment
@avonfonds2567
@avonfonds2567 3 жыл бұрын
@@G6EJD the dig ADC it's in the datasheet I can't find anything about it in Google
@G6EJD
@G6EJD 3 жыл бұрын
@@avonfonds2567 Do you mean the ESP32 ADC ?
@avonfonds2567
@avonfonds2567 3 жыл бұрын
@@G6EJD yes
@G6EJD
@G6EJD 3 жыл бұрын
@@avonfonds2567 docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html
@anguspatterson9164
@anguspatterson9164 2 жыл бұрын
I discovered that it's actually possible to use the value 8 for analogReadResolution(8).
@science4allworld587
@science4allworld587 2 жыл бұрын
How are you doing David? Haven't seen videos from you since quite a while. Hope and wish for your wellbeing.
@G6EJD
@G6EJD 2 жыл бұрын
I’m doing ok, lacking energy chemotherapy brain fog, but a small price to pay
@dodutils
@dodutils 7 жыл бұрын
Hello, just discovered your channel, I like the way you explain things, but I do have two questions about ADC : - How many ADC can ESP32 use at same time ? - if it is only one at a time then I guess you can switch each PIN you want and read Analog value from Pin X to Pin Y in a loop so you can read for example 10 analog source values ? - What is attenuation for ? I mean do it allow to input more than 1V to attenuate to the range of 0-1V and if yes what is the max voltage input ? I see you show 3V in your video.
@G6EJD
@G6EJD 7 жыл бұрын
Thanks, there are 18 ADC channels but only one can be read at a time, unless you get the ULP processor to read a channel, but that's a more advanced programming feature. Given the time to read the ADC is about 1uS and most analogue world values are quite slow (relatively) then you can sequentially read the channels. So as you say you could read all channels in one go, noting a very short time gap between each reading. Something like void read_ADC_Channels(){ value-1 = analogRead(pin-1); value-2 = analogRead(pin-2); ... value-n = analogRead(pin-n); } The maximum input value is Vdd or 3.3v, but in-practice because of non-linearity, the maximum is constrained to about 3.0volts. When you adjust the attenuation value you get this effect: 0dB attenuaton (ADC_ATTEN_0db) gives full-scale voltage 1.1V 2.5dB attenuation (ADC_ATTEN_2_5db) gives full-scale voltage 1.5V 6dB attenuation (ADC_ATTEN_6db) gives full-scale voltage 2.2V 11dB attenuation (ADC_ATTEN_11db) gives full-scale voltage 3.9V (see note) But note: The full-scale voltage is the voltage corresponding to a maximum reading (depending on ADC1 configured bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.) So in the above example and assuming you have set the ADC's to 12-bit (0-4095): 0dB attenuaton (ADC_ATTEN_0db) gives full-scale voltage 1.1V for a reading of 4095 2.5dB attenuation (ADC_ATTEN_2_5db) gives full-scale voltage 1.5V for a reading of 4095 6dB attenuation (ADC_ATTEN_6db) gives full-scale voltage 2.2V for a reading of 4095 11dB attenuation (ADC_ATTEN_11db) gives full-scale voltage 3.9V (see note below) for a reading of 4095 This affects resolution, in the 0dB example and input of 1.1volts (you can still input the maximum 3.3 volts but it will read 4095, so it will climb from 0 to 4095 then stay at 4095 even though the voltage has exceeded 11.volts) each step = 1.1/4096 = 0.2685mV In the 11dB attenuation example each step = 3.9/4096=0.9521mV When set to 12-bit the difference is not that great but set to 9-bits then 0dB each step = 1.1/512=2.14mV 11dB each step = 3.9/512=7.6mV You can get a wider input range by adding a voltage divider comprised to two resistors in series one end is the input, their intersection goes to the ADC input and the other end ground. If the values were 10K each the attenuation would = (10)/(10+10) = 1/2 and now the maximum input voltage on the 0dB range is 2.2volts for a reading of 4095. Attenuation is Vin x R1/(R1 + R2) but be aware the ADC has a input impedance too, so don't use high values say > 100K as the divider chin will be affected by the ADC input impedance. In my example (no-one has published the ADC input impedance) let's say the input impedance was 10K then Vix10/(10+10x10(10 + 10)) = 1/1.5 not 1/2. In practice it seems to be much higher than 10K, I assume 100K and then it's affect on a voltage divider is much lower.
@dodutils
@dodutils 7 жыл бұрын
Thanks for explanation so now I know I can connect multiple potentiometers to the ESP32 instead of having to add an extra ATMega328 or some I2C multiple channel ADC like I did for ESP8266
@joaorocha1227
@joaorocha1227 6 жыл бұрын
hey, i need some help, i want to use an esp32s for read values from 0v to 8.4v how can i do that? (sorry for my bad english)
@G6EJD
@G6EJD 6 жыл бұрын
João Rocha in my TN115 released this week I cover how to do this. Let me know if you have any problems.
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
David! ESP32 Wroom-32 doesn't work. analigSetPinAttenuation (36,ADC_0db);
@G6EJD
@G6EJD Жыл бұрын
What about ADC_11db?
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
​@@G6EJD #include "esp32-hal.h" const int potPin = 36; int potValue; float voltage =0; void setup() { analogSetPinAttenuation(36,ADC_0db); Serial.begin(115200); } void loop() { potValue = analogRead(36); voltage = (3.3/4095.0) * potValue; Serial.print("potValue:"); Serial.print(potValue); Serial.print(" Voltage:"); Serial.print(voltage); Serial.println("V"); delay(500); }
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
Output: potValue:1163 Voltage:0.94V potValue:1161 Voltage:0.94V potValue:1154 Voltage:0.93V potValue:1163 Voltage:0.94V potValue:1161 Voltage:0.94V
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
​@@G6EJD #include "esp32-hal.h" const int potPin = 36; int potValue; float voltage =0; void setup() { analogSetPinAttenuation(36,ADC_11db); Serial.begin(115200); } void loop() { potValue = analogRead(36); voltage = (3.3/4095.0) * potValue; Serial.print("potValue:"); Serial.print(potValue); Serial.print(" Voltage:"); Serial.print(voltage); Serial.println("V"); delay(500); }
@muhammadadnanahmed8324
@muhammadadnanahmed8324 Жыл бұрын
potValue:1163 Voltage:0.94V potValue:1161 Voltage:0.94V potValue:1154 Voltage:0.93V potValue:1163 Voltage:0.94V
@anandsamdadiya8772
@anandsamdadiya8772 3 жыл бұрын
How to increase accuracy at .1 voltage
@G6EJD
@G6EJD 3 жыл бұрын
You can't increase accuracy unless you calibrate the readings against a known measurement system. Resolution of the ADC is fixed on that range.
@anandsamdadiya8772
@anandsamdadiya8772 3 жыл бұрын
But I have to measure voltage near .1mv what shall I do
@G6EJD
@G6EJD 3 жыл бұрын
@@anandsamdadiya8772 Really the ESP32 is not the right tool for this, you need an external ADC of about 12-14 bit resolution. 1/4096 = 0.2mV so a 12-bit ADC wont be good enough. You will have problems with noise at that level too, you'd be better sending the voltage to be measured through an amplifier say x10 so that 0.1mV becomes 1mV, maybe even more amplification is needed.
@brakthehun
@brakthehun 3 жыл бұрын
'adcStart' was not declared in this scope Ok,, a little research later,, The latest Espressif board library from Arduino no longer supports all these cool functions. I wish they did.
@kengineer1379
@kengineer1379 6 жыл бұрын
can i use ADC in a 5v out sensor?
@G6EJD
@G6EJD 6 жыл бұрын
Yes but only if you add an external voltage divider using 2 series resistors one end to your input source (sensor) the junction to the ADC and other end to the ground. Two resistors of 100K each would extend the input voltage range to 0-6.6v
@kengineer1379
@kengineer1379 6 жыл бұрын
Would a 2k and 4k ohm resistor suffice? Im using a pH meter and it needs an analog pin..
@G6EJD
@G6EJD 6 жыл бұрын
That’s ok, those values will give you a 4/(2+4)=0,66 division so scale your ADC reading accordingly with some constant to adjust the range eg 3.3/0.66 so readadc/0.66
@G6EJD
@G6EJD 6 жыл бұрын
Your chosen values will give you a 0-5v reading range and you should be able to read the sensor with no issues assuming it can drive an approx. 6K load.
@kengineer1379
@kengineer1379 6 жыл бұрын
thank you so much for the replies, im using this pH sensor and the codes provided in the pdf. i tested it in my arduino uno and it has no problems, but when i used it in my esp32 (devkit v1) (pin 36), i cant seem to make it work. any advice in my situation sir? i am really lost..
@josegomez1956
@josegomez1956 4 жыл бұрын
Comparto mis pruebas de FFT con GPIO36 y A7 (Stereo), como uso de ADC----(how to use the ADC WITH FFT)
@G6EJD
@G6EJD 4 жыл бұрын
JOSE ARTURO GOMEZ VELASQUEZ, I have produced a TN that shows how to use FFT see TN076 or TN077
@josegomez1956
@josegomez1956 4 жыл бұрын
@@G6EJD Gracias, Thank for You help for me.
@josegomez1956
@josegomez1956 4 жыл бұрын
Sir - David Bird: I wanted to ask you if you have any videos about esp32-lna with GPIO36, GPIO37, GPIO38, AND GPIO39 ports ?? As a reference I give you the only thing that I have found : github.com/krzychb/esp32-lna , and really, I have not been able to understand how to do a basic or elementary reading, and from there I can experiment with this special feature of ESP32 Excuse my English, I hope it keeps getting better and God keep it. Thank
@G6EJD
@G6EJD 4 жыл бұрын
I have a TN on the ESP32 ADC which uses pins 35,36,37,38,39 have you seen that. Don’t forget these pins are input only!
@G6EJD
@G6EJD 4 жыл бұрын
Also the gain is varied by setting the attenuation levels, there is no plan to do any more - what are you trying to do?
@josegomez1956
@josegomez1956 4 жыл бұрын
@@G6EJD -->> Low-Noise Amplifier "LNA": SenseVP (GPIO36), SenseVN (GPIO39), and CapVP (GPIO37), CapVN (GPIO38). I need to understand well how to use the LNA feature of ESP32 as explained on page 559 of the following "pdf": www.mouser.com/pdfdocs/ESP32-Tech_Reference.pdf The structure of the low-noise amplifier is shown in Figure133. To take advantage of the specific characteristics of this Internal Operational application of the ESP32, I still do not have a specific project, but I think it is a very powerful feature of the ESP32, which I can consider taking advantage of in the future, to read sensors that give very weak DC voltage signals. .....Thank
@josegomez1956
@josegomez1956 4 жыл бұрын
@@G6EJD No, I have not seen it, what is the link (url), thank you very much for your interest.
@josegomez1956
@josegomez1956 4 жыл бұрын
@@G6EJD You refer to your previous video? Yes, thank you very much, very good explanation, you are very clear when you explain in your videos, I am eternally grateful. If it is another video can you tell me which one it is? (TN ??)
@andrewmitz1755
@andrewmitz1755 5 жыл бұрын
Came here to understand analogSetCycles() and analogSetSamples(). The esp32 Technical Ref discusses Sample cycles of SAR without much explanation. Cycles may have something to do with the pattern tables? I can only guess that Set Samples is related to oversampling. It would have been nice to get some meaning other than just using the words already on the page. Thumb down.
@G6EJD
@G6EJD 5 жыл бұрын
Andrew, then why not make your own video then enjoy being criticised for covering every single word and meaning and iota of the data sheet. You really need to get a life and get into the real world.
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
"Идеальное" преступление
0:39
Кик Брейнс
Рет қаралды 1,4 МЛН
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН
Tech Note 137 - ESP32 a further insight into using the serial ports
6:43
Forget WiFi! This Wireless Method is WAY Better?
12:14
GreatScott!
Рет қаралды 711 М.
Using the ESP32 DAC - Voltages, Waveforms & Sounds
34:46
DroneBot Workshop
Рет қаралды 86 М.
ESP32 in a commercial product? - From prototype to production
7:58
Predictable Designs
Рет қаралды 66 М.
3 engineers race to design a PCB in 2 hours | Design Battle
11:50
Predictable Designs
Рет қаралды 506 М.
Tech Note 130 - Solar Power for Projects (Arduino/ESP8266/ESP32)
20:59
Hacking a weird TV censoring device
20:59
Ben Eater
Рет қаралды 3,3 МЛН
Какой я клей? | CLEX #shorts
0:59
CLEX
Рет қаралды 1,9 МЛН