![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Código sensor para material particulado con PMS 5003
main.cpp@0:d5dc1e5564a5, 2021-10-28 (annotated)
- Committer:
- sebastianrestrepo
- Date:
- Thu Oct 28 21:22:35 2021 +0000
- Revision:
- 0:d5dc1e5564a5
- Child:
- 1:5bc605d2b8f8
Programa 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 | 0:d5dc1e5564a5 | 3 | PMS5003 pm25(D1, D0, D3); // UART TX, UART RX, POWER |
sebastianrestrepo | 0:d5dc1e5564a5 | 4 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 5 | static EventQueue queue; // The callback from the driver is triggered from IRQ, use EventQueue to debounce to normal context |
sebastianrestrepo | 0:d5dc1e5564a5 | 6 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 7 | void pm25_data_callback(pms5003_data_t data) { |
sebastianrestrepo | 0:d5dc1e5564a5 | 8 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 9 | printf("Concentration Units (standard)\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 10 | printf("PM 1.0: %u", data.pm10_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 11 | printf("\t\tPM 2.5: %u", data.pm25_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 12 | printf("\t\tPM 10: %u\n", data.pm100_standard); |
sebastianrestrepo | 0:d5dc1e5564a5 | 13 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 14 | printf("Concentration Units (environmental)\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 15 | printf("PM 1.0: %u", data.pm10_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 16 | printf("\t\tPM 2.5: %u", data.pm25_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 17 | printf("\t\tPM 10: %u\n", data.pm100_env); |
sebastianrestrepo | 0:d5dc1e5564a5 | 18 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 19 | printf("Particles > 0.3um / 0.1L air: %u\n", data.particles_03um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 20 | printf("Particles > 0.5um / 0.1L air: %u\n", data.particles_05um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 21 | printf("Particles > 1.0um / 0.1L air: %u\n", data.particles_10um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 22 | printf("Particles > 2.5um / 0.1L air: %u\n", data.particles_25um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 23 | printf("Particles > 5.0um / 0.1L air: %u\n", data.particles_50um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 24 | printf("Particles > 10.0 um / 0.1L air: %u\n", data.particles_100um); |
sebastianrestrepo | 0:d5dc1e5564a5 | 25 | printf("---------------------------------------\n"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 26 | } |
sebastianrestrepo | 0:d5dc1e5564a5 | 27 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 28 | int main() { |
sebastianrestrepo | 0:d5dc1e5564a5 | 29 | //printf("Bienvenido"); |
sebastianrestrepo | 0:d5dc1e5564a5 | 30 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 31 | // This callback runs in an interrupt context, thus we debounce to the event queue here |
sebastianrestrepo | 0:d5dc1e5564a5 | 32 | pm25.enable(queue.event(&pm25_data_callback)); |
sebastianrestrepo | 0:d5dc1e5564a5 | 33 | |
sebastianrestrepo | 0:d5dc1e5564a5 | 34 | queue.dispatch_forever(); |
sebastianrestrepo | 0:d5dc1e5564a5 | 35 | } |