Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <antplusdefs.h>
- #include <USBHost_t36.h>
- #include <Wire.h>
- #include "I2C_Anything.h"
- #include <SparkFun_VEML6075_Arduino_Library.h>
- VEML6075 uv;
- const byte SLAVE_ADDRESS = 42;
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #define BME_SCK 13
- #define BME_MISO 12
- #define BME_MOSI 11
- #define BME_CS 10
- #define SEALEVELPRESSURE_HPA (1013.25)
- Adafruit_BME280 bme;
- #include "DGS.h"
- DGS mySensor1(&Serial1);
- DGS mySensor2(&Serial2);
- DGS mySensor3(&Serial3);
- DGS mySensor4(&Serial4);
- DGS mySensor5(&Serial5);
- float NO20 = 21, CO0 = 300, SO20 = 35, H2S0 = 8, O30 = 2;
- //float UVA=0, UVB=0, UV=0;
- float NO2um=0,COum=0,SO2um=0, H2Sum=0,O3um=0;
- int prom=5,timing=300;
- //int SO2um=0, H2Sum=0;
- void setup()
- {
- Serial.begin(9600);
- Serial1.begin(9600);
- Serial2.begin(9600);
- Serial3.begin(9600);
- Serial4.begin(9600);
- Serial5.begin(9600);
- FlushSerials();
- Serial.println("Begin Setup");
- mySensor1.DEBUG = false;
- mySensor2.DEBUG = false;
- mySensor3.DEBUG = false;
- mySensor4.DEBUG = false;
- mySensor5.DEBUG = false;
- firstSPEC_SET();
- Wire.begin ();
- USBHost::begin();
- bool status;
- // default settings
- // (you can also pass in a Wire library object like &Wire2)
- status = bme.begin();
- if (!status) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1);
- }
- uv.begin();
- } // end of setup
- void loop()
- {
- /***************************************************Adquisicion de datos*********************************************************/
- //BME280
- float S1 =bme.readTemperature();
- float S2 =bme.readPressure() / 100.0F;
- float S3 =bme.readAltitude(SEALEVELPRESSURE_HPA);
- float S4 =bme.readHumidity();
- float UVA = uv.uva();
- float UVB = uv.uvb();
- float UV = uv.index();
- //UVData();
- //Sensores de gas
- SensoresGases();
- /**************************************************Envio de datos**********************************************************/
- Wire.beginTransmission (SLAVE_ADDRESS);
- I2C_writeAnything (S1);
- I2C_writeAnything (S2);
- I2C_writeAnything (S3);
- I2C_writeAnything (S4),
- I2C_writeAnything (O3um);
- I2C_writeAnything (NO2um);
- Wire.endTransmission ();
- delay (1000);
- Wire.beginTransmission (SLAVE_ADDRESS);
- printGases_OG();
- I2C_writeAnything (COum);
- I2C_writeAnything (SO2um);
- I2C_writeAnything (H2Sum);
- I2C_writeAnything (UVA);
- I2C_writeAnything (UVB);
- Wire.endTransmission ();
- delay (1000);
- Wire.beginTransmission (SLAVE_ADDRESS);
- I2C_writeAnything (UV);
- Wire.endTransmission ();
- /*************************************************Impresion de datos**************************************************************/
- Serial.print("BME280\t");
- Serial.print(S1);Serial.print(";");
- Serial.print(S2);Serial.print(";");
- Serial.print(S3);Serial.print(";");
- Serial.println(S4);
- Serial.print("VEML\t");
- Serial.print(UVA);Serial.print(";");
- Serial.print(UVB);Serial.print(";");
- Serial.println(UV);
- //Serial.print("SPEC\t");
- //printSensoresGases();
- delay (1000);
- // end of for
- } // end of loop
- volatile int S1;
- void FlushSerials(){
- Serial.flush();
- Serial1.flush();
- Serial2.flush();
- Serial3.flush();
- Serial4.flush();
- Serial5.flush();
- }
- //void UVData(){
- // float UV = uv.index();
- // Serial.print(UV); Serial.println('\t');
- // // UV=UV+9;
- // String mensaje = "";
- // if ( 2>=UV && 0<=UV ){
- // mensaje="VERDE:BAJA";
- // Serial.println(mensaje);
- // }
- // if ( 5>=UV && 3<=UV ){
- // mensaje="AMARILLO:MODERADA",
- // Serial.println(mensaje);
- // }
- // if ( 7>=UV && 6<=UV ){
- // mensaje="NARANJA:ALTA",
- // Serial.println(mensaje);
- // }
- // if ( 10>=UV && 8<=UV ){
- // mensaje="ROJO:MUY ALTA",
- // Serial.println(mensaje);
- // }
- // if ( 11<=UV ){
- // mensaje="MORADO:EXTREMADAMENTE ALTA";
- // Serial.println(mensaje);
- // }
- //}
- void SensoresGases(){
- delay(100);
- //getConcSensores();
- promSPEC(prom);
- if((NO2um < 0 && mySensor1.zero()) || NO2um > 10*NO20){
- NO2um = NO20;
- //Serial.println("Finished Setting sensor 1 Zero");
- }
- if((COum < 0 && mySensor2.zero()) || COum > 10*CO0){
- COum = CO0;
- //Serial.println("Finished Setting sensor 2 Zero");
- }
- if((SO2um < 0 && mySensor3.zero()) || SO2um > 10*SO20){
- SO2um = SO20;
- //Serial.println("Finished Setting sensor 3 Zero");
- }
- if((H2Sum < 0 && mySensor4.zero()) || H2Sum > 10*H2S0){
- H2Sum = H2S0;
- //Serial.println("Finished Setting sensor 4 Zero");
- }
- if((O3um < 0 && mySensor5.zero()) || O3um > 10*O30){
- O3um = O30;
- //Serial.println("Finished Setting sensor 5 Zero");
- }
- }
- void getConcSensores(){
- mySensor1.getData('\r');
- mySensor2.getData('\r');
- mySensor3.getData('\r');
- mySensor4.getData('\r');
- mySensor5.getData('\r');
- NO2um = (float)mySensor1.getConc('p');
- COum = (float)mySensor2.getConc('p');
- SO2um = (float)mySensor3.getConc('p');
- H2Sum = (float)mySensor4.getConc('p');
- O3um = (float)mySensor5.getConc('p');
- }
- void printGases_OG(){
- Serial.print(NO2um,1);
- Serial.print(";");
- Serial.print(COum,1);
- Serial.print(";");
- Serial.print(SO2um,1);
- Serial.print(";");
- Serial.print(H2Sum,1);
- Serial.print(";");
- Serial.print(O3um,1);
- Serial.println();
- }
- void firstSPEC_SET(){
- delay(1000);
- Serial1.write('A');
- delay(1000);
- Serial1.print(timing);
- delay(500);
- Serial2.write('\r');
- delay(2000);
- Serial2.write('A');
- delay(1000);
- Serial2.print(timing);
- delay(500);
- Serial2.write('\r');
- delay(2000);delay(1000);
- Serial3.write('A');
- delay(1000);
- Serial3.print(timing);
- delay(500);
- Serial3.write('\r');
- delay(2000);delay(1000);
- Serial4.write('A');
- delay(1000);
- Serial4.print(timing);
- delay(500);
- Serial4.write('\r');
- delay(2000);
- Serial5.write('A');
- delay(1000);
- Serial5.print(timing);
- delay(500);
- Serial5.write('\r');
- delay(2000);
- if (mySensor1.zero()) Serial.println("Finished Setting Sensor 1 Zero");
- if (mySensor2.zero()) Serial.println("Finished Setting Sensor 2 Zero");
- if (mySensor3.zero()) Serial.println("Finished Setting Sensor 3 Zero");
- if (mySensor4.zero()) Serial.println("Finished Setting Sensor 4 Zero");
- if (mySensor5.zero()) Serial.println("Finished Setting Sensor 5 Zero");
- }
- void promSPEC(int prom){
- NO2um=0;COum=0;SO2um=0; H2Sum=0;O3um=0;
- for(int i=0 ; i < prom ; i++){
- mySensor1.getData('\r');
- mySensor2.getData('\r');
- mySensor3.getData('\r');
- mySensor4.getData('\r');
- mySensor5.getData('\r');
- NO2um = NO2um + mySensor1.getConc('p');
- COum = COum + mySensor2.getConc('p');
- SO2um = SO2um + mySensor3.getConc('p');
- H2Sum = H2Sum + mySensor4.getConc('p');
- O3um = O3um + mySensor5.getConc('p');
- }
- //Correcion valores referencia en ppb
- //NO2um = (NO2um)/prom+ NO20;
- //COum = (COum)/prom+ CO0;
- //SO2um = (SO2um)/prom + SO20;
- //H2Sum = (H2Sum)/prom + H2S0;
- //O3um = (O3um)/prom + O30;
- //Cambio de unidades de ppb a um/m3
- NO2um = 0.0409*NO2um*46.0055/prom + NO20;
- COum = 0.0409*COum*28.01/prom + CO0;
- SO2um = 0.0409*SO2um*64.066/prom + SO20;
- H2Sum = 0.0409*H2Sum*34.1/prom + H2S0;
- O3um = 0.0409*O3um*48/prom + O30;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement