#340

Поділитися
Вставка
  • Опубліковано 1 жов 2024
  • I often get questions about how to measure voltage with microcontrollers. We will look at this topic, at the quality of built-in and external Analog-to-digital converters, and I will show you some “secrets.”
    In this video, we will:
    - See how ADCs work
    - Look at how we can determine the quality of ADCs
    - Compare the ADCs of different microcontrollers with external chips
    - Learn how to tweak the calculations to get the best out of any ADC
    - See how we can extend the range of ADCs
    - Discover some “hidden” things of Microcontrollers and their ADCs
    - Look at different external boards and their usage
    I am a proud Patreon of GreatScott!, Electroboom, Electronoobs, EEVblog, and others.
    Links:
    ESP32 dev board: s.click.aliexpr...
    ESP32 Breakout: s.click.aliexpr...
    ADS1115: s.click.aliexpr...
    PCF8591: s.click.aliexpr...
    AD7705: s.click.aliexpr...
    Nice looking ADC (AD7606): s.click.aliexpr...
    Voltage reference: s.click.aliexpr...
    Voltage Divider: www.ohmslawcalc...
    ADC Theory: e2e.ti.com/blo...
    DAC Theory: en.wikipedia.o...
    The links above usually are affiliate links which support the channel (no additional cost for you).
    Supporting Material and Blog Page: www.sensorsiot.org
    Github: www.github.com...
    My Patreon Page: / andreasspiess
    Discord: / discord
    If you want to support the channel, please use the links below to start your shopping. No additional charges for you, but I get a commission (of your purchases the next 24 hours) to buy new stuff for the channel
    My Amazon.com shop: www.amazon.com...
    For Banggood bit.ly/2jAQEf4
    For AliExpress: bit.ly/2B0yTLL
    For Amazon.de: amzn.to/2r0ZCYI
    For Amazon UK: amzn.to/2mxBaJf
    For ebay.com: ebay.to/2DuYXBp
    www.facebook.c...
    / spiessa
    www.instructab...
    Please do not try to Email me or invite me on LinkedIn. These communication channels are reserved for my primary job
    As an Amazon Associate, I earn from qualifying purchases

