ADC ambient light sensor value read & display

This commit is contained in:
Alexander 2024-08-12 01:18:18 -04:00
parent 743d98d67a
commit 42d8c8eca8
11 changed files with 15849 additions and 15760 deletions

View File

@ -12,6 +12,6 @@ endif(DEFINED ENV{RMAKER_PATH})
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/components/esp-insights/components ${RMAKER_PATH}/components ${RMAKER_PATH}/examples/common)
# Increase project version in order for OTA to work
set(PROJECT_VER "2.5.2")
set(PROJECT_VER "2.6")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(ESP32-Rainmaker-Switch)

View File

@ -1 +1 @@
4b7b5b45c2fdf6ef37fa1397e1c4c0cf C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/ESP32-Rainmaker-Switch.bin
2d34446c25978744244956fee5b51e38 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/ESP32-Rainmaker-Switch.bin

View File

@ -1201,3 +1201,71 @@
14305 14896 7451411022640310 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/.bin_timestamp 983b9a5bbba3c76a
14897 15066 0 esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
14897 15066 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
216 532 7451392163232668 bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
216 532 7451392163232668 bootloader/bootloader.elf be50754f10ab1bb6
216 532 7451392163232668 bootloader/bootloader.bin be50754f10ab1bb6
216 532 7451392163232668 bootloader/bootloader.map be50754f10ab1bb6
216 532 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
216 532 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.elf be50754f10ab1bb6
216 532 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.bin be50754f10ab1bb6
216 532 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.map be50754f10ab1bb6
229 920 7451413669303288 esp-idf/main/CMakeFiles/__idf_main.dir/app_driver.c.obj 5959b69643102a16
925 1139 7451413671440519 esp-idf/main/libmain.a 8df08645a1b22e8a
1140 11301 7451413772826100 esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
1140 11301 7451413772826100 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
11301 14367 7451413803387512 ESP32-Rainmaker-Switch.elf deb2634d5539d691
14368 14946 7451413809588635 .bin_timestamp 983b9a5bbba3c76a
14368 14946 7451413809588635 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/.bin_timestamp 983b9a5bbba3c76a
14946 15139 0 esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
14946 15139 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
228 548 7451392163232668 bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
228 548 7451392163232668 bootloader/bootloader.elf be50754f10ab1bb6
228 548 7451392163232668 bootloader/bootloader.bin be50754f10ab1bb6
228 548 7451392163232668 bootloader/bootloader.map be50754f10ab1bb6
228 548 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
228 548 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.elf be50754f10ab1bb6
228 548 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.bin be50754f10ab1bb6
228 548 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.map be50754f10ab1bb6
241 933 7451416497394606 esp-idf/main/CMakeFiles/__idf_main.dir/app_driver.c.obj 5959b69643102a16
938 1240 7451416500452134 esp-idf/main/libmain.a 8df08645a1b22e8a
1240 11236 7451416600139681 esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
1240 11236 7451416600139681 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
11236 14336 7451416630985861 ESP32-Rainmaker-Switch.elf deb2634d5539d691
14337 14914 7451416637212340 .bin_timestamp 983b9a5bbba3c76a
14337 14914 7451416637212340 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/.bin_timestamp 983b9a5bbba3c76a
14915 15087 0 esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
14915 15087 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
207 529 7451392163232668 bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
207 529 7451392163232668 bootloader/bootloader.elf be50754f10ab1bb6
207 529 7451392163232668 bootloader/bootloader.bin be50754f10ab1bb6
207 529 7451392163232668 bootloader/bootloader.map be50754f10ab1bb6
207 529 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
207 529 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.elf be50754f10ab1bb6
207 529 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.bin be50754f10ab1bb6
207 529 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.map be50754f10ab1bb6
223 914 7451420826277731 esp-idf/main/CMakeFiles/__idf_main.dir/app_driver.c.obj 5959b69643102a16
919 1219 7451420829260226 esp-idf/main/libmain.a 8df08645a1b22e8a
1220 11216 7451420928964497 esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
1220 11216 7451420928964497 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
11217 14554 7451420962232388 ESP32-Rainmaker-Switch.elf deb2634d5539d691
14555 15147 7451420968601855 .bin_timestamp 983b9a5bbba3c76a
14555 15147 7451420968601855 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/.bin_timestamp 983b9a5bbba3c76a
15147 15331 0 esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
15147 15331 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
220 565 7451392163232668 bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
220 565 7451392163232668 bootloader/bootloader.elf be50754f10ab1bb6
220 565 7451392163232668 bootloader/bootloader.bin be50754f10ab1bb6
220 565 7451392163232668 bootloader/bootloader.map be50754f10ab1bb6
220 565 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader-prefix/src/bootloader-stamp/bootloader-build be50754f10ab1bb6
220 565 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.elf be50754f10ab1bb6
220 565 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.bin be50754f10ab1bb6
220 565 7451392163232668 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/bootloader.map be50754f10ab1bb6
234 935 7451425309930053 esp-idf/main/CMakeFiles/__idf_main.dir/app_driver.c.obj 5959b69643102a16
939 1185 7451425312364149 esp-idf/main/libmain.a 8df08645a1b22e8a
1186 11618 7451425416430392 esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
1186 11618 7451425416430392 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esp_system/ld/sections.ld ab09ddea2c39cf62
11619 14855 7451425448714747 ESP32-Rainmaker-Switch.elf deb2634d5539d691
14856 15445 7451425455015698 .bin_timestamp 983b9a5bbba3c76a
14856 15445 7451425455015698 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/.bin_timestamp 983b9a5bbba3c76a
15445 15620 0 esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290
15445 15620 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/esp-idf/esptool_py/CMakeFiles/app_check_size e2e552add3db6290

