Mercurial > d1workshop
changeset 18:0f7ae1553d9d
Analog to Digital Converter
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Thu, 16 Jun 2016 20:16:32 +0200 |
| parents | 4de4fce62d83 |
| children | 9bc0d9ae9f31 |
| files | advanced.rst |
| diffstat | 1 files changed, 28 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/advanced.rst Thu Jun 16 20:03:25 2016 +0200 +++ b/advanced.rst Thu Jun 16 20:16:32 2016 +0200 @@ -37,6 +37,34 @@ help on the Internet. +Analog to Digital Converter +=========================== + +Our board has only one "analog" pin, ``A0``. That pin is connected to an ADC, +or "analog to digital converter" -- basically an electronic voltmeter, which +can tell you what voltage is on the pin. The one we have can only measure from +0 to 1V, and would be damaged if it got more than 1V, so we have to be careful. + +We will connect a photo-resistor to it. It's a special kind of a resistor that +changes its resistance depending on how much light shines on it. But to make +this work, we will need a second, fixed, resistor to make a "volatge divider". +This way the voltage will change depending on the resistance of our +photo-resistor. + +.. image:: ./images/analog.png + +Now, we will just read the values in our program, and print them in a loop:: + + from machine import ADC + adc = ADC(0) + while True: + print(adc.read()) + +You should see a column of numbers changing depending on how much light the +photo-resistor has. Try to cover it or point it toward a window or lamp. The +values are from 0 for 0V, to 1024 for 1V. Ours will be somewhere in between. + + Communication Protocols =======================
