From 88e635bfb7954dd0e1ee4ed01bd58b8ab06b085d Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 3 Dec 2024 16:55:17 +0100 Subject: [PATCH] Fixed issue with analog. --- lib/sensor/sensor.cpp | 4 ++-- src/main.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/sensor/sensor.cpp b/lib/sensor/sensor.cpp index 936aaad..9660849 100644 --- a/lib/sensor/sensor.cpp +++ b/lib/sensor/sensor.cpp @@ -13,13 +13,13 @@ void Sensor::init(const uint8_t pin) float Sensor::get_analog() { - return analogRead(_pin); + return (static_cast(analogRead(_pin))/(1<<12))*3.3f; } // Normally should be 5V, but the ADC can only see up to 3.3 on 12 bits float Sensor::get_RSR0() { - float sensor_volt=(float)(analogRead(_pin))/((1<<12)*3.3); + float sensor_volt=(static_cast(analogRead(_pin))/(1<<12))*3.3f; float RS_gas = (3.3-sensor_volt)/sensor_volt; return RS_gas/R0; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 3b8d799..b3d7fb6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -113,7 +113,12 @@ void setup() { // Initialize SSD1306 Init_SSD1306(); delay(5000); + + // Initialize Gateway from LoRa initGateway(); + + // Initialize Sensor + gaz_sensor.init(SENSOR_PIN); } void loop() {