КОМЕНТАРІ • 698

  • @shenlong3879
    @shenlong3879 4 роки тому +56

    The external ADC at 2.5V didn't show 2.4994 as you say as per the reference but 2.4594 at 22:22 in the video.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +19

      You are right. My mistake!

    • @projectmanager9116
      @projectmanager9116 4 роки тому

      ua-cam.com/video/AIL36S6NpDA/v-deo.html awesone project

    • @tigerresearch2665
      @tigerresearch2665 4 роки тому +5

      yup. I felt a little spoofed.
      With that inaccuracy it seems that an external ADC isn't really that much better than a software-compensated ESP32 ADC.
      However, the precision of an external ADC could be interesting for scaled up projects: you are trading the extra costs for an ADC to skip the individual calibration process of each ESP32 ADC.

    • @leocurious9919
      @leocurious9919 4 роки тому +4

      @@tigerresearch2665 The external ADC only performs so bad due to his own "correction formula" that very likely only corrects errors on the analog end (aka from V_ref to the PGA inside the ADC). So it shows the correct value at this one point, but not anywhere else. One error that affects the analog end, which I would suspect here: High sampling rate -> low input impedance -> voltage drop Correcting ADC values in code like he does is not something anyone should do. The first step is to correct the hardware/setup!
      Let me compare that to a car that constantly steers to the left: Do you just "counter steer" to make it straight... or do you fix your car so it drives straight?

    • @matzke089
      @matzke089 4 роки тому +3

      Andreas Spiess So, the conclusion of the Video is wrong?

  • @TheDefpom
    @TheDefpom 4 роки тому +45

    If you tweak the adc settings in the ESP32 down to 10 bits, and some other changes, the noise and accuracy gets a LOT better, I’m not at my computer at the moment but I will post the code when I get a chance.

    • @augustinenwafor7673
      @augustinenwafor7673 4 роки тому +2

      Please leave a link on your comment when you do. Thanks

    • @TheDefpom
      @TheDefpom 4 роки тому +1

      Augustine Nwafor - I posted the code in the comments, it’s here somewhere.

    • @skuashh
      @skuashh 4 роки тому +28

      Here is the code of the @@TheDefpom​ comment:
      "Here you go, here is the code to help get the ESP32 ADC to behave better:
      // configure ADC for getting battery voltage
      pinMode(VoltageSense, INPUT); // Battery Voltage Sense input
      analogSetPinAttenuation(VoltageSense, ADC_0db); // set the attenuator for the ADC to allow 1.1V input range
      analogSetWidth(11); // set the resolution width to be 2048 instead of the default 4096 to try and reduce noise
      analogReadResolution(11); // set the resolution to be 2048 instead of the default 4096 to try and reduce noise"

    • @raymondzhao9557
      @raymondzhao9557 3 роки тому

      @@skuashh cool, will try when i have a chance

  • @Graham_Wideman
    @Graham_Wideman 4 роки тому +23

    23:35 Really freaky video compression artifact at 23:35 -- the RF connectors appear to randomly telescope in and out!

    • @shreyaskul
      @shreyaskul 4 роки тому +13

      Because they are not soldered in, he just put them on the PCB just to show the board.
      It's not a video artifact.

    • @Graham_Wideman
      @Graham_Wideman 4 роки тому +1

      @@shreyaskul Yes, on closer viewing, I think you're right. They seem to be rocking back and forth.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +5

      Shreyas is right!

    • @shreyaskul
      @shreyaskul 4 роки тому +1

      @@AndreasSpiess Hey! Thanks for your comment.
      Can you share which IC you have used in your ADC board? That would be great :)

  •  4 роки тому +61

    The AVR ATmega328p used in the Arduino, and other AVR chips, have a special sleep mode for ADC noise reduction. It keeps the ADC running, but stops all the digital processing. See the "ADC Noise Reduction Mode" in the datasheet. It could be that the external ADC chips appear better simply because they are physically further away from the running digital logic.

    • @Slutuppnu
      @Slutuppnu 4 роки тому

      Interesting. I didn't know Arduino had a sleep mode.

    •  4 роки тому +4

      @@Slutuppnu I don't know about the Arduino library, but with AVR-GCC you have fine-grained control over it. www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html

    •  4 роки тому +8

      PS: The Arduino IDE already uses AVR-GCC, so you can use the functions that I linked from Arduino projects as well.

    • @GISED_Link
      @GISED_Link 4 роки тому

      @ is it worth it with a 10 bit adc ? (Atmega16A)

    • @rojirrim7298
      @rojirrim7298 4 роки тому +5

      @@Slutuppnu Most AVR chips (the ones inside arduinos) don't have just one sleep mode but a few of them. It has (as has been said), an ADC noise reduction in which the CPU and some other digital parts of the chip are turned off in order to remove noise from the ADC signal; it has a CPU sleep mode that allows you to save a bit of power during delays or when waiting for a short timer to wake you up; and finally it has a deep sleep mode, in which the CPU, fast clock signal (either the internal fast oscillator or the external crystal oscillator), and most peripherals are turned off, except for the WatchDog Timer (low power timer) and a few more things like pin interrupt wakeups. This allows for very low power applications, in which you can put the chip to sleep and only use a few microamps of current, which for battery applications is really useful. For those types of applications, you have to take care and desolder all the LEDs on the board that you can't control, make sure to avoid using any LDOs onboard, etc.

  • @bobblaine1437
    @bobblaine1437 4 роки тому +8

    Thanks for this video! I've been puzzling over how to reduce the noise of a voltage reading for a project without losing responsiveness introduced by filtering. Based on your video, I switched over to an external ADC (ADS1115) and it solved the problem. Much appreciated!

  • @y2ksw1
    @y2ksw1 4 роки тому +34

    For a very long time I paid my studies by building accurate DAC's for the growing digital industry. Making them precise is a science! 😊

    • @Scrogan
      @Scrogan 4 роки тому +2

      Sounds neat, were they hand-matched R2R ladders? I always wonder why you can’t just buy R2R resistor networks in single packages, like a SIP10. Though these days I’d be tempted to just use a half-bridge and low-pass filter, like a good-old class-d amp.

    • @budward7846
      @budward7846 4 роки тому

      @@Scrogan Try www.digikey.com/products/en/resistors/resistor-networks-arrays/50?k=resistor+array&k=&pkeyword=resistor+array&sv=0&pv9=392120&sf=0&FV=-8%7C50&quantity=&ColumnSort=0&page=1&pageSize=100

    • @AndyPayne42
      @AndyPayne42 4 роки тому

      Yup, I have a esp32 based ph/temp/ec meter I'm doing for hydroponics github.com/physiii/grow

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +2

      @y2ksw1: I can imagine that this is not trivial!

    • @y2ksw1
      @y2ksw1 4 роки тому +1

      James Barclay Yes, with my never patented fool proof method nobody ever thought about before. Pure science 😊

  • @klif_n
    @klif_n 4 роки тому +11

    How timely. I'm just trying to do this right now to monitor the voltage on a battery in my mailbox alerter. :). Thank you!

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +7

      For monitoring a battery the internal ADCs should be ok.

  • @L-36
    @L-36 4 роки тому +8

    I am using an ESP32 to monitor the battery voltage on my boat and send an email if it gets too low. I found the measurements very noisy due to occasional glitches. My solution was to take 8 readings and ignore the largest and smallest and average the middle 6. I do this twice and average them. It is quite easy to do in the code as you just have to keep track of the largest and smallest measurements and subtract them from the sum and divide by 6. I found this better than longer averages so that I did not get multiple glitches in my sample period. The result is very stable and quite fast. I very much enjoy your videos I am a retired circuit designer. I designed test equipment for HP (Now Keysight) and things like cable modems in the early days. Now it is a hobby.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +3

      Good idea because you can eliminate the far glitches. I did not investigate the distribution of the measured values, but maybe they have a pattern you break with your formula.
      I like my Keysight MSOX3045 ;-) Good products!

    • @L-36
      @L-36 4 роки тому +3

      @@AndreasSpiess The distribution was not Gaussian. It was mostly correct values with a few outliers. It is actually a pretty standard way of filtering. There is even a name for it but I can't find it any longer. I learned it from a statistician who worked for me for a short time.

    • @michael_the_chef
      @michael_the_chef 4 місяці тому

      Would it help to put a cap (as low Pass?) between the divider and gnd.

    • @L-36
      @L-36 4 місяці тому

      @@michael_the_chef It has been a long time but I think I measured with a dead stable voltage so the answer would be no.

    • @michael_the_chef
      @michael_the_chef 4 місяці тому

      @@L-36 ok thanks, i am planning to use an ads1115 and an esp32 to monitor a battery Bank of 4

  • @artiem5262
    @artiem5262 4 роки тому +6

    Hints for those starting out -- for built-in ADCs, throw away the bottom bit as it's most likely useless anyway. You can average samples equal to a power of 2 by adding the integer values and doing a right shift -- for example add up 8 integer ADC samples and right shift 3, a useful trick when your microprocessor doesn't have a divide instruction! What's your signal bandwidth? Adding a single pole RC low pass filter in front of the ADC can help. And do not expect the input impedance of the ADC to be constant.

  • @michaelbruns473
    @michaelbruns473 4 роки тому +9

    That was very enlightening, too bad my favorite MC ESP32 yielded such weak (lab) results - still plenty accurate though for many projects. Will look into the ADS1115. Dankeschön !

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +4

      I also use the internal ADC. If you know what you can expect, it is ok.

  • @klaushelmgens8403
    @klaushelmgens8403 4 роки тому +4

    The ADS1115 is a good choice, BUT with my ESP-32 I had some trouble due to the fact that they was in the same casing and WiFi was enabled/used. The results was overlayed with lots of noise. The method of averageing takes to much time for my project. I need the result ASAP and the ADS1115 is anyway no the fastest. But I was able to solve the issue and I want to share this with you guys: First step was to build (3D Print) to boxes which fit in each other with a small gap. The outside of the small box got covered with a copper film. Afterwards I fit the small box in the big box. Why two boxes? Quit simple : isolation. The copper film I connected to ground. Inside the box I placed the ADS1115. For the cables I made small holes and the cable which is going to the probe is an coaxial. Problem solved. What I want to say by this is, that the interference of the RF signal has not to be underestimated!

  • @MarcoTedaldi
    @MarcoTedaldi 3 роки тому +5

    Awesome. Thank you for the great content! Just my two cents:
    1. I've had to learn the hard way, that many (all?) of the ADC that have a MUX only have a single S/H aufter the MUX. This leads to problems, when reading signals on different channels with very different voltages in quick succession. There is quite a bit of "crosstalk". It's really important to make sure that the inputs to such an ADC are low impedance.
    2. When I do averaging on a uC, I do 2^n samles (8, 16, 32...1024) samples, add the read values up (make sure to prevent overflow) and just use shift for the division at the end. Especially on uC without an FPU this speeds the averaging up quite a bit.

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому +1

      Good info. Thank you! I would have expected only one S/H, though, because it is usually part of the ADC.

    • @TheRainHarvester
      @TheRainHarvester 5 місяців тому

      ​@myselfremadedid you ever find an answer?

  • @jenskaa4044
    @jenskaa4044 4 роки тому +13

    Nice video.
    Remember to consider the input impedance of the ADC, especially if you use high value resistors for a voltage divider in front.

    • @uwezimmermann5427
      @uwezimmermann5427 4 роки тому +6

      since the input is in parallel to the low-side resistor of the voltage divider only its value really matters - well actually it is of course the parallel-combination of the upper and lower resistance in the voltage divider...
      And for the ATmega328 the input resistance of the ADC-channels is astonishingly high! I tested it with discharging a 1µF capacitor from 5 V to zero through a 100 MΩ resistor - it took about 15 minutes to discharge and the resulting curve indicates an input resistance beyond 1 GΩ.

    • @Scrogan
      @Scrogan 4 роки тому

      Uwe Zimmermann
      I was going to ask what you used to measure that voltage, but I guess you were just using the ADC itself. I imagine most of the leakage current will be through the protection diodes, if it had none then it would be a real recipe for ESD. Which reminds me of a friend using his atmega ADC for measuring back-emf of a solenoid. Directly on the 12V half-bridge output that was powering the solenoid. With no extra diode or resistors. The arduino got really hot, but somehow the circuit actually worked.

    • @jenskaa4044
      @jenskaa4044 4 роки тому

      @@uwezimmermann5427 I am not talking Any specific microprocesor. I had an adc in a low power circuit where I wanted to messure the battery voltage, here I used a resistor divider in 10 Mohm Range to avoid draning the battery. In this applikation the messured voltage was wrong due to current flowing into the mcu.

  • @bm830810
    @bm830810 4 роки тому +17

    I recommend using median filter for removing ESP32 ADC glitches, averaging is not good for this kind of noise

    • @valcob6617
      @valcob6617 4 роки тому +12

      The formula @Andreas Spiess is using is not the usual average formula. He uses a so called filter with feed back and I don't know why he is calling it average but that one for sure is not just an average. And the second point when he says "when I use 10 samples or even 100 samples in that formula" .. those are not the actual samples. That number tells how much we should fed back to the initial value so basically to explain it we have an initial x=0.551 and in the loop he is calculating the next x by taking 99 parts of original x value (0.551) and adding 1 part of the new analogRead value thus it basically means we are just drifting to the left or right of the initial value and the amount of drift is expressed in the ratio we are using 1/10, 1/100, 1/1000 and so on parts of the new value mixed back to the initial one. Also this number will be the speed of conversion to the initial value so the higher value we use the slower is the speed and the more analog reads we need to go back to normal and at the same time the less is the chance to affect the final number by the new erroneous reading. Maybe @Andreas Spiess does not fully understand the formula he is using which I doubt but who knows maybe he can explain it in some further videos.

    • @bm830810
      @bm830810 4 роки тому +2

      @@valcob6617 This is a simple IIR filter (meaning the response never reaches steady state theoretically), its good for quick & dirty filtering

    • @bm830810
      @bm830810 4 роки тому

      @@valcob6617 Also the filter is prone to accumulating round off error for high filtering coefficients and my guess is this is why he gets 10% error on ESP32's ADC

  • @agf9995
    @agf9995 4 роки тому +4

    Greetings from South Africa Andreas. Well done as usual! I am always surprised how much information you share with great clarity and structure in such a short video clip. When I learnt this stuff (long before internet), choices were fewer and one had to study the data sheets thoroughly (or copy somebody's example from Elektor, EE, ETI etc). Microcontrollers (with built in ADCs) only arrived later and choices were fewer - which was a blessing, because obsolescence took longer. Hobbyists today should be thankful that you share years of experience, crammed into a nutshell...and for free. Love your work and your very structured method of teaching (unlike my ADHD brain which likes to skip around). Best Regards, Allen.

  • @TheDefpom
    @TheDefpom 4 роки тому +1

    Here you go, here is the code to help get the ESP32 ADC to behave better:
    // configure ADC for getting battery voltage
    pinMode(VoltageSense, INPUT); // Battery Voltage Sense input
    analogSetPinAttenuation(VoltageSense, ADC_0db); // set the attenuator for the ADC to allow 1.1V input range
    analogSetWidth(11); // set the resolution width to be 2048 instead of the default 4096 to try and reduce noise
    analogReadResolution(11); // set the resolution to be 2048 instead of the default 4096 to try and reduce noise

    • @TheDefpom
      @TheDefpom 4 роки тому

      Also another trick I found is to add a delay directly before the read, it helps get a more stable reading too! 50ms worked well, but you can’t always do that obviously.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +1

      I never tried to reduce the resolution and compare it woth averaging. Good to know. Thanks!

  • @freepoet6737
    @freepoet6737 4 роки тому +6

    Nice comprehensive review, one question comes to my mind, is the ESP32-S2 any better than the ESP32?

    • @Sovvyy
      @Sovvyy 4 роки тому +5

      Notf sure overall, but the esp32s2 has a bit width of 13, compared to the esp32's 12 - which is significant.
      I don't think it's shown in the documentation yet? However idf alerts you to this when compiling and it can be seen in the respective header files (of course it works too!).

    • @cbm80amiga
      @cbm80amiga 4 роки тому +3

      The same BS :)

    • @krukhlis
      @krukhlis 4 роки тому +2

      @@Sovvyy It's just a marketing. I've tried this to monitor charge of the battery -- it's useless in the same way as regular ESP32 or ESP8266 that ESP32s2 should replace. Use only external battery controllers chips, internal ESP ADC is useless for such sensitive things. And what I hate the most with ESP -- this "filtering" formulas with magic numbers -- you need to adjust it for each and every chip. I never had any 2 chips in ESP32 or ESP8266 lines with the same ADC errors.

  • @giuseppedanilovaccarella8026
    @giuseppedanilovaccarella8026 4 роки тому +3

    Thanks for another fantastic video. Just for curiosity, if I insert a delay(1) between each analogRead(A0), the measurements related to WeMos D1 Mini have more fluctuations than without it. Is this due to the capacitor in the Sample and Hold circuit that discharges faster by inserting delay(1)? It is evident within low serial baud rate. Thanks

  • @ericon.7015
    @ericon.7015 4 роки тому +4

    I never get tired to watch your videos. I like the fact that you put your personal opinion in each fact. I understand better this way. Thank you

  • @jorgefeal7716
    @jorgefeal7716 3 роки тому +1

    Hi folks,
    I'm trying to get a voltage sensor to measure over 50V DC on an Arduino microcontroller. Any recommendations?

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому +1

      You can google "voltage divider calculator". Then you can can calculate the two resistors to get the voltage down to the range of your sensor

  • @johnhutchens8970
    @johnhutchens8970 4 роки тому +3

    The ADS1115 is my favorite ADC for microcontrollers. I started using it when I moved over to 32bit microcontrollers, but needed a way to read 5V automotive sensors (using a Teensy 3.2). I had 4 sensors (an MPX5700AP pressure sensor, an NTC thermistor, an AEM Wideband oxygen sensor and a 0-100psi oil pressure sensor), the ADS1115 had 4 inputs, it was a match! I didn't have to average values to get a stable reading, like you said, the stability of the ADC is fantastic.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      Thank you for sharing your experience. This seems to be a perfect solution.

  • @TannerFrisby
    @TannerFrisby 4 роки тому +4

    Thanks for putting out such high-quality videos regularly!

  • @knyazhefilms2154
    @knyazhefilms2154 4 роки тому +6

    Very interesting. Thank you. BTW I've learned to copy your accent! Now I speak like you.Or.Very Similar. Really :) Doing it for fun when reading loudly a new tech. topic:)

    • @michaels3003
      @michaels3003 4 роки тому

      The Professor should copyright that. We don't want any impostors on the YT.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +3

      @knyazhe: Wonderful! An Italian boy also imitaded me on Facebook ;-)

    • @knyazhefilms2154
      @knyazhefilms2154 4 роки тому +1

      @@AndreasSpiess Oh .. now it's a competition :)) perfeetto :)

    • @GRBtutorials
      @GRBtutorials 4 роки тому

      Luca Capelli And of courrrrse, here is my caaat!

  • @davefiddes
    @davefiddes 4 роки тому +2

    Useful concise video as always. I would recommend using a simple digital filter (IIR filter) rather than averaging. It will actually use the thermal noise which is inherent to the the SAR process to improve the accuracy. I found this to be a useful reference: tttapa.github.io/Pages/Mathematics/Systems-and-Control-Theory/Digital-filters/Exponential%20Moving%20Average/Exponential-Moving-Average.html
    I despair of the Wemos D1 component values on the analog input. The input impedance of the ESP8266 is something like 25k but with the 200k/100k potential divider you end up with a lot of noise in the input signal as it charges the sample capacitor in the S/H circuit. Swapping the resistors for something smaller and more appropriate improved things. It's still not a very good ADC though.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      Thanks for the link. Another commenter said, my moving average formula is an IIR ;-) Exponential averaging is also a good way. But you have to pay attention to speed for some processors.

  • @meclucas
    @meclucas 4 роки тому +4

    Very interesting video as always, thank you.
    Another benefit of using the ADS1115 is that the internal PGA can be configured to read a differential signal, this is very useful for measuring some sensors, although it also results in a slower data acquisition rate.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +1

      True!

    • @sewingmachinesindetail
      @sewingmachinesindetail 11 місяців тому

      This trick can also be used in general by the Arduino by using two analog inputs connected to the signal direct and the signal amplified by a fixed op amp.

  • @mahudson3547
    @mahudson3547 4 роки тому +4

    At 12.07, I love the way you dodge the 1023/1024 argument!

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +2

      I had enough discussions about that in my life. So I once used 1023 and once 65536

    • @TheRainHarvester
      @TheRainHarvester 5 місяців тому

      ​@@AndreasSpiessWhy was there ever an argument? (1023/1023 =1) Just curious

    • @AndreasSpiess
      @AndreasSpiess  5 місяців тому

      @@TheRainHarvester Because of the 0

    • @TheRainHarvester
      @TheRainHarvester 5 місяців тому

      @@AndreasSpiess if you can measure the voltage at the high rail, you divide by 4095 so you get 1* vcc.

  • @leozendo3500
    @leozendo3500 4 роки тому +1

    I have a similar adc module with just 2 16bit ADCs and 50Mhz sample rate. It's like 40usd on eBay. It would be incredible if you want to make a video about how to read data off these cracy fast parallel lanes. My primary goal was to reduce cost. I thought it would be interesting if we can dump all the ADC data straight into a ram with some hard logic, and read the ram with some cheap slow microcenter. Thus eliminating the need of fpga.

  • @peterpepo9232
    @peterpepo9232 3 роки тому +2

    Thanks for this awesome intro to the ADCs!
    I'm going to measure voltage of my LiPo cell, so I know when to charge it :)

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому +1

      I do this too for most of my battery operated nodes

  • @matyasmatous9213
    @matyasmatous9213 Рік тому +1

    hi i would like to know what the x in the wemos d1 mini code stands fore or would you be so kind and poste the code please

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      This line calculates a moving average of the measured value.

  • @Arrowtake
    @Arrowtake 4 роки тому +7

    Thanks Andreas, once again learned alot!

  • @GRBtutorials
    @GRBtutorials 4 роки тому +1

    One more thing: you should divide by 1024 and add one LSB instead of dividing by 1023 because there are 1024 steps, not 1023, and you’re scaling the ADC’s output incorrectly if you do so. This article explains it: forum.allaboutcircuits.com/threads/why-adc-1024-is-correct-and-adc-1023-is-just-plain-wrong.80018/

    • @krukhlis
      @krukhlis 4 роки тому

      It's another historical holy war with long roots. :)

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      I do no more care. There are two fractions. It does not matter in any case if you calibrate your factor to a measured value (BTW: I used 65536 in another place to use both concepts. It did not help ;-)

    • @GRBtutorials
      @GRBtutorials 4 роки тому

      Andreas Spiess You can’t correct the error with a single point calibration, it’s a scaling error. It’s minor (hence why you might not have noticed anything) but important if you’re doing something that require high accuracy, and a good practice in general. Though I guess it’s not that important for most of your projects.

  • @timballam3675
    @timballam3675 4 роки тому +3

    People are complaining about the ADC of a sub $5 MCU, they are like brexiteers, you can't have your cake and eat it.

  • @IchrisiI
    @IchrisiI 4 роки тому +1

    Hello,
    thanks for the in depth explanation!!
    Can you explain where is this
    float y = (x * 1023.0 / 331.0) ; coming from? In detail the term 1023.0/331.0 ... min19.45
    also in min18.11 I do not understand the 5/497 :(
    many thanks for help

    • @vlastimilhajek6371
      @vlastimilhajek6371 2 роки тому

      I don't understand this either. If x is a digital value, to calculate real voltage we need 1lsb voltage coef. Which is max_voltage/max_resolution. So, the proper formula seems to be: float y = x * 3.09/1023

  • @DavidinEssexUK
    @DavidinEssexUK 4 роки тому +2

    So if your running an esp32 from battery and you want to test for low battery how would you do that as you don’t have a stable reference voltage?

    • @aaron41
      @aaron41 4 роки тому

      Use a separate chip with an internal reference like the ads1115

    • @GordieGii
      @GordieGii 4 роки тому

      I would connect a precision voltage reference chip to one analog input and calculate what Vcc would produce the measured value. The number goes up as Vcc goes down. You could also use this value to scale the other three analog inputs. Seems backwards, but it should work.

    • @pfeerick
      @pfeerick 4 роки тому

      I beleive you can still use an internal voltage reference on the ESP32 - via `adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_0db);` ... You can see more about the ADC in Espressif's ESP-IDF documentation (which you can use in Arduino code still) at docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html

  • @AkosLukacs42
    @AkosLukacs42 4 роки тому +8

    Don't forget about adc noise reduction in Atmega. Automatic sampling, averaging without CPU intervention or built-in comparators & other advanced features in bigger Atmegas, STM32, nRf52, and most other arm uCs.

  • @TheAoab50
    @TheAoab50 3 роки тому +1

    Thanks for the video, I had a problem with the adc fluctuating reading with my arduino, I never knew that there are imperfections in these microchips.
    I wish you also compared an STM32 board like the black pill (STM32f411)

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      I thought I did this in another video.

  • @JanJeronimus
    @JanJeronimus 4 роки тому +3

    As always a verry interesting video.
    By the way it is also possible to do other things than averaging. E.g. dropping the spikes / outliers.

    • @ThijsVandenrijt
      @ThijsVandenrijt 4 роки тому +5

      To remove this kind of "shot noise", a median or percentile filter is a common and easy-to-implement method!

    • @gerleimarci
      @gerleimarci 4 роки тому +1

      Or simply use "Olympic average"

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +3

      @Jan. True. I just used this simple one, also to show the formula. Many people store all values and then create the average, which is not good in a MCU environment.

    • @zawilious
      @zawilious 6 місяців тому

      ​@@AndreasSpiess
      Can you plz explain how the averaging formula works ? And how you get the 3.09 number for correction you used for esp32 test

  • @alexandern8671
    @alexandern8671 4 роки тому +1

    Another great video from a very competent presenter.
    Just a point for a possible misconception: there are two other ADC architectures in common use, namely pipelined and sigma-delta. The first tries to keep the number of parallel comparators required in check by converting the output of a comparator stage back to analogue using a DAC, subtracting this output from the original input, and feeding the result to another comparators' stage. Three stages are quite common with typically 4bits per stage; leaving aside the unavoidable latency the conversion takes one clock cycle like the comparators' ADC. This breaks for high resolutions because analog subtractions accumulate too much error. Then sigma-delta comes to the rescue where in fact a control system tries to get its 1 bit output bitstream average as close to the input as possible (its operating principle is not easy to understand in detail though); 24 bits and higher resolutions became possible.
    Successive approximation is favoured by the MCU manufacturers for a very simple reason - it requires a single analog comparator and an R-2R DAC - cheap, accurate and reproducible architecture that covers nearly all practical DAC needs. Moreover it can be difficult to find a standalone successive approximation ADC as most are either pipelined (higher sampling rates) or sigma-delta (for high, eg audio, resolution).
    Again for a typical maker these are too finer points but I wanted to make sure they are mentioned in the footnote. Thanks again Andreas for your work

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      Thank you for your explanations. I always learn something from my viewers! As you saw I am more a user and not a specialist in this matter.

  • @whaidRiyal
    @whaidRiyal 4 роки тому +1

    My Esp8266 over heating issue.How to solved.

  • @Mr_Zisky
    @Mr_Zisky 2 роки тому +1

    Perfect! Thank you for this video! I am working on a project now with analog sensors and i learned everything I needed to!

  • @tonysfun
    @tonysfun 4 роки тому +1

    I'm amazed every time I see your great videos!!! You are testing stuff that went true testing before manufacture, but you made it better - why isn't Arduino listening??? If Arduino and ESP's had better ADC, the cost would not be that much higher - right? But now we can use your recipe and suggestions! Thank you again Andreas. And wishing your finger to heal FASTER!

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +2

      I am sure they have their constrraints. Create chips for a few cents with 3 CPUs and Wi-Fi is for sure not easy.

  • @Johann75
    @Johann75 8 місяців тому

    Such a good explanation. I was desperate to understand why my reading are so wrong... Thank you Andreas. Would something like below also work?
    int adcValue = analogRead(ADC2_PIN); //ADC2_PIN is an Adruino constant for ESP32 build-in internal reference voltage PIN on ADC2 (Analog-to-Digital Converter 2)
    float voltage = adcValue * (DEFAULT_VREF / [ADC_RESOLUTION]); //DEFAULT_VREF is am Adruino constant for internal reference voltage value (1100.0)

    • @AndreasSpiess
      @AndreasSpiess  8 місяців тому

      I do not know what it should enhance. Noise can be "filtered" by averaging many readings, and systematically wrong values by calibration (store the difference to the exact value in EEPROM). All other effects are hard to eliminate (or even not possible)

  • @Scrogan
    @Scrogan 4 роки тому +1

    Neat video! I’d have liked it more if you went over the details of successive approximation registers, and how a delta-sigma ADC (or DAC) works, but maybe that’s outside the scope of this video. On the topic of ADCs and DACs, I’d be interested in a video on DSP algorithms being implemented in an arduino, be it for audio or for filtering out narrow-band noise.
    Also when you said that SDRs use these very high speed GHz ADCs, I don’t think they actually do. They use lower speed ADCs with mixers and tuneable local oscillators to generate the I and Q signals. Direct sampling SDRs are very rare.
    I’d also have mentioned the fact that the ADCs have a finite input impedance, so putting a network of resistors in front of one without buffering it after could cause some systematic error. Well, you often use an instrumentation amplifier there anyhow so maybe it’s not too useful of a tip.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      1. This channels is for makers, so the most important decision is what not to show.
      2. I define SDR not only as "SDR receivers for the general public". I define them as "digitalize the signal and do the processing in software". So radar and many other applications fit my definition.
      3. You are right with the input resistance. If you calibrate the readings I assume you can live witout an instrumentation amplifier for 10 or 12 bit resolution. For more precise applications you are right, of course

  • @TheBreadboardca
    @TheBreadboardca 4 роки тому

    You say at 6:15 the Arduino (ATMEGA328) uses 5V for its reference and for an Arduino that is the default for sure but not the ATMEGA328. it happens to simply be the default that the Arduino Abstraction layer uses in its IDE. It is fully programmable between an external reference, an internal 1.1V band gap reference and of course VCC. they use VCC because it gives a simple range to the user and matches the most lightly voltage they will use for the external circuits that will be used to feed into it. this is perfectly reasonable but as I said... not the ATMEGA doing it but the Arduino IDE programmer.
    You also have to remember that the internal Vcc choice will be different depending on the micro-controller, a 328 based arduino is typically 5V by default (Or more specifically what ever the USB power is and can be close to 4.75 v), A sam based arduino may only be 3V3 (Nominally) etc etc. even the internal references are different between each micro-controller see this for more
    www.arduino.cc/en/Reference.AnalogReference
    www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
    Default to Vcc is for simplicity, not accuracy, if you want accurate, choose an external precision Vref or the internal Band Gap reference and add the required external voltage dividers to match

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      You are, of course, right. In video #10 I showed how to use the internal reference ;-)

  • @TheBreadboardca
    @TheBreadboardca 4 роки тому

    at 9:30 describing SAR, you first say it would take 4000 samples to get the result, this is not SAR. SAR only ever takes the number of clock that = number of bits so a 12 bit ADC SAR would take 12 clocks. BTW, I do love your videos and find them very well presented and prepared, I am just trying to ad to the excelent presentation you have here for new engineers that may miss interpret the info

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      You are right with the number of 12. There I made a mistake by saying "around 10". The 4000 points was the explanation without SAR.

  • @noslackyak
    @noslackyak 4 роки тому +2

    Seriously good video. Thanks man! Appreciate your hard work :)

  • @juanramirezjardua2082
    @juanramirezjardua2082 4 роки тому +2

    Thanks Andreas for this interesting video. I've used ADC lots of times, and never had concerns about the quality of the conversion (noise reduction with average method). In a current project, getting feedback from the servo's potentiometers for a robotic arm, I've used a calibration table, but now I'm going to introduce your formulas. Thanks again, Juan.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      It depends on the desired accuracy. I compared, of course, with the data sheet.Calibration tables are good if the ADC is dependable wrong and not stochastically wrong...

  • @0124akash
    @0124akash Рік тому

    Sir, i will try to make dc volt meter using ESP32 wroom but am facing some critical condition
    Actual voltage is applied for measuring 12.7V
    ESP32 display 12.7
    If i applied 7.4V
    ESP32 display 6.9V why sir ?
    After this problem am using Arduino UNO
    This board is accurate measure voltage in range.
    ESP32 is not for voltage measurement ?
    Can you give me any solution sir ?

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      Unfortunately, I cannot do remote debugging. But you can draw a curve when you apply from 12.7 to 0 volts. Then you see if the ESP shows linear values or if it has some non-linearities in the curve. Then you might correct it with a formula.

  • @grimtagnbag
    @grimtagnbag 21 день тому

    Nailed it again. Thank u for your work. You always have what I need. Explained in full. Perfect

  • @WacKEDmaN
    @WacKEDmaN 4 роки тому +2

    very nice info there Andreas, thanks, it will come in handy...
    id be interested in seeing an RTL-SDR ADC compaired to these MCU ADCs

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      It is quite different. If I remember it has only 8 bits. But of course, it is faster.

  • @0124akash
    @0124akash 8 місяців тому

    Sir, can you make video for DC volt meter (0-300VDC) and AC volt meter (0-350VAC) using
    Esp32, ADS1115, 16*2 LCD

    • @AndreasSpiess
      @AndreasSpiess  7 місяців тому

      I do not think so. These meters are very cheap these days...

  • @kaikart123
    @kaikart123 3 роки тому

    What about STM32s ADC's accuracy? I heard they are pretty good with 12-bit resolution and high sampling rate.

  • @Regimantas_Baublys
    @Regimantas_Baublys 4 роки тому +1

    Nice video :) 2 mistakes.Forget sigma delta adc. And arduino impedence is 10k becose of hold capacitor so voltage divider resistors values is to high

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +2

      Thanks for the corrrections. I forgot more than just the sigma delta converter.

  • @isprithul
    @isprithul 4 роки тому +2

    Would you please make a video about how delta sigma ADCs work?
    Thank you

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +3

      Unfortunately I do not understand it :-(

    • @giovanniazzali9616
      @giovanniazzali9616 3 роки тому

      @@AndreasSpiess Hi Andreas, the sigma-delta ADC is less complicate than it seems. Imagine that you have a capacitor in series with a resistor, and you have a 2 position switch by which you can choose to charge the capacitor or discharge it. Now, if you want to make the voltage across the capacitor equal to the input voltage that you want to measure, you will have to continuosly move the switch from one position to the other, The voltage across your capacitor will zig-zag around the target voltage that you want to track. When the input voltage is high, the switch will have to stay in the ON position longer than in the OFF position, and viceversa. If you measure the time that the switch has been in the ON position in each sampling interval, you have a digital representation of the input voltage. Not sure that this short explanation is clear or accurate, but I hope that it helps!

    • @giovanniazzali9616
      @giovanniazzali9616 3 роки тому

      @@AndreasSpiess Perhaps my previous explanation was oversimplified, but you can find a nice "demo" here: www.analog.com/en/design-center/interactive-design-tools/sigma-delta-adc-tutorial.html

  • @franciscogaray2129
    @franciscogaray2129 2 роки тому

    Good Afternoon from south America. Andreas I have a doubt. ADS115 have a max. resolution 860S/s, to 16 bits it's equal to 41280bps (data=16bits+newline=8bits) it's correct this?
    If I needed more channels for example 4 channels I would need another other mcu...or Arduino could help me?

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому +1

      I cannot follow. But the resolution is in bits and the speed is in conversions per second, not pits per second. Maybe you consult the data sheet for details.

  • @guangyang8596
    @guangyang8596 Рік тому

    HI, I am newbie and have a question here may be very stupid... , for the equation that can get the voltage, why is x * 4095/1134, not x * 1134/4095? x not the adc value? Thanks for your answer

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      Make the calculations yourself with the highest reading of the ADC (4095). You probably get a strange voltage with your calculation.

  • @RoyAndrews82
    @RoyAndrews82 2 роки тому

    VRef is applied to the inverting inputs ( - ) of the operational amplifiers. When an input signal (voltage) is applied to Vin (non Inverting Inputs) ( + ), then the operational amplifiers will turn on accordingly because of the rules of the operational amplifier logic as a comparator. The way you have it, if Vin is zero, then all outputs on the operational amplifier is logic HIGH. So LEDs on the outputs on the Operational Amplifiers would turn off instead of turning on when an input signal is applied to Vin.

  • @dreamcat4
    @dreamcat4 4 роки тому +2

    I have to say.... Given how poor these microcontroller built in ADCs are. Then it would have been nice to also include STM32 lines for comparison. As that is a common one used in industry.

    • @dreamcat4
      @dreamcat4 4 роки тому

      In fact it was one of your conclusions in the video at the end. You said to everybody: well if you need an accurate ADC then it must be external. However by not including STM32 in your evaluation. Then it's ignoring all the people who have now begun using STM32 platforms for hobbyist use. And we can see that while being harder to choose from, they have a much broader range going up much higher in price and features. So inevitably at some point when you get up to the price of an Esp32 then its going to include a significantly better ADC yes? Well this is imprtant decision whether to integrate the wifi on the mcu itself and then have a seperate ADC. However with STM32 it is the other way round. You then might integrate the ADC but instead put the wifi off aways a distance (not to interfere). Like by attaching some external ESP8266. Since ST platform do not make wifi so easy as ESP does.... It is a choice to make early in a project., before going too far down either road. So before starting a project then I think this topic is an important discussion. Before fixing the design. Actually i ask the same question to somebody else recently after watching your video: 'well why not use the esp32 since it is so fast'. Well here is the answer. And these same questions also apply to the Nordic Semiconductor Devices. If they are to 'do a better job' and replace these shortcomings of the esp32

    • @meanxmeanx1763
      @meanxmeanx1763 4 роки тому +1

      I was surprised too.The STM32F1(bluepill) has 2x 12 bits Adc that can up to 1M/S with something like 6pins available. And it supports DMA, so you can high speed capture with little CPU time.The GD32 compatible chips even have hardware oversampling, so averaging is free.. The bluepill uses VCC as reference , BUT you can measure VCC, so it's not a problem.2x 12 bitsADC @ 1Ms/S for 2$ ? by far the best for that usage.

    • @uwezimmermann5427
      @uwezimmermann5427 4 роки тому

      define "poor" ?!?
      The built-in ADC in the ATmega is not poor at all for its specifications. A lot depends on your choice of reference voltage and front-end. I am currently working on a project with an STM32 and had to sadly realize that the lower-pin-count versions do not allow even to use the built-in bandgap reference for the ADC or DAC, only the VDDA supply voltage...

    • @dreamcat4
      @dreamcat4 4 роки тому +1

      @@uwezimmermann5427 Yes thank you for bringing this up. Actually I was more talking about the shortcomings of the ESP32 chip there (and not the Arduino, and thank you because your point about having a good accurate Vcc is not only unique to the Arduino). And of course ATMega also have other MCU products. Furthermore I am so happy you bring up is how confusing the STM32 product line is, because the low medium and high pin count versions has different features set. So it's like a 'Matrix of Tiers' xy instead of 'just simply have a single tier structure'. But in addition to that there are now also legitimately license STM32 clone parts. Which themselves also have even more hidden differences. It's really a drawback for hobbyists. To have such a huge and complicated range of products to have to evaluate across. You get a feature X but give up a feature Y. So this is why I also am asking about alternatives such as those new Nordic Semiconductor MCUs who Andreas has noticed are now getting Arduino IDE support.... If they really are better than ESP32. Then how their range of products compares against STM32 platform. For the simplicity, the actual features and performance, and the cost. In the meantime perhaps having some STM32 'cheat sheet' would be useful. To de-confuse the linup and extract the most essential differences between them out from the datasheet(s). Or a sort-able Google Sheet document or something. Even better if it also included other MCU families from ATMega, Nordic, etc. It seems that ST themselves expect us to use their 'ST-MCU-FINDER' application for android / iOS / windows. While for Atmel (now acquired by Microchip) their online parametric search tool www.microchip.com/maps/Microcontroller.aspx ... Each want you to buy into their respective platforms / eco systems. Elsewhere I cannot find a good independant cross manufacturer comparison. Including comments critical about quality of features such as ease of debugging etc. Details ehich just the basic numbers on a spec page like how many ADCs does not reveal. Not without a deep dive into the datasheets. Which is pretty time consuming. Not so practical when trying to get a bigger picture 'birds eye view' across all these many different MCUs.

    • @uwezimmermann5427
      @uwezimmermann5427 4 роки тому

      @@dreamcat4 a general cheat sheet about and across microcontroller families sounds like a great idea. I would be willing to contribute... just don't know what the best platform would be: google, git, ...

  • @Lion_McLionhead
    @Lion_McLionhead 4 роки тому +1

    They’re not always linear, either. Trap for young players.

  •  11 місяців тому

    I'm surprised that the 24 bit HX711 ADC was not also covered in this video. It's designed supposedly specifically for load cells but I'm curious if there is something special about it so that it can be used with (and only with) load cells or if it can be used as a general purpose ADC?

  • @chesshooligan1282
    @chesshooligan1282 Рік тому

    We also have an additional problem with the ESP32: the input-voltage-to-ADC-reading graph is not linear but kind of parabolic. It seems you need to use an external ADC if you need a reasonable degree of accuracy,.

  • @synergie8
    @synergie8 8 місяців тому

    FYI.
    Re: ADS1115
    It seems to be OK to supply input voltage to the ADS1115 even when it is not supplied with Vcc.
    i.e I have a project where I am measuring the voltage of a car battery, using a ADS1115 and a ESP32 , using a voltage divider to reduce max of 16V to 3.3V on the input of the ADS1115
    If I remove the supply voltage, the ADS1115 seems to survive even though the input was 3.2V and Vcc was 0V.
    Possibly this is because I'm using 4.7k in series as part of the voltage divider, so the current would be limited to about 3.5mA.
    In hindsight, I will try using higher values for the voltage divider and use a reservoir capacitor to reduce the effects of the higher impedance input.
    e.g. try 47k and 12k as the divider, so that the max current would be only 0.3mA
    PS. I just accidently destroyed on channel of ADS1115 by shorting the 4.7k resistor with a solder bridge, hence supplying 16 to one input, but the other inputs still work OK.
    So when I rebuild my prototype I will change the voltage divider resistances.

    • @AndreasSpiess
      @AndreasSpiess  8 місяців тому

      So you were lucky that only one input was destroyed... I try to stay inside the limits of the data sheet.
      Maybe the chip has an input protection diode towards VCC and as you write, this protects the chip during power off.
      And you are right, you can use higher resistors for the voltage divider.

    • @synergie8
      @synergie8 8 місяців тому

      @@AndreasSpiess
      I actually destroyed 2 inputs, because I shorted 2 resistors. However the other 2 inputs still work OK.
      Before I replace the module I will do some more testing on the 2 remaining operational inputs to see how much current is taken by the ADC inputs when the battery I am measuring is still connected, but the supply to the ADS1115 is removed, i.e I don't power my entire sensing board.
      Like you say, there is probably a protection diode to Vcc on the ADC inputs, but this diode is probably only designed to protect when the supply is removed from the ADS1115 when there is a series resistor connected to the ADC input.
      I wonder if someone had a 1.5V battery connected directly to the input of the ADC, whether the input would be destroyed if the ADC was not powered.
      I also need to experiment with higher value resistors in the voltage divider, to increase protection, The manufacturer seems to recommend resistor dividers with values around 1k Ohm in total, to prevent measurement error, according to a post on their forum. However the input impedance of the ADC is 3M Ohm, so higher values should not cause significant measurement error and adding a reservoir capacitor will also compensate for the higher resistor values albeit slowing response time.

  • @IamTheHolypumpkin
    @IamTheHolypumpkin 3 роки тому

    Wait, when I understood correctly, most ADC in Microcontroller have an build in DAC?
    Why do they not expose the DAC to external pins?
    Why do I have to buy an external DAC board to get Analog out?
    So few Microcontrollers have an build in (accessible) DAC.

    • @AndreasSpiess
      @AndreasSpiess  3 роки тому

      The ADCs have an internal DAC, yes. They are probably too specialized to be used also for external purposes. Otherwise companies would do that. I also do not know why a lot of chips do not have DACs. I assume it is the market demand.

  • @jmachorrov
    @jmachorrov Рік тому

    All adc with suc. Aprox check fron hi to lowes bit if adding is bigger HS vulue itn is not ser .... So on for eaach bits

  • @n.t.1243
    @n.t.1243 4 роки тому +1

    Watched already a lot of videos of your channel and at the beginning it was a lot of „häääää, versteh grad überhaupt nix“ but from one video to the next I start to understand what you are explaining us. Have to say that I am a totally new beginner.
    My goal is to measure the 2 12V Solar Batteries in the OFF-Grid garden of my parents in law. Tried a lot with the ADC from the ESP32 itself and as u mentioned it’s readings are just bullshit.
    Thank you for introducing the ADS1115 to me. I guess that will fix my measuring problem and can finally bring the project into production.
    As I am original from Vorarlberg and worked many years in Kanton SG I love to hear your swiss accent as it remembers me of that great time in my life!
    Electronic wise you are my personal hero ;-)

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +1

      For this purpose you probably could also use a INA226 as suggested by other commenters.
      And I am glad you learn something with each video. We all started as beginners in this field.

  • @sewingmachinesindetail
    @sewingmachinesindetail 11 місяців тому

    Thank you very much for this video. I got a question regarding the ATmega328p, that I guess is used for Arduino uno now and in your test. When I read the manual for the chip page 211, there is an ADC Noise Canceler. It allows stop of CPU execution while the ADC is active. It will typically prevent interrupts being executed for about 54 or 108 us while the ADC is active. For many applications a 108 us delay for some interrupt is not desireable.
    I would think, that your test did not include this Noise canceler process - am I right?
    How was the prescaler set - or what was the clock frequency for the ADC in your test?
    Do you have any idea on how accuracy is degraded, if you increase ADC clock above 200 kHz?

    • @AndreasSpiess
      @AndreasSpiess  11 місяців тому +1

      I just used the "normal" Arduino code. So whatever settings are used there are used in my tests (I even did not know the details you mention).

    • @sewingmachinesindetail
      @sewingmachinesindetail 11 місяців тому

      @@AndreasSpiessThanks. I have read some parts of the hardware description, but I am still not familiar in reading the "normal" Arduino code. My best guess based on what i could understand is, that the noise canceler is not used. The ADC clock is set to 125 kHz. I have seen indication, that the ADC should be able to work quite well up to 1 MHz. One reading takes 13½ clock cycles.

  • @KelvinNishikawa
    @KelvinNishikawa 4 роки тому

    The ADS1015 is a drop-in replacement for the ADS1115 and can provide much better stability and speed, but is only 12 bits. Conversion is 3 to 8 times faster when reading values over I2C and sample rate is more than 4 times faster. It's also half the cost and has the same footprint.

  • @AjinkyaMahajan
    @AjinkyaMahajan 4 роки тому +1

    Using Arduino PWM for signal generation and internal comparator, a precise DelSig ADC can be implemented in Arduino for precision work.
    For reference, read the Parallax app note.
    Link - www.parallax.com/sites/default/files/downloads/AN008-SigmaDeltaADC-v1.0.pdf
    Thanks for sharing.✨✨
    Cheers

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +1

      Interesting concept. Did you try it?

    • @AjinkyaMahajan
      @AjinkyaMahajan 4 роки тому +1

      @@AndreasSpiess Way back, I had implemented it on XC6L__ FPGA for sound detection using an external comparator.
      Nowadays, this type of DelSic ADC comes built-in in PSoC 5LP which I often use for many DIY projects.
      I had also done it on atmega328p.
      I am not sure if it can be implemented on all microcontrollers like ATtiny, etc as Delsig needs Timer, Counter and comparator, and memory or dedicated peripherals for UART.

  • @rikimr701
    @rikimr701 4 місяці тому

    It will be nice if there is updated version of this video. Considering now espresif have many varians (s3, C3, C2, etc)

  • @marcopfeiffer3032
    @marcopfeiffer3032 3 роки тому

    The esp32 has adc calibration information baked into its efuse storage. If I use those, I can get pretty accurate results between 100-2500 mV.

  • @bm830810
    @bm830810 4 роки тому +1

    I think sigma delta ADC was also worth mentioning which is also used in ADS1115, maybe in future videos

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      You are probably right. But the video was already very long :-(

  • @nektariosbasdekis1123
    @nektariosbasdekis1123 2 роки тому

    Hey Andreas.
    In the AD7606 module you saw at the end,
    the logic levels are 3,3 or 5 V?
    Thank you!

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому +1

      It looks like 3.3 volt (see on the Aliexpress listing)

  • @robdavis3220
    @robdavis3220 4 роки тому +1

    Nice explanation on the ADC basics. This can be confusing for beginners and experienced people alike.
    The resistor values used when measuring higher voltages(30V) are way to high. With a few meg ohms the ADC's sampling capacitor cant fully charge and your results will be off. As the voltage drops the problem will get worse. You need to either increase the sampling time (not rate) or put a big cap (10-100nf should do) at the junction of the voltage divider. The capacitor will then supply the required charge to charge up the ADC's sampling capacitor. This will obviously mean the sampling RATE will be dependent on the RC values of the voltage divider and the cap.
    If you do the same experiment with resistor values in the range of 10 - 100K as the voltage divider , you will get much better results. This is not an issue with the ESP32 , the same will hold true for all ADC's. I use the STM32 a lot and have seen this exact issue. If you have to sample a high impedance source you will have to increase your sampling time. You will also see more noise if you don't add filtering.
    This is the reason that fast ADC's usually require some sort of amplifier/buffer stage up front to make sure the sampling cap can be charged fast enough to meet the frequency requirements.
    Cheers
    Rob

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      Thank you for your additional information. I wanted to keep the (tiny) resistors on the Wemos. This is why I ended up with such high values. But the current should be the same as in the original Wemos(@30 volts) .

    • @robdavis3220
      @robdavis3220 4 роки тому

      @@AndreasSpiess
      The issue is that when the ADC sampling capacitor is switched in at the start of the sampling period it is discharged. The mid point of the divider will drop to 0volts. The cap then charges through the 2meg resistor. Even though the cap is only a few pF it still has a time constant. If the sampling time is short enough the cap will be sampled before it is fully charged and the reading will be off. A big capacitor at the junction of the divider can provide the charge to charge up the ADC cap quickly without significant drop in the voltage at that point.
      Cheers
      Rob

  • @ismzaxxon
    @ismzaxxon Рік тому

    In the formula x = (99.0 * X ... I always zero out undefined variables. So X=0. therefore X = (99.0 X 0 ) which would = 0. What does 99 represent?

    • @AndreasSpiess
      @AndreasSpiess  Рік тому +1

      I say it in the video: The formula should average across 100 samples.

  • @giorgioboiero
    @giorgioboiero 4 роки тому +1

    A good alternative condidate could be the STM32 micros such as the Blue Pill (STM32F103) or the Black Pill (STM32F4x1)
    They could be programmed using Arduino or PlatformIO

  • @RandomTorok
    @RandomTorok 8 місяців тому

    I am trying to build a device to measure power from a solar panel. I purchased a small voltage sensor that has a 30K ohm resistor and a 7.5K ohm resistor. If I measure the voltage with a multimeter I consistently get a figure that is about 2 volts over what my esp32 device is reading. Is this normal or is there something I can do to increase the accuracy?

    • @AndreasSpiess
      @AndreasSpiess  7 місяців тому

      Maybe you google "voltage divider"? And pay attention taht you do not kill your ESP with overvoltage!

  • @neeravdesai3940
    @neeravdesai3940 5 місяців тому

    what is (X * 12.292 /4096), i didnt understood the 12.292 what does it signify

    • @AndreasSpiess
      @AndreasSpiess  5 місяців тому

      4096 is the maximum value of a 12bit ADC. and 12292 is its current reading. The rest is rule of three.

  • @TYGAMatt
    @TYGAMatt 4 роки тому

    I too had major issues with the ESP32 ADC. Drove me insane. I'd been using the UNO prior to that with 1.1v reference and was very disappointed with the ESP32 ADC performance. Bullshit indeed lol! Changed to an ADS1115 and very happy. So happy I bought lots of them and won't use the built in ADC now. If you're going to use an ADC, might as well use an accurate one.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      Thank you for sharing your expreience!

  • @9h5bmjason19
    @9h5bmjason19 2 роки тому

    Can you test 1M in series with 100k@25 degrees Celsius NTC with ADS1115 - I am running tests and have issues with the readings

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому

      This is maybe more a topic for a blog, not for such a big channel :-(

  • @kwazar6725
    @kwazar6725 4 роки тому +1

    Reminds me of school and r2r ladder dacs. I get my fix of andreas every sunday. Lovely stuff.

  • @ingenia-tec5194
    @ingenia-tec5194 3 роки тому

    Thank you a lot.
    Very impressive :D Thanks for all the info.
    Excelent Video :D

  • @stefano.a
    @stefano.a 4 роки тому

    what is the sense of having a fast ADC converter if the correct measure is obtained only averaging 100 samples reducing the effective speed by a factor 100?

  • @jasonnation6615
    @jasonnation6615 2 роки тому

    How would I go about using the esp32 as a simple wifi antenna for my laptop? for example if my wifi card inside was to fail, could I use the esp32 to connect and surf?

    • @AndreasSpiess
      @AndreasSpiess  2 роки тому

      No need for two times the same comment.

  • @tengelgeer
    @tengelgeer 4 роки тому +5

    12:15 I almost spit out my coffee, I expected better from you Andreas ;) But that is the wrong calculation. You have 1024 steps so the resolution is 5,0V / 1024. Rounded, that's also 4,9mV and to calibrate you might want to use a different factor but that's not the point. Using the real resolution on most micros is also quite a bit faster because it's always a factor of 2. (Lack of div operator vs using shift to div by 2).
    So that makes 9:10 4055 in an ideal world. But more important 9:45 is not "maybe 10 tests", it will end up with exactly 12 tests. The number of tests of a successive approximation is equal to the number of bits. Which are just tested MSB to LSB.
    I know the changes are small but I think if you teach them in a video the content deserves to be correct :) In contrast to teaching in front of a class where you want to make "mistakes" like this to see if pupils spot the error.
    18:35 Don't agree it's always "not good". For example, if you want to read the position of a pot (or LDR). The pot is also referenced to Vcc which makes the error cancel out. Where you would have different values if you used a good and stable reference for the ADC.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому +1

      1. You can discuss with the 1023 fraction. I do not care too much. Last time I used 1024 and had the same number of complaints.
      2. Concerning the number of steps: After thinging I found my mistake: I thought, if Vin is exactly 5 volts you could stop. But this is not true.

    • @leocurious9919
      @leocurious9919 4 роки тому +1

      Lets make it simple: 1 step Resolution: 0->5V or: 5V/1
      2 steps: 0->2,5->5 or: 5V/2
      4 steps: 0->1,25->2,5->3,7->5 or: 5V/4
      1024 steps from 0 to 5V or: 5V/1024
      Thus: Voltage range divided by number of steps.
      The other way around, ADC-value to voltage, its number of steps minus one:
      1 bit ADC: only 1 or 0 -> 5V*2^1 = 10V = wrong --> 5V*(2^1-1) = 5V = correct

  • @KnaufL
    @KnaufL 4 роки тому +1

    Hey Andreas, what about splitting the digital and analog star ground connection point? I mean putting one before the other, or vice versa.

    • @uwezimmermann5427
      @uwezimmermann5427 4 роки тому +2

      I have used the internal ADC of the ATtiny/ATmega in several scientific (aka "serious") projects - and they are up to the task when 10 bit resolution is enough. But you can loose a lot of the potential by not using a good design for the front-end outside the chip. The datasheet of the AVR series recommends to use a 10 µH inductor in series with the AVCC supply pin as well as the mandatory 100 nF decoupling capacitor. Using a star-ground is absolutely necessary if you have parts around which will draw significant current. However, while AVCC and VCC in the ATmega are separated inside the GND-pins are all connected to the same metal-layer going all around the chip. But for everything you have outside the chip, i.e. voltage divider, possibly an opamp, a split GND is almost mandatory.

  • @akbarharun4474
    @akbarharun4474 7 місяців тому

    bang cara menambahkan modul ADC pada esp8266 gimana ya caranya?🙏

  • @stefans9990
    @stefans9990 4 роки тому

    I had to chuckle a little about the example of measuring a 24V Solar panel and then setting the range to 30V (around 13:23 in your video). A solar panel that you would use with 24V batteries in a real-world scenario would normally be a 72-Cell panel, which typically has an open circuit voltage around 45V @25ºC, and quite a bit higher when it gets really cold. I realise it was just an example in your video, but for anyone wanting to really measure a "24V Solar Panel", maybe increase that range in your resistor divider a little :-) As usual, thanks for an interesting Video Andreas - toll!

  • @ismettopal7564
    @ismettopal7564 4 роки тому +1

    Good video. Thank you. Differential ADCs missed?

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      The ADS1115 can be used in differencial mode. I am not sure if differential mode is used by many makers (appart from measuring shunt resistors)

    • @ismettopal7564
      @ismettopal7564 4 роки тому +1

      Some sensors needs, for example load cells.

  • @zilogfan
    @zilogfan Рік тому

    Is there a better way to remove the noise in software other than the simple long averages? Better math algo? THANKS! love your vids

    • @AndreasSpiess
      @AndreasSpiess  Рік тому +1

      I assume there are other ways. But I do not know them. Maybe Google knows?

  • @TheDefpom
    @TheDefpom 4 роки тому

    The atmega328 has a built in 1.1V reference voltage, you just need to tell it to use it, also you can measure the actual voltage on one of the pins so you know exactly what it is, as they are never exactly 1.1V

  • @geekmystique
    @geekmystique 4 роки тому

    13 people hate analog signals!!! If only they would realize the world is analog :'(

  • @lenaroseguera3121
    @lenaroseguera3121 Рік тому

    Can somebody explain to me, how that average formula wokrs, please?

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      Just try it with your pocket calculator ;-)

  • @electronic7979
    @electronic7979 4 роки тому +1

    Very helpful video.

  •  4 роки тому

    Someone who wears a hat like that is likely to eat an entire package of expired hotdogs in one sitting. I bet he carries around hotdogs in open ziplock bags in his pocket just for a mid day snack.

  • @robertfischer7212
    @robertfischer7212 4 роки тому

    Danke, Andreas, du bestätigst meine Beobachtungen. Ich verwende auch nur noch die kleinen, externen ADCs. Ein Hinweis noch, die Adafruit-Treiber für ADS1015/ADS1115 könnten beim ADS1115 Probleme machen. Der ADS1015 (12Bit ADC) arbeitet perfekt. Für den ADS1115 ggf einen Fork der Adafruit-Lib von User soligen2010 nutzen.

  • @Tally-MA
    @Tally-MA Рік тому

    Hello Andreas! I found your video when searching about adc because i am trying to trick a STM8S003F3 without success.
    The STM8S seems to be running at 3,3v and has a 10k linear pot connected to 3,3v VCAP, GND and the variable output to PD3 , which is described as AIN4 and ADC_ETR. It stands for External trigger. From what i understand, the ADC external triggering means it is possible that the ADC only reads on some programmed event. Turns out that when i rotate the POT, even when reading with a digital meter, the voltage values are not linear at all and behaves differently along the POT range. It can read steadily on the starting range, mid range it will fluctuate values and even read 0 and on the end range read some steady values again, higher than on the start range. But the device works correctly. What can be the cause for this? The STM8 adc pin can be programmed to somehow behave like this? Or expecting some pwm signal synchronized with its clock? I don’t have a scope to analyse this in a better way. If i input the POT output to a wemos d1 8266 it will read accordingly to the digital meter, but i cannot put the wemos bypassing that signal to a pwm output back to the STM8, it will not work the same way as if the POT is directly connected to the STM8. Do you have a clue about why this happens?
    Thank you

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      I have no idea. And I never used an STM8. So I am not a big help :-(

    • @Tally-MA
      @Tally-MA Рік тому

      @@AndreasSpiess ok. Thanks anyways. Maybe it would be something good to figure out. I gave up on that approach because i don’t own a scope but i really would like to know what’s going on behind the scenes. Cheers!

  • @jockey12022011
    @jockey12022011 Рік тому

    I couldn't get such stable readings as you have for the ADS1115. Do you have some sample code? I'm averaging over 100 readings, with a gain of 1.0 , and still get plus minus 20 digits of noise. (Which is plus minus 2.5mv)

    • @AndreasSpiess
      @AndreasSpiess  Рік тому

      This is most probably not a SW issue. Noise is a hard thing to conquer. Good ground and short wires can help.

    • @jockey12022011
      @jockey12022011 Рік тому

      @@AndreasSpiess Andreas, you are 100% correct! It was the WiFi 2.4 ghz causing the problem. When the ESP8266 mini is not connected to WiFi, the noise drops down to similarly shown in your video. As soon as WiFi is connected, the readings fluctuate quite a lot.

  • @JeffCM1
    @JeffCM1 4 роки тому +6

    Andreas, you're getting pretty good at this. In a foreign language, even more impressive.
    Thanks

    • @jamesgoacher1606
      @jamesgoacher1606 4 роки тому

      He has a Swiss Accent though! :-)

    • @JeffCM1
      @JeffCM1 4 роки тому +1

      @@jamesgoacher1606 Too late to change that. But look at Big Clive with his Scottish accent.

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      I vote for the content, not the form!

  • @yunuszenichowski
    @yunuszenichowski Місяць тому

    Thank you, extremely helpful!

  • @BirdsBoxTV
    @BirdsBoxTV 4 роки тому +1

    No INA226? Why?

    • @javierpallalorden
      @javierpallalorden 4 роки тому

      INA226 is way better, I use them often to measure voltages with ESP8266 or ESP32’s

    • @AndreasSpiess
      @AndreasSpiess  4 роки тому

      I think this is a very specialized chip. But of course, it can solve the problem of measuring higher voltages.