Advertisement
JuanPa26

teensy_master1607

Jul 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1.  
  2. #include <antplusdefs.h>
  3. #include <USBHost_t36.h>
  4. #include <Wire.h>
  5. #include "I2C_Anything.h"
  6. #include <SparkFun_VEML6075_Arduino_Library.h>
  7. VEML6075 uv;
  8. const byte SLAVE_ADDRESS = 42;
  9. #include <SPI.h>
  10. #include <Adafruit_Sensor.h>
  11. #include <Adafruit_BME280.h>
  12.  
  13. #define BME_SCK 13
  14. #define BME_MISO 12
  15. #define BME_MOSI 11
  16. #define BME_CS 10
  17.  
  18. #define SEALEVELPRESSURE_HPA (1013.25)
  19.  
  20. Adafruit_BME280 bme;
  21.  
  22. #include "DGS.h"
  23.  
  24. DGS mySensor1(&Serial1);
  25. DGS mySensor2(&Serial2);
  26. DGS mySensor3(&Serial3);
  27. DGS mySensor4(&Serial4);
  28. DGS mySensor5(&Serial5);
  29.  
  30. float NO20 = 21, CO0 = 300, SO20 = 35, H2S0 = 8, O30 = 2;
  31. //float UVA=0, UVB=0, UV=0;
  32. float NO2um=0,COum=0,SO2um=0, H2Sum=0,O3um=0;
  33. int prom=5,timing=300;
  34. //int SO2um=0, H2Sum=0;
  35. void setup()
  36. {
  37. Serial.begin(9600);
  38. Serial1.begin(9600);
  39. Serial2.begin(9600);
  40. Serial3.begin(9600);
  41. Serial4.begin(9600);
  42. Serial5.begin(9600);
  43. FlushSerials();
  44.  
  45. Serial.println("Begin Setup");
  46.  
  47. mySensor1.DEBUG = false;
  48. mySensor2.DEBUG = false;
  49. mySensor3.DEBUG = false;
  50. mySensor4.DEBUG = false;
  51. mySensor5.DEBUG = false;
  52.  
  53. firstSPEC_SET();
  54. Wire.begin ();
  55.  
  56. USBHost::begin();
  57. bool status;
  58.  
  59. // default settings
  60. // (you can also pass in a Wire library object like &Wire2)
  61. status = bme.begin();
  62. if (!status) {
  63. Serial.println("Could not find a valid BME280 sensor, check wiring!");
  64. while (1);
  65. }
  66. uv.begin();
  67. } // end of setup
  68.  
  69. void loop()
  70. {
  71. /***************************************************Adquisicion de datos*********************************************************/
  72. //BME280
  73. float S1 =bme.readTemperature();
  74. float S2 =bme.readPressure() / 100.0F;
  75. float S3 =bme.readAltitude(SEALEVELPRESSURE_HPA);
  76. float S4 =bme.readHumidity();
  77. float UVA = uv.uva();
  78. float UVB = uv.uvb();
  79. float UV = uv.index();
  80. //UVData();
  81. //Sensores de gas
  82. SensoresGases();
  83.  
  84.  
  85. /**************************************************Envio de datos**********************************************************/
  86. Wire.beginTransmission (SLAVE_ADDRESS);
  87. I2C_writeAnything (S1);
  88. I2C_writeAnything (S2);
  89. I2C_writeAnything (S3);
  90. I2C_writeAnything (S4),
  91. I2C_writeAnything (O3um);
  92. I2C_writeAnything (NO2um);
  93.  
  94. Wire.endTransmission ();
  95. delay (1000);
  96.  
  97. Wire.beginTransmission (SLAVE_ADDRESS);
  98. printGases_OG();
  99. I2C_writeAnything (COum);
  100. I2C_writeAnything (SO2um);
  101. I2C_writeAnything (H2Sum);
  102. I2C_writeAnything (UVA);
  103. I2C_writeAnything (UVB);
  104. Wire.endTransmission ();
  105.  
  106. delay (1000);
  107.  
  108. Wire.beginTransmission (SLAVE_ADDRESS);
  109. I2C_writeAnything (UV);
  110. Wire.endTransmission ();
  111. /*************************************************Impresion de datos**************************************************************/
  112. Serial.print("BME280\t");
  113. Serial.print(S1);Serial.print(";");
  114. Serial.print(S2);Serial.print(";");
  115. Serial.print(S3);Serial.print(";");
  116. Serial.println(S4);
  117. Serial.print("VEML\t");
  118. Serial.print(UVA);Serial.print(";");
  119. Serial.print(UVB);Serial.print(";");
  120. Serial.println(UV);
  121. //Serial.print("SPEC\t");
  122. //printSensoresGases();
  123. delay (1000);
  124. // end of for
  125.  
  126. } // end of loop
  127.  
  128. volatile int S1;
  129. void FlushSerials(){
  130. Serial.flush();
  131. Serial1.flush();
  132. Serial2.flush();
  133. Serial3.flush();
  134. Serial4.flush();
  135. Serial5.flush();
  136. }
  137.  
  138. //void UVData(){
  139. // float UV = uv.index();
  140. // Serial.print(UV); Serial.println('\t');
  141. // // UV=UV+9;
  142. // String mensaje = "";
  143. // if ( 2>=UV && 0<=UV ){
  144. // mensaje="VERDE:BAJA";
  145. // Serial.println(mensaje);
  146. // }
  147. // if ( 5>=UV && 3<=UV ){
  148. // mensaje="AMARILLO:MODERADA",
  149. // Serial.println(mensaje);
  150. // }
  151. // if ( 7>=UV && 6<=UV ){
  152. // mensaje="NARANJA:ALTA",
  153. // Serial.println(mensaje);
  154. // }
  155. // if ( 10>=UV && 8<=UV ){
  156. // mensaje="ROJO:MUY ALTA",
  157. // Serial.println(mensaje);
  158. // }
  159. // if ( 11<=UV ){
  160. // mensaje="MORADO:EXTREMADAMENTE ALTA";
  161. // Serial.println(mensaje);
  162. // }
  163. //}
  164.  
  165.  
  166.  
  167. void SensoresGases(){
  168. delay(100);
  169.  
  170. //getConcSensores();
  171. promSPEC(prom);
  172. if((NO2um < 0 && mySensor1.zero()) || NO2um > 10*NO20){
  173. NO2um = NO20;
  174. //Serial.println("Finished Setting sensor 1 Zero");
  175. }
  176. if((COum < 0 && mySensor2.zero()) || COum > 10*CO0){
  177. COum = CO0;
  178. //Serial.println("Finished Setting sensor 2 Zero");
  179. }
  180. if((SO2um < 0 && mySensor3.zero()) || SO2um > 10*SO20){
  181. SO2um = SO20;
  182. //Serial.println("Finished Setting sensor 3 Zero");
  183. }
  184. if((H2Sum < 0 && mySensor4.zero()) || H2Sum > 10*H2S0){
  185. H2Sum = H2S0;
  186. //Serial.println("Finished Setting sensor 4 Zero");
  187. }
  188. if((O3um < 0 && mySensor5.zero()) || O3um > 10*O30){
  189. O3um = O30;
  190. //Serial.println("Finished Setting sensor 5 Zero");
  191. }
  192. }
  193.  
  194. void getConcSensores(){
  195. mySensor1.getData('\r');
  196. mySensor2.getData('\r');
  197. mySensor3.getData('\r');
  198. mySensor4.getData('\r');
  199. mySensor5.getData('\r');
  200. NO2um = (float)mySensor1.getConc('p');
  201. COum = (float)mySensor2.getConc('p');
  202. SO2um = (float)mySensor3.getConc('p');
  203. H2Sum = (float)mySensor4.getConc('p');
  204. O3um = (float)mySensor5.getConc('p');
  205. }
  206.  
  207. void printGases_OG(){
  208. Serial.print(NO2um,1);
  209. Serial.print(";");
  210. Serial.print(COum,1);
  211. Serial.print(";");
  212. Serial.print(SO2um,1);
  213. Serial.print(";");
  214. Serial.print(H2Sum,1);
  215. Serial.print(";");
  216. Serial.print(O3um,1);
  217. Serial.println();
  218. }
  219.  
  220. void firstSPEC_SET(){
  221. delay(1000);
  222. Serial1.write('A');
  223. delay(1000);
  224. Serial1.print(timing);
  225. delay(500);
  226. Serial2.write('\r');
  227. delay(2000);
  228. Serial2.write('A');
  229. delay(1000);
  230. Serial2.print(timing);
  231. delay(500);
  232. Serial2.write('\r');
  233. delay(2000);delay(1000);
  234. Serial3.write('A');
  235. delay(1000);
  236. Serial3.print(timing);
  237. delay(500);
  238. Serial3.write('\r');
  239. delay(2000);delay(1000);
  240. Serial4.write('A');
  241. delay(1000);
  242. Serial4.print(timing);
  243. delay(500);
  244. Serial4.write('\r');
  245. delay(2000);
  246. Serial5.write('A');
  247. delay(1000);
  248. Serial5.print(timing);
  249. delay(500);
  250. Serial5.write('\r');
  251. delay(2000);
  252.  
  253. if (mySensor1.zero()) Serial.println("Finished Setting Sensor 1 Zero");
  254. if (mySensor2.zero()) Serial.println("Finished Setting Sensor 2 Zero");
  255. if (mySensor3.zero()) Serial.println("Finished Setting Sensor 3 Zero");
  256. if (mySensor4.zero()) Serial.println("Finished Setting Sensor 4 Zero");
  257. if (mySensor5.zero()) Serial.println("Finished Setting Sensor 5 Zero");
  258.  
  259. }
  260.  
  261. void promSPEC(int prom){
  262. NO2um=0;COum=0;SO2um=0; H2Sum=0;O3um=0;
  263.  
  264. for(int i=0 ; i < prom ; i++){
  265.  
  266. mySensor1.getData('\r');
  267. mySensor2.getData('\r');
  268. mySensor3.getData('\r');
  269. mySensor4.getData('\r');
  270. mySensor5.getData('\r');
  271.  
  272. NO2um = NO2um + mySensor1.getConc('p');
  273. COum = COum + mySensor2.getConc('p');
  274. SO2um = SO2um + mySensor3.getConc('p');
  275. H2Sum = H2Sum + mySensor4.getConc('p');
  276. O3um = O3um + mySensor5.getConc('p');
  277. }
  278. //Correcion valores referencia en ppb
  279.  
  280. //NO2um = (NO2um)/prom+ NO20;
  281. //COum = (COum)/prom+ CO0;
  282. //SO2um = (SO2um)/prom + SO20;
  283. //H2Sum = (H2Sum)/prom + H2S0;
  284. //O3um = (O3um)/prom + O30;
  285.  
  286. //Cambio de unidades de ppb a um/m3
  287. NO2um = 0.0409*NO2um*46.0055/prom + NO20;
  288. COum = 0.0409*COum*28.01/prom + CO0;
  289. SO2um = 0.0409*SO2um*64.066/prom + SO20;
  290. H2Sum = 0.0409*H2Sum*34.1/prom + H2S0;
  291. O3um = 0.0409*O3um*48/prom + O30;
  292. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement