From 5efca6b3c02b0b527e203485a90da4451de246e7 Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Tue, 24 Oct 2023 20:32:45 +0100 Subject: [PATCH] Figured out how to turn on PSRAM Now it looks like you can just allocate from a regular "malloc" Code ran successfully (afaict) when writing to 7MB - didn't seem to when doing 8MB. Not 100% sure why, but I don't think it'll matter tbh --- README.md | 4 ++-- components/dht22/dht22.c | 3 ++- main/main.c | 26 +++++++++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2afc21c..33f0521 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ESP Air Monitor +# Yet Another eSP Air Monitor - YASPAM Skeletal idea for an esp based air monitor. @@ -6,7 +6,7 @@ Skeletal idea for an esp based air monitor. I have used the following: -* ESP32-S3 (although as far as I know, I'm not using any special features... and should work on any esp) +* ESP32-S3 (although as far as I know, I'm not using any special features... and should work on any esp). * DHT22 * PMS5003 diff --git a/components/dht22/dht22.c b/components/dht22/dht22.c index 9285268..e707979 100644 --- a/components/dht22/dht22.c +++ b/components/dht22/dht22.c @@ -1,5 +1,6 @@ #include "dht22.h" #include "sdkconfig.h" +#include "esp_log.h" #define DATA_GPIO CONFIG_DHT22_DATA_GPIO @@ -15,7 +16,6 @@ deci_degrees_c _dht22_temperature = INT16_MIN; dht22_error dht22_read() { uint8_t data[5] = {0}; - // TODO: Actually figure out how to read the data from the chip. // TODO test that data[x] << 8 will be promoted to 16bits otherwise I'm shifting them to just zeros @@ -28,6 +28,7 @@ dht22_error dht22_read() { if (checksum_val != data[4]) { _dht22_relative_humidity = UINT16_MAX; _dht22_temperature = INT16_MIN; + ESP_LOGE(TAG, "Error in final checksum check"); return DHT22_CHECKSUM_ERROR; } diff --git a/main/main.c b/main/main.c index d2f9506..5630b2c 100644 --- a/main/main.c +++ b/main/main.c @@ -1,4 +1,4 @@ -/* +/** * Author: Arthur Roberts (c) 2023 * * License: GPLv3+ @@ -8,11 +8,31 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "dht22.h" +#include "esp_log.h" +#include "esp_wifi.h" + +static const char *TAG = "YASPAM"; + +struct air_monitor_data { +#ifdef CONFIG_DHT22_DATA_GPIO + deci_percent dht22_relative_humidity; + deci_degrees_c dht22_temperature; +#endif /* CONFIG_DHT22_DATA_GPIO */ + +#ifdef CONFIG_PMS5003_DATA_GPIO + // TODO +#endif /* CONFIG_PMS5003_DATA_GPIO */ + int64_t time; // TODO think about how best to store this. +}; void app_main(void) { - int ret = dht22_temperature(); - printf("Hello world! - dhtRet: %i\n", ret); +#ifdef CONFIG_DHT22_DATA_GPIO + int ret = dht22_read(); +#endif /* CONFIG_DHT22_DATA_GPIO */ + + + for (int i = 10; i >= 0; i--) { printf("Restarting in %d seconds...\n", i); vTaskDelay(1000 / portTICK_PERIOD_MS);