User Tools

Site Tools


No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:iot:labesp32

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:edu:zmitac:macro:iot:labesp32 [2020/03/12 08:57] – [Laboratory scenarios] pczekalskien:edu:zmitac:macro:iot:labesp32 [2020/03/12 11:08] (current) – [Laboratory scenarios] pczekalski
Line 47: Line 47:
 | 5   | LCD                  | GPIO5, GPIO18-19, GPIO21-23, GPIO25                                 |                                                                                                         | | 5   | LCD                  | GPIO5, GPIO18-19, GPIO21-23, GPIO25                                 |                                                                                                         |
  
 +<note important>Note - GPIOs 34, 35, 36 and 39 do not have internal pull-up nor pull-down resistors so you may use them as inputs only.</note>
  
 == DHT11 == == DHT11 ==
Line 260: Line 261:
 </code> </code>
  
-You may observe that for single button press an interrupt is triggered not once but many times. That is natural because of the physical switch connection oscillations. To avoid it, introduce the minimum time that is necessary between subsequent interrupt triggers. a function ''millis()'' will help you here.+You may observe that for single button press an interrupt is triggered not once but many times. That is natural because of the physical switch connection oscillations. To avoid it, introduce the minimum time that is necessary between subsequent interrupt triggers. a function ''micros()'' will help you here. 
 +<note tip>Use ''micros()'' not ''millis()'' as ADC conversion is pretty quick and usually takes less than a ms.</note>
  
 ** Task 7 ** - reading analog data\\ ** Task 7 ** - reading analog data\\
-In this task, you will read analogue data via integrated ADCs of the ESP32. +In this task, you will read analogue data via integrated ADCs.\\ 
 +Hardware part includes use of the "Joystick" sensor, composed of two potentiometers (one per axis) and a button (we do not use it here). 
 +__Please note correct pinout. Connect **GND** to board's GND, **5V** to 3.3V (**NOT 5V!**) even if on-board print states 5V.!__. Analogue resistance (voltage divider) goes through VRx and VRy.\\ 
 + 
 +ESP32 has 15 channels exposed (18 total) of the up to 12-bit resolution ADCs. Reading of the raw data (12-bit resolution is the default, 8 samples per measure as default) is easy using ''analogRead()'' function. \\ 
 +Technically, under the hood on the hardware level, there are two ADCs (ADC1 and ADC2). ADC 1 uses GPIOs 32 through 39. ADC2 GPIOs 0,2,4, 12-15 and 25-27. Note, ADC2 is used for WiFi purposes so you cannot use it when WiFi communication is enabled (so cannot you use GPIOs). Other limitations include use of GPIOs 0, 2, 4 an 15 in ESP WROVER KIT as mentioned above (those are already bound to other hardware). \\ 
 +Just execute ''analogRead(GPIO)''.\\ 
 +A number of useful functions is here (not limited to): 
 +  * ''analogReadResolution(res)'' - where ''res'' is a value between 9 and 12 (default 12). For 9-bit resolution, you get 0..511 values, for 12-bit resolution, it is 0..4095 respectively.  
 +  * ''analogSetCycles(ccl)'' - where ''ccl'' is number of cycles per ADC sample. Default is 8, valid number is between 1 and 255. 
 +  * ''analogSetClockDiv(divider)'' - sets base clock divider for the ADC. That has an impact on the speed of conversion. 
 +  * ''analogSetAttenuation(a)'' and ''analogSetPinAttenuation(GPIO,a)'' - sets input attenuation (for all channels or for selected channel). Default is ''ADC_11db''. This paremeter reflects dynamic scalling of the input value: 
 +    * ''ADC_0db'' - no attenuation (1V on input = 1088 reading on ADC), so full scale is 0..1.1V 
 +    * ''ADC_2_5db'' - 1.34 (1V on input = 2086 reading on ADC), so full scale is 0..1.5V 
 +    * ''ADC_6db'' - 1.5 (1V on input = 2975 reading on ADC), so full scale is 0..2.2V 
 +    * ''ADC_11db'' - 3.6 (1V on input = 3959 reading on ADC), so full scale is 0..3.9V 
 + 
 +<note important>Do not execute consequent way ''analogRead()''. As technically all channels use same two registers (ADC1 and ADC2) you need to give it some time to sample (i.e. ''delay(100)'' between consecutive reads on different channels).</note> 
 + 
 +During your exercise, you may start from informing ESP to start sampling on particular GPIOs, usually in the ''setup()'' function: 
 +<code c> 
 +... 
 +#define VRxPIN 25 
 +#define VRyPIN 26 
 +... 
 +void setup() 
 +{ 
 +... 
 +  adcAttachPin(VRxPIN); 
 +  adcAttachPin(VRyPIN); 
 +  // here you can also change clock divider, number of cycles per sample and so on. 
 +... 
 +} 
 +</code>
 ==== Resources ==== ==== Resources ====
   - [[https://www.espressif.com/en/products/hardware/esp-wrover-kit/resources|ESP32 WROVER kit starting page]]   - [[https://www.espressif.com/en/products/hardware/esp-wrover-kit/resources|ESP32 WROVER kit starting page]]
en/edu/zmitac/macro/iot/labesp32.1583999841.txt.gz · Last modified: by pczekalski