You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.3KB

  1. /*****************************************************************************************************************************
  2. Auteur : FDES et LilianRM
  3. Pour LowTech Bordeaux
  4. Exemple de fichier Arduino pour 5 capteurs:
  5. - 1 capteur multicanaux, I2C (4 capteurs)
  6. - 1 capteur O2, analogique
  7. - 1 capteur CO2 MH-Z19B, UART (+ température intégrée)
  8. - 1 thermocouple, lecture analogique
  9. - 1 sonde de température Onewire, numérique.
  10. *****************************************************************************************************************************/
  11. // setup des librairies et des variables globales
  12. #include <Arduino.h>
  13. #include <High_Temp.h>
  14. #include <OneWire.h>
  15. #include <DallasTemperature.h>
  16. #include <Multichannel_Gas_GMXXX.h>
  17. #include <Wire.h>
  18. GAS_GMXXX<TwoWire> gas;
  19. #include <SoftwareSerial.h>
  20. #include <MHZ.h>
  21. int MHZ19B_PREHEATING_TIME = 3 * 60;
  22. #define O2_WIRE A2
  23. #define ONE_WIRE_BUS 2
  24. HighTemp ht(A1, A0);
  25. OneWire oneWire(ONE_WIRE_BUS);
  26. DallasTemperature dallasTemp(&oneWire);
  27. uint8_t tempAddress[8] = {0x28,0x46,0xBF,0x31,0x08,0,0,0x1B};
  28. char data_sent[100];
  29. char incomingInt;
  30. String data_string;
  31. MHZ co2capt(4,5, MHZ19B); // RX, TX, type
  32. // fonctions de conversion
  33. int Float2Int(float number){
  34. return (int)number/1;
  35. }
  36. int Coma2Int(float number, int nbAfterComa){
  37. number = number - (int)number;
  38. if(number < 0){
  39. return (int)((-number)*pow(10, nbAfterComa)/1);
  40. }else{
  41. return (int)(number*pow(10, nbAfterComa)/1);
  42. }
  43. }
  44. void setup() // setup des capteurs
  45. {
  46. delay(20000);
  47. for(int i = 0;i<10;i++){
  48. co2capt.calibrate400ppm();
  49. delay(10);
  50. }
  51. gas.begin(Wire, 0x08); // use the hardware I2C
  52. ht.begin();
  53. dallasTemp.begin();
  54. dallasTemp.setResolution(12);
  55. delay(10000);
  56. Serial.begin(9600);
  57. delay(20);
  58. Serial.println('0');
  59. }
  60. void loop() {
  61. if(Serial.available() > 0){ // wait for serial to have data
  62. incomingInt = Serial.read() - '0';
  63. if(incomingInt == 1){ // read data from captors and construct string
  64. Serial.flush();
  65. // GM102B NO2 sensor
  66. int val102 = gas.getGM102B();
  67. // GM102B alcool? sensor
  68. int val302 = gas.getGM302B();
  69. // GM502B VOC sensor
  70. int val502 = gas.getGM502B();
  71. // GM702B CO sensor
  72. int val702 = gas.getGM702B();
  73. int valOxygen = analogRead(O2_WIRE);
  74. int gazco2ppm = co2capt.readCO2UART();
  75. int tempco2ppm = co2capt.getLastTemperature();
  76. float thermoCpl = ht.getThmc();
  77. dallasTemp.requestTemperatures();
  78. int onewireTemp = dallasTemp.getTemp(tempAddress);
  79. data_string = String(valOxygen) + ","
  80. + String(val102) + ","
  81. + String(val302) + ","
  82. + String(val502) + ","
  83. + String(val702) + ","
  84. + String(gazco2ppm) + ","
  85. + String(tempco2ppm) + ","
  86. + String(Float2Int(thermoCpl)) + "." + String(Coma2Int(thermoCpl,1)) + ","
  87. + String(Float2Int(onewireTemp));
  88. data_string.toCharArray(data_sent, 100);
  89. }else if(incomingInt == 2){ // send data
  90. delay(10);
  91. Serial.flush();
  92. Serial.println(data_sent);
  93. }else if(incomingInt == 0){ // send ready signal
  94. Serial.flush();
  95. Serial.println('0');
  96. }else{
  97. Serial.flush();
  98. }
  99. }
  100. }