![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Código sensor para material particulado con PMS 5003
main.cpp@2:e80f510b3cb2, 2021-10-28 (annotated)
- Committer:
- sebastianrestrepo
- Date:
- Thu Oct 28 22:24:20 2021 +0000
- Revision:
- 2:e80f510b3cb2
- Parent:
- 1:5bc605d2b8f8
- Child:
- 3:4c7554fd88a5
Programa para sensor PMS5003 utilizando K64F con display en tarjeta LCD
Who changed what in which revision?
User | Revision | Line number | New 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); |
sebastianrestrepo | 0:d5dc1e5564a5 | 54 | printf("\t\tPM 2.5: %u", data.pm25_standard); |
sebastianrestrepo | 2:e80f510b3cb2 | 55 | tft.drawString(70, 100, "PM 2.5:"); |
sebastianrestrepo | 2:e80f510b3cb2 | 56 | tft.drawNumber(150, 100, data.pm25_standard, 2, false); |
sebastianrestrepo | 0:d5dc1e5564a5 | 57 | printf("\t\tPM 10: %u\n", data.pm100_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 58 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 59 | printf("Concentration Units (environmental)\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 60 | printf("PM 1.0: %u", data.pm10_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 61 | printf("\t\tPM 2.5: %u", data.pm25_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 62 | printf("\t\tPM 10: %u\n", data.pm100_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 63 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 64 | printf("Particles > 0.3um / 0.1L air: %u\n", data.particles_03um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 65 | printf("Particles > 0.5um / 0.1L air: %u\n", data.particles_05um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 66 | printf("Particles > 1.0um / 0.1L air: %u\n", data.particles_10um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 67 | printf("Particles > 2.5um / 0.1L air: %u\n", data.particles_25um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 68 | printf("Particles > 5.0um / 0.1L air: %u\n", data.particles_50um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 69 | printf("Particles > 10.0 um / 0.1L air: %u\n", data.particles_100um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 70 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 71 | } |
sebastianrestrepo | 0:d5dc1e5564a5 | 72 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 73 | /****************************************************************************** |
sebastianrestrepo | 1:5bc605d2b8f8 | 74 | * Main |
sebastianrestrepo | 1:5bc605d2b8f8 | 75 | *****************************************************************************/ |
sebastianrestrepo | 1:5bc605d2b8f8 | 76 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 77 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 78 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 79 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 80 | int main() { |
sebastianrestrepo | 0:d5dc1e5564a5 | 81 | //printf("Bienvenido"); |
sebastianrestrepo | 1:5bc605d2b8f8 | 82 | log("init tft \r\n"); |
sebastianrestrepo | 2:e80f510b3cb2 | 83 | tft.init(); |
sebastianrestrepo | 2:e80f510b3cb2 | 84 | |
sebastianrestrepo | 2:e80f510b3cb2 | 85 | // uint16_t x = 0; |
sebastianrestrepo | 2:e80f510b3cb2 | 86 | // uint16_t y = 0; |
sebastianrestrepo | 2:e80f510b3cb2 | 87 | uint16_t w = tft.width(); |
sebastianrestrepo | 2:e80f510b3cb2 | 88 | uint16_t h = tft.height(); |
sebastianrestrepo | 1:5bc605d2b8f8 | 89 | |
sebastianrestrepo | 2:e80f510b3cb2 | 90 | // bool down = false; |
sebastianrestrepo | 2:e80f510b3cb2 | 91 | // bool lastDown = false; |
sebastianrestrepo | 2:e80f510b3cb2 | 92 | tft.setTextColor(0xFFFF,0xF81F); |
sebastianrestrepo | 2:e80f510b3cb2 | 93 | tft.drawString(35, 30, "Cantidad de particulas : "); |
sebastianrestrepo | 2:e80f510b3cb2 | 94 | //tft.drawString(70, 100, "Pm 2.5: "); |
sebastianrestrepo | 2:e80f510b3cb2 | 95 | tft.drawString(70, 150, "Pm 1.0: "); |
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 | } |