|
|
@@ -0,0 +1,119 @@ |
|
|
|
/***************************************************************************************************************************** |
|
|
|
Auteur : FDES et LilianRM |
|
|
|
Pour LowTech Bordeaux |
|
|
|
*****************************************************************************************************************************/ |
|
|
|
|
|
|
|
// setup des librairies et des variables globales |
|
|
|
|
|
|
|
#include <Arduino.h> |
|
|
|
|
|
|
|
#include <High_Temp.h> |
|
|
|
#include <OneWire.h> |
|
|
|
#include <DallasTemperature.h> |
|
|
|
#include <Multichannel_Gas_GMXXX.h> |
|
|
|
#include <Wire.h> |
|
|
|
GAS_GMXXX<TwoWire> gas; |
|
|
|
#include <SoftwareSerial.h> |
|
|
|
#include <MHZ.h> |
|
|
|
|
|
|
|
int MHZ19B_PREHEATING_TIME = 3 * 60; |
|
|
|
|
|
|
|
#define O2_WIRE A2 |
|
|
|
#define ONE_WIRE_BUS 2 |
|
|
|
|
|
|
|
HighTemp ht(A1, A0); |
|
|
|
OneWire oneWire(ONE_WIRE_BUS); |
|
|
|
DallasTemperature dallasTemp(&oneWire); |
|
|
|
uint8_t tempAddress[8] = {0x28,0x46,0xBF,0x31,0x08,0,0,0x1B}; |
|
|
|
|
|
|
|
char data_sent[100]; |
|
|
|
char incomingInt; |
|
|
|
String data_string; |
|
|
|
|
|
|
|
MHZ co2capt(4,5, MHZ19B); // RX, TX, type |
|
|
|
|
|
|
|
// fonctions de conversion |
|
|
|
|
|
|
|
int Float2Int(float number){ |
|
|
|
return (int)number/1; |
|
|
|
} |
|
|
|
|
|
|
|
int Coma2Int(float number, int nbAfterComa){ |
|
|
|
number = number - (int)number; |
|
|
|
if(number < 0){ |
|
|
|
return (int)((-number)*pow(10, nbAfterComa)/1); |
|
|
|
}else{ |
|
|
|
return (int)(number*pow(10, nbAfterComa)/1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setup() // setup des capteurs |
|
|
|
{ |
|
|
|
delay(20000); |
|
|
|
for(int i = 0;i<10;i++){ |
|
|
|
co2capt.calibrate400ppm(); |
|
|
|
delay(10); |
|
|
|
} |
|
|
|
gas.begin(Wire, 0x08); // use the hardware I2C |
|
|
|
ht.begin(); |
|
|
|
dallasTemp.begin(); |
|
|
|
dallasTemp.setResolution(12); |
|
|
|
delay(10000); |
|
|
|
Serial.begin(9600); |
|
|
|
delay(20); |
|
|
|
Serial.println('0'); |
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|
if(Serial.available() > 0){ // wait for serial to have data |
|
|
|
incomingInt = Serial.read() - '0'; |
|
|
|
if(incomingInt == 1){ // read data from captors and construct string |
|
|
|
Serial.flush(); |
|
|
|
|
|
|
|
// GM102B NO2 sensor |
|
|
|
int val102 = gas.getGM102B(); |
|
|
|
// GM102B alcool? sensor |
|
|
|
int val302 = gas.getGM302B(); |
|
|
|
// GM502B VOC sensor |
|
|
|
int val502 = gas.getGM502B(); |
|
|
|
// GM702B CO sensor |
|
|
|
int val702 = gas.getGM702B(); |
|
|
|
|
|
|
|
int valOxygen = analogRead(O2_WIRE); |
|
|
|
|
|
|
|
int gazco2ppm = co2capt.readCO2UART(); |
|
|
|
int tempco2ppm = co2capt.getLastTemperature(); |
|
|
|
|
|
|
|
float thermoCpl = ht.getThmc(); |
|
|
|
|
|
|
|
dallasTemp.requestTemperatures(); |
|
|
|
int onewireTemp = dallasTemp.getTemp(tempAddress); |
|
|
|
|
|
|
|
data_string = String(valOxygen) + "," |
|
|
|
+ String(val102) + "," |
|
|
|
+ String(val302) + "," |
|
|
|
+ String(val502) + "," |
|
|
|
+ String(val702) + "," |
|
|
|
+ String(gazco2ppm) + "," |
|
|
|
+ String(tempco2ppm) + "," |
|
|
|
+ String(Float2Int(thermoCpl)) + "." + String(Coma2Int(thermoCpl,1)) + "," |
|
|
|
+ String(Float2Int(onewireTemp)); |
|
|
|
data_string.toCharArray(data_sent, 100); |
|
|
|
|
|
|
|
|
|
|
|
}else if(incomingInt == 2){ // send data |
|
|
|
|
|
|
|
delay(10); |
|
|
|
Serial.flush(); |
|
|
|
Serial.println(data_sent); |
|
|
|
|
|
|
|
}else if(incomingInt == 0){ // send ready signal |
|
|
|
Serial.flush(); |
|
|
|
Serial.println('0'); |
|
|
|
|
|
|
|
}else{ |
|
|
|
Serial.flush(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |