Implement initial firmware version of envisens
This commit is contained in:
parent
5900a8384e
commit
1df37cb910
62
envisens/atmega_fw/atmega_fw.ino
Normal file
62
envisens/atmega_fw/atmega_fw.ino
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/* Macrocell environmental sensor project EnviSens
|
||||||
|
*
|
||||||
|
* This firmware provides features to use an ATMEGA µC as an environmental sensor provider.
|
||||||
|
* Currently supported sensors:
|
||||||
|
* - digital pin D2: DHT22 temperature and humidity sensor
|
||||||
|
* - analog pin A0: MQ135 gas and air quality sensor
|
||||||
|
*
|
||||||
|
* (C) 2019 Macrocell - Environmental Sensing Solutions (MESS)
|
||||||
|
* proudly presented by Macrocell - FPGA Innovators
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include "DHT.h"
|
||||||
|
#include "configuration.h"
|
||||||
|
|
||||||
|
#define MQ135_PIN A0
|
||||||
|
#define DHT_PIN 2 // Digital pin connected to the DHT sensor
|
||||||
|
#define DHT_TYPE DHT22 // DHT 22 (AM2302), AM2321
|
||||||
|
DHT dht(DHT_PIN, DHT_TYPE);
|
||||||
|
|
||||||
|
int sensorValue;
|
||||||
|
long last_sample = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(SERIAL_BAUDRATE);
|
||||||
|
pinMode(MQ135_PIN, INPUT);
|
||||||
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
dht.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
long now = millis();
|
||||||
|
if (now - last_sample > OPERATION_PERIOD / 2) {
|
||||||
|
if (OPERATION_BLINK_EN) {digitalWrite(LED_BUILTIN, LOW);}
|
||||||
|
}
|
||||||
|
if (now - last_sample > OPERATION_PERIOD) {
|
||||||
|
last_sample = now;
|
||||||
|
if (OPERATION_BLINK_EN) {digitalWrite(LED_BUILTIN, HIGH);}
|
||||||
|
|
||||||
|
float h = dht.readHumidity();
|
||||||
|
float t = dht.readTemperature();
|
||||||
|
|
||||||
|
if (isnan(h) || isnan(t)) {
|
||||||
|
Serial.println(F("Failed to read from DHT sensor!"));
|
||||||
|
} else {
|
||||||
|
float hi = dht.computeHeatIndex(t, h, false);
|
||||||
|
Serial.print(F("Humidity: "));
|
||||||
|
Serial.print(h);
|
||||||
|
Serial.print(F("% Temperature: "));
|
||||||
|
Serial.print(t);
|
||||||
|
Serial.print(F("°C Heat index: "));
|
||||||
|
Serial.print(hi);
|
||||||
|
Serial.println(F("°C "));
|
||||||
|
}
|
||||||
|
|
||||||
|
sensorValue = analogRead(MQ135_PIN);
|
||||||
|
Serial.print("AirQuality=");
|
||||||
|
Serial.print(sensorValue, DEC);
|
||||||
|
Serial.println(" PPM");
|
||||||
|
}
|
||||||
|
}
|
11
envisens/atmega_fw/configuration.h
Normal file
11
envisens/atmega_fw/configuration.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/* Macrocell environmental sensor project EnviSens
|
||||||
|
*
|
||||||
|
* This header provides the necessary configurations for the ATMEGA firmware.
|
||||||
|
*
|
||||||
|
* (C) 2019 Macrocell - Environmental sensing solutions
|
||||||
|
* proudly presented by Macrocell - FPGA Innovators
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define SERIAL_BAUDRATE 115200
|
||||||
|
#define OPERATION_BLINK_EN true // blink continuously if in correct operation
|
||||||
|
#define OPERATION_PERIOD 2000 // sensor reading period in milliseconds
|
Loading…
Reference in New Issue
Block a user