ESP8266 ADC
来自Jack's Lab
(版本间的差异)
(以“== Overview == * 10 bit sigmal delta ADC * Internal reference voltage is 1.0 V <br><br> == Example == <source lang=cpp> </source> Output: <source lang=bash> ...”为内容创建页面) |
(→Example) |
||
(未显示1个用户的3个中间版本) | |||
第7行: | 第7行: | ||
== Example == | == Example == | ||
+ | |||
+ | On [https://github.com/icamgo/Noduino-Falcon-Board Noduino Falcon] board: | ||
<source lang=cpp> | <source lang=cpp> | ||
+ | #include "noduino.h" | ||
+ | /* | ||
+ | * A0 --> 220K ---> 100K --> GND | ||
+ | * | | ||
+ | * | | ||
+ | * esp_adc | ||
+ | */ | ||
+ | void setup() | ||
+ | { | ||
+ | serial_begin(115200); | ||
+ | wifi_set_opmode(NULL_MODE); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | int ad = analogRead(A0); | ||
+ | |||
+ | serial_printf("ad = %d\r\n", ad); | ||
+ | |||
+ | float V = (ad / 1024.0) * (220 + 100)/100; | ||
+ | serial_printf("V*1000 = %d\r\n", (int)(V*1000)); | ||
+ | |||
+ | delay(5000); | ||
+ | } | ||
</source> | </source> | ||
− | Output: | + | Connect A0 to GND, Output: |
<source lang=bash> | <source lang=bash> | ||
第20行: | 第46行: | ||
ad = 0 | ad = 0 | ||
V*1000 = 0 | V*1000 = 0 | ||
+ | </source> | ||
+ | |||
+ | |||
+ | Connect A0 to 3.3V, Output: | ||
+ | |||
+ | <source lang=bash> | ||
ad = 1024 | ad = 1024 | ||
V*1000 = 3200 | V*1000 = 3200 | ||
ad = 1024 | ad = 1024 | ||
+ | V*1000 = 3200 | ||
</source> | </source> | ||
2018年10月28日 (日) 17:03的最后版本
[编辑] 1 Overview
- 10 bit sigmal delta ADC
- Internal reference voltage is 1.0 V
[编辑] 2 Example
On Noduino Falcon board:
#include "noduino.h" /* * A0 --> 220K ---> 100K --> GND * | * | * esp_adc */ void setup() { serial_begin(115200); wifi_set_opmode(NULL_MODE); } void loop() { int ad = analogRead(A0); serial_printf("ad = %d\r\n", ad); float V = (ad / 1024.0) * (220 + 100)/100; serial_printf("V*1000 = %d\r\n", (int)(V*1000)); delay(5000); }
Connect A0 to GND, Output:
ad = 0 V*1000 = 0 ad = 0 V*1000 = 0
Connect A0 to 3.3V, Output:
ad = 1024 V*1000 = 3200 ad = 1024 V*1000 = 3200