-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #413 from pimoroni/patch-pms3005-i2c
PMS5003: Support for i2c version.
- Loading branch information
Showing
4 changed files
with
84 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
set(OUTPUT_NAME pms5003_demo) | ||
add_executable(pms5003_demo pms5003_demo.cpp) | ||
target_link_libraries(pms5003_demo pico_stdlib pms5003) | ||
pico_add_extra_outputs(pms5003_demo) | ||
|
||
add_executable( | ||
${OUTPUT_NAME} | ||
pms5003_demo.cpp | ||
) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(${OUTPUT_NAME} pico_stdlib pms5003) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(${OUTPUT_NAME}) | ||
add_executable(pmsa003i_demo pmsa003i_demo.cpp) | ||
target_link_libraries(pmsa003i_demo pico_stdlib pms5003) | ||
pico_add_extra_outputs(pmsa003i_demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <stdio.h> | ||
#include "pico/stdlib.h" | ||
#include "common/pimoroni_common.hpp" | ||
#include "common/pimoroni_i2c.hpp" | ||
|
||
#include <cstring> | ||
|
||
#include "pms5003.hpp" | ||
|
||
using namespace pimoroni; | ||
|
||
I2C i2c(4, 5, 100000); | ||
PMS5003 pms5003(&i2c, 9, 10); | ||
PMS5003::response_data data; | ||
|
||
int main() { | ||
stdio_init_all(); | ||
|
||
// Enable Enviro power supply! | ||
gpio_init(11); | ||
gpio_set_dir(11, GPIO_OUT); | ||
gpio_put(11, true); | ||
|
||
while(true){ | ||
bool result = pms5003.read(data); | ||
if(result){ | ||
printf("%04x ", data.pm_1_0); // PM1.0 ug/m3 (ultrafine particles) | ||
printf("%04x ", data.pm_2_5); // PM2.5 ug/m3 (combustion particles, organic compounds, metals) | ||
printf("%04x ", data.pm_10); // PM10 ug/m3 (dust, pollen, mould spores) | ||
printf("%04x ", data.pm_1_0_ao); // PM 1.0 under atmospheric environment | ||
printf("%04x ", data.pm_2_5_ao); // PM 2.5 under atmospheric environment | ||
printf("%04x ", data.pm_10_ao); // PM 10 under atmospheric environment | ||
printf("%04x ", data.pm_0_3_1l); // PM 0.3 in 0.1L of air | ||
printf("%04x ", data.pm_0_5_1l); // PM 0.5 in 0.1L of air | ||
printf("%04x ", data.pm_1_0_1l); // PM 1.0 in 0.1L of air | ||
printf("%04x ", data.pm_2_5_1l); // PM 2.5 in 0.1L of air | ||
printf("%04x ", data.pm_5_1l); // PM 5 in 0.1L of air | ||
printf("%04x ", data.pm_10_1l); // PM 10 in 0.1L of air | ||
printf("\n"); | ||
} | ||
sleep_ms(100); | ||
}; | ||
|
||
return 0; | ||
} |