![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Código sensor para material particulado con PMS 5003
main.cpp@1:5bc605d2b8f8, 2021-10-28 (annotated)
- Committer:
- sebastianrestrepo
- Date:
- Thu Oct 28 21:55:43 2021 +0000
- Revision:
- 1:5bc605d2b8f8
- Parent:
- 0:d5dc1e5564a5
- Child:
- 2:e80f510b3cb2
Programa Sensor Pantalla Funcional
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 | 1:5bc605d2b8f8 | 43 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 44 | /****************************************************************************** |
sebastianrestrepo | 1:5bc605d2b8f8 | 45 | * Local functions |
sebastianrestrepo | 1:5bc605d2b8f8 | 46 | *****************************************************************************/ |
sebastianrestrepo | 0:d5dc1e5564a5 | 47 | static EventQueue queue; // The callback from the driver is triggered from IRQ, use EventQueue to debounce to normal context |
sebastianrestrepo | 0:d5dc1e5564a5 | 48 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 49 | void pm25_data_callback(pms5003_data_t data) { |
sebastianrestrepo | 0:d5dc1e5564a5 | 50 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 51 | printf("Concentration Units (standard)\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 52 | printf("PM 1.0: %u", data.pm10_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 53 | printf("\t\tPM 2.5: %u", data.pm25_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 54 | printf("\t\tPM 10: %u\n", data.pm100_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 55 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 56 | printf("Concentration Units (environmental)\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 57 | printf("PM 1.0: %u", data.pm10_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 58 | printf("\t\tPM 2.5: %u", data.pm25_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 59 | printf("\t\tPM 10: %u\n", data.pm100_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 60 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 61 | printf("Particles > 0.3um / 0.1L air: %u\n", data.particles_03um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 62 | printf("Particles > 0.5um / 0.1L air: %u\n", data.particles_05um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 63 | printf("Particles > 1.0um / 0.1L air: %u\n", data.particles_10um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 64 | printf("Particles > 2.5um / 0.1L air: %u\n", data.particles_25um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 65 | printf("Particles > 5.0um / 0.1L air: %u\n", data.particles_50um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 66 | printf("Particles > 10.0 um / 0.1L air: %u\n", data.particles_100um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 67 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 68 | } |
sebastianrestrepo | 0:d5dc1e5564a5 | 69 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 70 | /****************************************************************************** |
sebastianrestrepo | 1:5bc605d2b8f8 | 71 | * Main |
sebastianrestrepo | 1:5bc605d2b8f8 | 72 | *****************************************************************************/ |
sebastianrestrepo | 1:5bc605d2b8f8 | 73 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 74 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 75 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 76 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 77 | int main() { |
sebastianrestrepo | 0:d5dc1e5564a5 | 78 | //printf("Bienvenido"); |
sebastianrestrepo | 1:5bc605d2b8f8 | 79 | log("init tft \r\n"); |
sebastianrestrepo | 1:5bc605d2b8f8 | 80 | tft.init(); |
sebastianrestrepo | 1:5bc605d2b8f8 | 81 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 82 | // uint16_t x = 0; |
sebastianrestrepo | 1:5bc605d2b8f8 | 83 | // uint16_t y = 0; |
sebastianrestrepo | 1:5bc605d2b8f8 | 84 | uint16_t w = tft.width(); |
sebastianrestrepo | 1:5bc605d2b8f8 | 85 | uint16_t h = tft.height(); |
sebastianrestrepo | 1:5bc605d2b8f8 | 86 | |
sebastianrestrepo | 1:5bc605d2b8f8 | 87 | // bool down = false; |
sebastianrestrepo | 1:5bc605d2b8f8 | 88 | // bool lastDown = false; |
sebastianrestrepo | 1:5bc605d2b8f8 | 89 | tft.setTextColor(0xFFFF,0xF81F); |
sebastianrestrepo | 1:5bc605d2b8f8 | 90 | tft.drawString(35, 30, "Cantidad de particulas :( "); |
sebastianrestrepo | 1:5bc605d2b8f8 | 91 | tft.drawString(70, 100, "Pm 2.5: "); |
sebastianrestrepo | 1:5bc605d2b8f8 | 92 | tft.drawString(70, 150, "Pm 1.0: "); |
sebastianrestrepo | 0:d5dc1e5564a5 | 93 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 94 | // This callback runs in an interrupt context, thus we debounce to the event queue here |
sebastianrestrepo | 0:d5dc1e5564a5 | 95 | pm25.enable(queue.event(&pm25_data_callback)); |
sebastianrestrepo | 0:d5dc1e5564a5 | 96 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 97 | queue.dispatch_forever(); |
sebastianrestrepo | 0:d5dc1e5564a5 | 98 | } |