Código sensor para material particulado con PMS 5003

Dependencies:   DmTftLibrary

Committer:
mateojs16
Date:
Fri Oct 29 21:57:36 2021 +0000
Revision:
3:4c7554fd88a5
Parent:
2:e80f510b3cb2
Child:
4:c8e5928f440c
szs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sebastianrestrepo 0:d5dc1e5564a5 1 #include "PMS5003.h"
sebastianrestrepo 0:d5dc1e5564a5 2
sebastianrestrepo 1:5bc605d2b8f8 3 //#include "DmTftHX8353C.h"
sebastianrestrepo 1:5bc605d2b8f8 4 //#include "DmTftS6D0164.h"
sebastianrestrepo 1:5bc605d2b8f8 5 //#include "DmTftIli9325.h"
sebastianrestrepo 1:5bc605d2b8f8 6 #include "DmTftIli9341.h"
sebastianrestrepo 1:5bc605d2b8f8 7 #include "DmTftSsd2119.h"
sebastianrestrepo 1:5bc605d2b8f8 8 #include "DmTftRa8875.h"
sebastianrestrepo 1:5bc605d2b8f8 9 #include "DmTouch.h"
sebastianrestrepo 1:5bc605d2b8f8 10 #include "DmTpFt6x06.h"
sebastianrestrepo 1:5bc605d2b8f8 11
sebastianrestrepo 1:5bc605d2b8f8 12 //#define log(...) printf(__VA_ARGS__)
sebastianrestrepo 1:5bc605d2b8f8 13 #define log(...)
sebastianrestrepo 1:5bc605d2b8f8 14
sebastianrestrepo 1:5bc605d2b8f8 15 /* Displays without adapter */
sebastianrestrepo 1:5bc605d2b8f8 16 #define DM_PIN_SPI_MOSI D11
sebastianrestrepo 1:5bc605d2b8f8 17 #define DM_PIN_SPI_MISO D12
sebastianrestrepo 1:5bc605d2b8f8 18 #define DM_PIN_SPI_SCK D13
sebastianrestrepo 1:5bc605d2b8f8 19 #define DM_PIN_CS_TOUCH D4
sebastianrestrepo 1:5bc605d2b8f8 20 #define DM_PIN_CS_TFT D10
sebastianrestrepo 1:5bc605d2b8f8 21 #define DM_PIN_CS_SDCARD D8
sebastianrestrepo 1:5bc605d2b8f8 22 #define DM_PIN_CS_FLASH D6
sebastianrestrepo 1:5bc605d2b8f8 23 /******************************************************************************
sebastianrestrepo 1:5bc605d2b8f8 24 * Local variables
sebastianrestrepo 1:5bc605d2b8f8 25 *****************************************************************************/
sebastianrestrepo 1:5bc605d2b8f8 26
sebastianrestrepo 1:5bc605d2b8f8 27 /********* TFT DISPLAY INIT *********/
sebastianrestrepo 1:5bc605d2b8f8 28 DmTftIli9341 tft(D10, D9, D11, D12, D13); /* DmTftIli9341(PinName cs, PinName dc, PinName mosi, PinName miso, PinName clk) DM_TFT28_105 and DM_TFT28_116*/
sebastianrestrepo 1:5bc605d2b8f8 29 DmTouch touch(DmTouch::DM_TFT28_105, D11, D12, D13);
sebastianrestrepo 1:5bc605d2b8f8 30
sebastianrestrepo 1:5bc605d2b8f8 31 DigitalInOut csTouch(DM_PIN_CS_TOUCH, PIN_OUTPUT, PullUp, 1);
sebastianrestrepo 1:5bc605d2b8f8 32 DigitalInOut csDisplay(DM_PIN_CS_TFT, PIN_OUTPUT, PullUp, 1);
sebastianrestrepo 1:5bc605d2b8f8 33 DigitalInOut csSDCard(DM_PIN_CS_SDCARD, PIN_OUTPUT, PullUp, 1);
sebastianrestrepo 1:5bc605d2b8f8 34 #ifdef DM_PIN_CS_FLASH
sebastianrestrepo 1:5bc605d2b8f8 35 DigitalInOut csFlash(DM_PIN_CS_FLASH, PIN_OUTPUT, PullUp, 1);
sebastianrestrepo 1:5bc605d2b8f8 36 #endif
sebastianrestrepo 1:5bc605d2b8f8 37 /********* SENSOR INIT *********/
sebastianrestrepo 0:d5dc1e5564a5 38 PMS5003 pm25(D1, D0, D3); // UART TX, UART RX, POWER
sebastianrestrepo 0:d5dc1e5564a5 39
sebastianrestrepo 1:5bc605d2b8f8 40 /******************************************************************************
sebastianrestrepo 1:5bc605d2b8f8 41 * Global variables
sebastianrestrepo 1:5bc605d2b8f8 42 *****************************************************************************/
sebastianrestrepo 2:e80f510b3cb2 43 uint16_t pm = 0;
sebastianrestrepo 1:5bc605d2b8f8 44
sebastianrestrepo 1:5bc605d2b8f8 45 /******************************************************************************
sebastianrestrepo 1:5bc605d2b8f8 46 * Local functions
sebastianrestrepo 1:5bc605d2b8f8 47 *****************************************************************************/
sebastianrestrepo 0:d5dc1e5564a5 48 static EventQueue queue; // The callback from the driver is triggered from IRQ, use EventQueue to debounce to normal context
sebastianrestrepo 0:d5dc1e5564a5 49
sebastianrestrepo 0:d5dc1e5564a5 50 void pm25_data_callback(pms5003_data_t data) {
sebastianrestrepo 0:d5dc1e5564a5 51 printf("---------------------------------------\n");
sebastianrestrepo 0:d5dc1e5564a5 52 printf("Concentration Units (standard)\n");
sebastianrestrepo 0:d5dc1e5564a5 53 printf("PM 1.0: %u", data.pm10_standard);
mateojs16 3:4c7554fd88a5 54 tft.drawString(70, 70, "PM 1.0:");
mateojs16 3:4c7554fd88a5 55 tft.drawNumber(150, 70, data.pm10_standard, 5, false);
sebastianrestrepo 0:d5dc1e5564a5 56 printf("\t\tPM 2.5: %u", data.pm25_standard);
mateojs16 3:4c7554fd88a5 57 tft.drawString(70, 110, "PM 2.5:");
mateojs16 3:4c7554fd88a5 58 tft.drawNumber(150, 110, data.pm25_standard, 5, false);
sebastianrestrepo 0:d5dc1e5564a5 59 printf("\t\tPM 10: %u\n", data.pm100_standard);
mateojs16 3:4c7554fd88a5 60 tft.drawString(70, 150, "PM 10.0:");
mateojs16 3:4c7554fd88a5 61 tft.drawNumber(150, 150, data.pm100_standard, 5, false);
sebastianrestrepo 0:d5dc1e5564a5 62 printf("---------------------------------------\n");
sebastianrestrepo 0:d5dc1e5564a5 63 printf("Concentration Units (environmental)\n");
sebastianrestrepo 0:d5dc1e5564a5 64 printf("PM 1.0: %u", data.pm10_env);
sebastianrestrepo 0:d5dc1e5564a5 65 printf("\t\tPM 2.5: %u", data.pm25_env);
sebastianrestrepo 0:d5dc1e5564a5 66 printf("\t\tPM 10: %u\n", data.pm100_env);
sebastianrestrepo 0:d5dc1e5564a5 67 printf("---------------------------------------\n");
sebastianrestrepo 0:d5dc1e5564a5 68 printf("Particles > 0.3um / 0.1L air: %u\n", data.particles_03um);
sebastianrestrepo 0:d5dc1e5564a5 69 printf("Particles > 0.5um / 0.1L air: %u\n", data.particles_05um);
sebastianrestrepo 0:d5dc1e5564a5 70 printf("Particles > 1.0um / 0.1L air: %u\n", data.particles_10um);
sebastianrestrepo 0:d5dc1e5564a5 71 printf("Particles > 2.5um / 0.1L air: %u\n", data.particles_25um);
sebastianrestrepo 0:d5dc1e5564a5 72 printf("Particles > 5.0um / 0.1L air: %u\n", data.particles_50um);
sebastianrestrepo 0:d5dc1e5564a5 73 printf("Particles > 10.0 um / 0.1L air: %u\n", data.particles_100um);
sebastianrestrepo 0:d5dc1e5564a5 74 printf("---------------------------------------\n");
sebastianrestrepo 0:d5dc1e5564a5 75 }
sebastianrestrepo 0:d5dc1e5564a5 76
sebastianrestrepo 1:5bc605d2b8f8 77 /******************************************************************************
sebastianrestrepo 1:5bc605d2b8f8 78 * Main
sebastianrestrepo 1:5bc605d2b8f8 79 *****************************************************************************/
sebastianrestrepo 1:5bc605d2b8f8 80
sebastianrestrepo 1:5bc605d2b8f8 81
sebastianrestrepo 1:5bc605d2b8f8 82
sebastianrestrepo 1:5bc605d2b8f8 83
sebastianrestrepo 0:d5dc1e5564a5 84 int main() {
sebastianrestrepo 1:5bc605d2b8f8 85 log("init tft \r\n");
sebastianrestrepo 2:e80f510b3cb2 86 tft.init();
sebastianrestrepo 2:e80f510b3cb2 87
mateojs16 3:4c7554fd88a5 88
sebastianrestrepo 2:e80f510b3cb2 89 uint16_t w = tft.width();
sebastianrestrepo 2:e80f510b3cb2 90 uint16_t h = tft.height();
mateojs16 3:4c7554fd88a5 91 tft.fillRectangle(0, 0, 1000,1000, 0xFFFF);
mateojs16 3:4c7554fd88a5 92 tft.fillCircle(130, 250, 40, 0xF81F);
sebastianrestrepo 2:e80f510b3cb2 93 tft.setTextColor(0xFFFF,0xF81F);
sebastianrestrepo 2:e80f510b3cb2 94 tft.drawString(35, 30, "Cantidad de particulas : ");
mateojs16 3:4c7554fd88a5 95
sebastianrestrepo 0:d5dc1e5564a5 96
sebastianrestrepo 0:d5dc1e5564a5 97 // This callback runs in an interrupt context, thus we debounce to the event queue here
sebastianrestrepo 0:d5dc1e5564a5 98 pm25.enable(queue.event(&pm25_data_callback));
sebastianrestrepo 0:d5dc1e5564a5 99
sebastianrestrepo 0:d5dc1e5564a5 100 queue.dispatch_forever();
sebastianrestrepo 0:d5dc1e5564a5 101 }