113 lines
3.1 KiB
C++
Raw Normal View History

2024-07-13 23:48:32 -04:00
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
2024-07-14 00:18:25 -04:00
#include <Wire.h>
2024-07-13 23:48:32 -04:00
#include <Adafruit_BME280.h>
2024-07-14 01:02:19 -04:00
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
2024-07-13 23:48:32 -04:00
#include "config.h"
2024-07-14 18:24:36 -04:00
#include "epaper.h"
2024-07-13 23:48:32 -04:00
Adafruit_BME280 bme;
2024-07-14 00:59:39 -04:00
// Define tasks.
TaskHandle_t TaskStatusLED, TaskSensorValues;
// Dummy task blinking built-in LED
2024-07-14 01:01:19 -04:00
void TaskStatusLEDCode (void* parameters) {
2024-07-14 01:15:26 -04:00
Serial.print("Task 0 running on core # ");
Serial.println(xPortGetCoreID());
2024-07-14 00:59:39 -04:00
2024-07-14 01:23:05 -04:00
for (;;) {
digitalWrite(SYS_LED_PIN, LOW);
vTaskDelay(250 / portTICK_RATE_MS);
digitalWrite(SYS_LED_PIN, HIGH);
vTaskDelay(250 / portTICK_RATE_MS);
digitalWrite(SYS_LED_PIN, LOW);
vTaskDelay(250 / portTICK_RATE_MS);
digitalWrite(SYS_LED_PIN, HIGH);
2024-07-14 01:29:41 -04:00
vTaskDelay(pdMS_TO_TICKS(1000));
2024-07-14 01:23:05 -04:00
}
2024-07-14 00:59:39 -04:00
}
2024-07-14 01:23:50 -04:00
2024-07-14 01:01:19 -04:00
void TaskSensorValuesCode (void* parameters) {
2024-07-14 01:23:05 -04:00
for (;;) {
Serial.println("BME-280 Sensors Readings ...");
2024-07-14 01:33:07 -04:00
Serial.print("Temperature:\t\t");
2024-07-14 01:23:05 -04:00
Serial.print(bme.readTemperature());
2024-07-14 01:39:14 -04:00
Serial.println("\t°C");
2024-07-14 01:33:07 -04:00
Serial.print("Humidity:\t\t");
2024-07-14 01:23:05 -04:00
Serial.print(bme.readHumidity());
2024-07-14 01:39:14 -04:00
Serial.println("\t%");
2024-07-14 01:34:09 -04:00
Serial.print("Barometric Pressure:\t");
2024-07-14 01:23:05 -04:00
Serial.print(bme.readPressure() / 100.0F);
2024-07-14 01:39:14 -04:00
Serial.println("\tkPa");
2024-07-14 01:23:05 -04:00
Serial.println("");
2024-07-14 01:29:41 -04:00
vTaskDelay(pdMS_TO_TICKS(5000));
2024-07-14 01:23:05 -04:00
}
2024-07-14 01:01:19 -04:00
}
2024-07-14 00:59:39 -04:00
2024-07-13 23:48:32 -04:00
void setup() {
2024-07-14 00:18:25 -04:00
Serial.begin(9600);
2024-07-13 23:48:32 -04:00
Serial.println();
Serial.println("Setting up GPIOs ...");
pinMode(LED_PIN, OUTPUT);
2024-07-14 01:08:17 -04:00
Serial.println("GPIO setup done");
2024-07-13 23:48:32 -04:00
2024-07-14 00:18:25 -04:00
Serial.println("Setting up BME280 sensor");
2024-07-14 00:25:02 -04:00
Wire.setPins(SDA_PIN, SCL_PIN);
2024-07-14 00:26:02 -04:00
Wire.begin();
2024-07-14 00:27:19 -04:00
//unsigned status = bme.begin(0x76); // 0x76
if (!bme.begin(0x76)) {
2024-07-13 23:48:32 -04:00
Serial.println("Could not find a valid BME/BMP280 sensor, check wiring!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
2024-07-14 00:18:25 -04:00
while (1) {
digitalWrite(LED_PIN, LOW);
2024-07-14 00:50:38 -04:00
delay(150);
2024-07-14 00:18:25 -04:00
digitalWrite(LED_PIN, HIGH);
2024-07-14 00:50:38 -04:00
delay(150);
Serial.println("Could not find a valid BME/BMP280 sensor, check wiring!");
2024-07-14 00:18:25 -04:00
}
2024-07-14 00:27:19 -04:00
}
2024-07-14 01:06:28 -04:00
else {
Serial.println("Sensor was found.");
2024-07-14 01:23:05 -04:00
xTaskCreate(TaskStatusLEDCode, "Status LED Task", 4096, NULL, 10, &TaskStatusLED);
xTaskCreate(TaskSensorValuesCode, "Status LED Task", 4096, NULL, 5, &TaskSensorValues);
2024-07-14 01:06:28 -04:00
}
2024-07-14 21:01:25 -04:00
// Initialize ePaper display
display.init(115200);
display.fillScreen(GxEPD_BLACK);
display.update();
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMono9pt7b);
//display.setCursor(205, 10);
//display.print("ESP32_DisplayNode"); // Takes 195 pixels in width
display.setCursor(5, 5);
display.setFont(&TomThumb);
display.print("10.100.50.105");
display.update();
2024-07-13 23:48:32 -04:00
}
void loop() {
2024-07-14 18:59:36 -04:00
}
/*
#elif defined(ESP32) && (CONFIG_IDF_TARGET_ESP32C3)
#define DF_GFX_SCK 4
#define DF_GFX_MOSI 6
#define DF_GFX_MISO GFX_NOT_DEFINED
#define DF_GFX_CS 7
#define DF_GFX_DC 2
#define DF_GFX_RST 1
#define DF_GFX_BL 3*/