diff --git a/embedded-pio b/embedded-pio index 7163822..9e8f34c 160000 --- a/embedded-pio +++ b/embedded-pio @@ -1 +1 @@ -Subproject commit 7163822407f165e2ef49d13a0b9832665a582128 +Subproject commit 9e8f34cb83b9d1232a50e24863bb080c85eb7a45 diff --git a/platformio.ini b/platformio.ini index c790269..88697de 100644 --- a/platformio.ini +++ b/platformio.ini @@ -15,6 +15,7 @@ framework = arduino lib_deps = bodmer/TFT_eSPI@^2.5.43 bodmer/JPEGDecoder@^2.0.0 +lib_extra_dirs = ./embedded-pio build_flags = -D USER_SETUP_LOADED diff --git a/src/main.cpp b/src/main.cpp index 7e89fd6..a7eaf80 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,43 @@ +#include "adc_esp.h" #include -#include "display.h" + +int voltage; + +ESP32_ADC_Config config; + +int gpio_pin = 4; // Example: GPIO4 +adc_unit_t unit; +adc_channel_t channel; void setup() { - Serial.begin(115200); - Serial.println("Starting..."); - initDisplay(false); - - // drawSdJpeg("/bsr/Jonathan.jpeg", 130, 0); - HeapAnim(); - Serial.println("Setup done."); + // 1. Initialize ADC unit + config.unit = ADC_UNIT_2; + config.width = ADC_WIDTH_BIT_12; + config.attenuation = ADC_ATTEN_11db; // For full 0-3.3V range + config.vref = 1100; // Default reference voltage (1.1V) + + esp32_adc_init(&config); + + // 2. Determine ADC channel for GPIO pin + + esp32_adc_gpio_to_channel(gpio_pin, &unit, &channel); + + // 3. Configure the specific ADC channel + esp32_adc_config_channel(unit, channel, config.attenuation); + + // Now you can read from this ADC pin + int raw_value = esp32_adc_read_raw(unit, channel); + voltage = esp32_adc_read_voltage(unit, channel, &config); + + Serial.begin(115200); + Serial.printf("hello world\n"); + Serial.printf("Raw ADC Value: %d\n", raw_value); } void loop() { - // rotateColors(); - // delay(42); - // drawSdJpeg("/test.jpg", 0, 0); - - // HeapAnim(); -} + int raw = esp32_adc_read_raw(unit, channel); + Serial.printf("Voltage: %d mV\n", voltage); + Serial.printf("Raw ADC Value: %d\n", raw); + delay(1000); + voltage = esp32_adc_read_voltage(unit, channel, &config); +} \ No newline at end of file