107 lines
3.0 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"
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);
vTaskDelay(750 / portTICK_RATE_MS);
}
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 ...");
Serial.print("Temperature: ");
Serial.print(bme.readTemperature());
Serial.println("°C");
Serial.print("Humidity: ");
Serial.print(bme.readHumidity());
Serial.println("%");
Serial.print("Barometric Pressure: ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" kPa");
Serial.println("");
2024-07-14 01:23:50 -04:00
vTaskDelay(5000 / portTICK_RATE_MS);
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-13 23:48:32 -04:00
}
void loop() {
2024-07-14 01:06:54 -04:00
/*digitalWrite(LED_PIN, LOW);
2024-07-13 23:48:32 -04:00
delay(250);
digitalWrite(LED_PIN, HIGH);
delay(250);
digitalWrite(LED_PIN, LOW);
2024-07-14 00:18:25 -04:00
delay(250);
digitalWrite(LED_PIN, HIGH);
delay(750);
Serial.println("Main loop");
2024-07-14 00:50:38 -04:00
Serial.print("Temperature: ");
Serial.print(bme.readTemperature());
Serial.println("°C");
2024-07-14 00:59:39 -04:00
Serial.print("Humidity: ");
Serial.print(bme.readHumidity());
Serial.println("%");
Serial.print("Barometric Pressure: ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" kPa");
2024-07-14 01:06:54 -04:00
Serial.println("");*/
2024-07-13 23:48:32 -04:00
}