File diff suppressed because it is too large Load Diff

View File

@ -107,3 +107,11 @@
34 253 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
36 210 0 esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
36 210 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
35 209 0 esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
35 209 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
36 214 0 esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
36 214 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
38 217 0 esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
38 217 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
42 235 0 esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e
42 235 0 C:/Users/alex/github/ESP-Nodes/ESP32-Rainmaker-Switch/build/bootloader/esp-idf/esptool_py/CMakeFiles/bootloader_check_size 7fa5a58273f3cc6e

View File

@ -49,6 +49,7 @@ static bool g_power_state = DEFAULT_POWER;
// Define the name of app for logs.
static const char *TAG = "ESP32-Nodes Rainmaker Switch";
static float a_light;
static int a_light_raw;
static TimerHandle_t sensor_timer;
esp_adc_cal_characteristics_t adc1_chars;
@ -63,18 +64,20 @@ static void light_sensor_update(TimerHandle_t handle) {
static float delta = 0.25;
a_light += delta;
int adc_value = adc1_get_raw(ADC1_CHANNEL_1);
// Obtain raw ADC value from the ambient light sensor connected to GPIO 1
a_light_raw = adc1_get_raw(ADC1_CHANNEL_1);
// switch_device
esp_rmaker_param_update_and_report(
esp_rmaker_device_get_param_by_type(switch_device, ESP_RMAKER_PARAM_TEMPERATURE),
//esp_rmaker_float(a_light));
esp_rmaker_int(adc_value));
esp_rmaker_device_get_param_by_type(temp_sensor_device, ESP_RMAKER_PARAM_TEMPERATURE),
esp_rmaker_float((float)a_light_raw));
ESP_LOGI(TAG, "\nSensor value: %i", adc_value);
ESP_LOGI(TAG, "\nSensor value: %i", a_light_raw);
}
void app_sensor_init(void) {
//esp_err_t app_sensor_init(void) {
a_light = 15.0;
a_light_raw = 0;
sensor_timer = xTimerCreate("ambient_light_sensor_update_timer", (REPORTING_PERIOD*250) / portTICK_PERIOD_MS,
pdTRUE, NULL, light_sensor_update);
@ -86,7 +89,8 @@ void app_sensor_init(void) {
}
float app_get_current_temperature() {
return a_light;
//return a_light;
return a_light_raw;
}
//static void app_bme280_init() {}
@ -161,9 +165,12 @@ void app_driver_init()
gpio_config(&io_conf);
app_indicator_init();
// Configure ambient light sensor GPIO
adc1_config_channel_atten(ADC_UNIT_2, ADC_ATTEN_DB_11);
esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_DEFAULT, 0, &adc1_chars);
/* Configure ambient light sensor ADC GPIO */
// Set the attenuation parameter of ADC; GPIO 1 to 12db
adc1_config_channel_atten(ADC_UNIT_2, ADC_ATTEN_DB_12);
// Calibrate ADC
esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_12, ADC_WIDTH_BIT_DEFAULT, 0, &adc1_chars);
// Set ADC bit width (resolution)
adc1_config_width(ADC_WIDTH_BIT_DEFAULT);
/*gpio_config_t sensor_io_conf = {