/esp-idf-web-analog

ADC Monitor for esp-idf

Primary LanguageCMIT LicenseMIT

esp-idf-web-analog

This project is a demonstration of real-time visualization of data via a web browser.
The purpose of this project is to introduce a library that can visualize data in real time.
Use the ADC value as the data to display.

ESP32 has two ADCs, ADC1 and ADC2.
This project uses ADC1.
You can use ADC1 to convert analog values to digital values.
The analog values change dynamically and are suitable for this demonstration.

web-meter web-horizontal web-vertical Chartjs Plotly Epoch

ADC Attenuation

This project uses ADC_ATTEN_DB_11(11dB) for attenuation.
11dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9V.
But the range that can be measured accurately is as follows:

  • Measurable input voltage range for ESP32 is 150 mV ~ 2450 mV.
  • Measurable input voltage range for ESP32S2 is 0 mV ~ 2500 mV.
  • Measurable input voltage range for ESP32S3 is 0 mV ~ 3100 mV.
  • Measurable input voltage range for ESP32C3 is 0 mV ~ 2500 mV.
  • Measurable input voltage range for ESP32C2 is 0 mV ~ 2800 mV.

Software requirements

ESP-IDF V4.4/V5.0/V5.1.
ESP-IDF V5.0 is required when using ESP32-C2.

I used this component.
This component can communicate directly with the browser.
It's a great job.

Installation for ESP-IDF V4.4

git clone -b v4.4 https://github.com/nopnop2002/esp-idf-web-analog
cd esp-idf-web-analog/RadialGauge/
git clone https://github.com/Molorius/esp32-websocket components/websocket

Installation for ESP-IDF V5.0/5.1

git clone https://github.com/nopnop2002/esp-idf-web-analog
cd esp-idf-web-analog/RadialGauge/
git clone https://github.com/Molorius/esp32-websocket components/websocket

Note for ESP-IDF V5.0
ESP-IDF V5.0 ADC driver has a bug and does not define GPIO lookup macros like ADC1_GPIO32_CHANNEL.
Therefore, when using ESP-IDF V5.0, it is necessary to include the legacy driver.
This bug has been resolved in ESP-IDF V5.1.

Configuration

idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3}
idf.py menuconfig
idf.py flash monitor

config-top config-app

WiFi Setting

Set the information of your access point. config-wifi-1

You can connect using the mDNS hostname instead of the IP address.
config-wifi-2

ADC Setting

Set the information of gpio for analog input. config-adc-1

It is possible to monitor 3 channels at the same time.
config-adc-2

Analog input gpio for ESP32 is GPIO32 ~ GPIO39. 12Bits width.
Analog input gpio for ESP32S2 is GPIO01 ~ GPIO10. 13Bits width.
Analog input gpio for ESP32S3 is GPIO01 ~ GPIO10. 12Bits width.
Analog input gpio for ESP32C2 is GPIO00 ~ GPIO04. 12Bits width.
Analog input gpio for ESP32C3 is GPIO00 ~ GPIO04. 12Bits width.

Analog source

Connect ESP32 and Analog source using wire cable.
I used a variable resistor for testing.

                                          +---------------------------+
                                          |      variable resistor    |
ESP32 3.3V   -----------------------------+ Ra of variable resistor   |
                                          |                           |
                                          |                           |
ESP32 GPIO32 -------------------------+---+ Vout of variable resistor |
                                      |   |                           |
                  R1      R2      R3  |   |                           |
ESP32 GND    ----^^^--+--^^^--+--^^^--+   |                           |
                      |       |           |                           |
                      |       |           |                           |
ESP32 GPIO33 ---------+       |           |                           |
                              |           |                           |
                              |           |                           |
ESP32 GPIO34 -----------------+           |                           |
                                          |                           |
                                          |                           |
ESP32 GND    -----------------------------+ Rb of variable resistor   |
                                          |                           |
                                          +---------------------------+

Launch a web browser

Enter the following in the address bar of your web browser.

http:://{IP of ESP32}/
or
http://esp32-server.local/

Using mDNS hostname

You can connect using the mDNS hostname instead of the IP address.

  • esp-idf V4.4
    If you set CONFIG_MDNS_STRICT_MODE = y in sdkconfig.defaults, the firmware will be built with MDNS_STRICT_MODE.
    If MDNS_STRICT_MODE is not set, mDNS name resolution will not be possible after long-term operation.
  • esp-idf V4.4.1
    mDNS component has been updated.
    If you set CONFIG_MDNS_STRICT_MODE = y in sdkconfig.defaults, the firmware will be built with MDNS_STRICT_MODE.
    Even if MDNS_STRICT_MODE is set, mDNS name resolution will not be possible after long-term operation.
  • esp-idf V5.0 or later
    mDNS component has been updated.
    Long-term operation is possible without setting MDNS_STRICT_MODE.
    The following lines in sdkconfig.defaults should be removed before menuconfig.
    CONFIG_MDNS_STRICT_MODE=y

WEB Pages

WEB pages are stored in the html folder.
You can change it as you like.