Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| dev:iot:riot:esp32:utiliser_convertisseur_analogique_numerique [2021/04/18 16:28] – 77.192.232.26 | dev:iot:riot:esp32:utiliser_convertisseur_analogique_numerique [2021/04/18 16:49] (Version actuelle) – 77.192.232.26 | ||
|---|---|---|---|
| Ligne 48: | Ligne 48: | ||
| ===== Exemple ===== | ===== Exemple ===== | ||
| + | |||
| + | ==== Montage ==== | ||
| On branche un potentiomètre sur le GPIO33 du d'une carte de type ESP32-DEVKIT. On cherche ici à afficher régulièrement sa valeur sur le port série. | On branche un potentiomètre sur le GPIO33 du d'une carte de type ESP32-DEVKIT. On cherche ici à afficher régulièrement sa valeur sur le port série. | ||
| + | |||
| + | Note: Note that the call to adc_init is needed for the reads to work. I remeber that the ESP8266 had a 1.0 V reference, maybe this is also the case here? | ||
| + | |||
| + | ==== Code ==== | ||
| Déclarer l' | Déclarer l' | ||
| Ligne 84: | Ligne 90: | ||
| <code c main.c> | <code c main.c> | ||
| #include < | #include < | ||
| - | | + | |
| #include " | #include " | ||
| #include " | #include " | ||
| - | | + | |
| #define RES ADC_RES_10BIT | #define RES ADC_RES_10BIT | ||
| #define ADC_GPIO33 ADC_LINE(11) | #define ADC_GPIO33 ADC_LINE(11) | ||
| - | | + | |
| int main(void) | int main(void) | ||
| { | { | ||
| - | | + | |
| - | + | ||
| - | printf(" | + | printf(" |
| - | // | + | // |
| - | if(adc_init(ADC_GPIO33) < 0 ) { | + | if(adc_init(ADC_GPIO33) < 0 ) { |
| - | printf(" | + | printf(" |
| - | } else { | + | |
| - | printf(" | + | |
| - | } | + | |
| - | + | ||
| - | while(1) | + | |
| - | { | + | |
| - | + | ||
| - | //lecture du CAN | + | |
| - | sample = adc_sample(ADC_LINE(ADC_GPIO33), | + | |
| - | if (sample < 0) { | + | |
| - | printf(" | + | |
| } else { | } else { | ||
| - | | + | |
| - | } | + | } |
| - | + | ||
| - | xtimer_sleep(2); | + | while(1) |
| - | } | + | { |
| - | + | ||
| - | return 0; | + | //lecture du CAN |
| + | sample = adc_sample(ADC_GPIO33, | ||
| + | if (sample < 0) { | ||
| + | printf(" | ||
| + | } else { | ||
| + | printf(" | ||
| + | } | ||
| + | |||
| + | xtimer_sleep(2); | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| } | } | ||
| </ | </ | ||