init pms5003 lib
This commit is contained in:
parent
98748d3e6d
commit
f2638dddce
4 changed files with 77 additions and 8 deletions
|
|
@ -19,7 +19,7 @@ pico_sdk_init()
|
||||||
|
|
||||||
|
|
||||||
# the executable
|
# the executable
|
||||||
add_executable( node1 node1.c bme280.c )
|
add_executable( node1 node1.c bme280.c pms5003.c )
|
||||||
pico_set_program_version(node1 "0.1")
|
pico_set_program_version(node1 "0.1")
|
||||||
pico_set_program_name(node1 "node_one")
|
pico_set_program_name(node1 "node_one")
|
||||||
|
|
||||||
|
|
|
||||||
30
node1.c
30
node1.c
|
|
@ -1,21 +1,37 @@
|
||||||
|
#include <hardware/uart.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <hardware/i2c.h>
|
#include <hardware/i2c.h>
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "bme280.h"
|
#include "bme280.h"
|
||||||
|
#include "pms5003.h"
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
stdio_init_all();
|
stdio_init_all();
|
||||||
|
|
||||||
|
// Setup BME280
|
||||||
bme280_config config;
|
bme280_config config;
|
||||||
bme280_init(&config, i2c1, 14, 15);
|
bme280_init(&config, i2c1, 14, 15);
|
||||||
bme280_reading current_reading;
|
bme280_reading current_bem280_reading;
|
||||||
|
|
||||||
|
// Setup PMS5003
|
||||||
|
pms5003_config pms_config;
|
||||||
|
pms5003_init(&pms_config, uart1, 20, 21);
|
||||||
|
pms5003_reading current_pms5003_reading;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sleep_ms(5000); // wait 5 sec
|
sleep_ms(5000); // wait 5 sec
|
||||||
printf("Making reading\n");
|
printf("Making reading\n");
|
||||||
current_reading = bme280_read(&config);
|
|
||||||
printf("Tempature: %.2f\n", current_reading.temperature);
|
// Read BME280
|
||||||
printf("Pressure: %.2f\n", current_reading.pressure);
|
current_bem280_reading = bme280_read(&config);
|
||||||
printf("Humidity: %.2f\n", current_reading.humidity);
|
printf("Tempature: %.2f\n", current_bem280_reading.temperature);
|
||||||
|
printf("Pressure: %.2f\n", current_bem280_reading.pressure);
|
||||||
|
printf("Humidity: %.2f\n", current_bem280_reading.humidity);
|
||||||
|
|
||||||
|
// Read PMS5003
|
||||||
|
current_pms5003_reading = pms5003_read(&pms_config);
|
||||||
|
printf("PM1: %.2f\n", current_pms5003_reading.pm1);
|
||||||
|
printf("PM2.5: %.2f\n", current_pms5003_reading.pm2_5);
|
||||||
|
printf("PM10: %.2f\n", current_pms5003_reading.pm10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
33
pms5003.c
Normal file
33
pms5003.c
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#include "pms5003.h"
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
#include "pico/stdlib.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Lib for Plantower PMS5003 Particulate Matter (PM) Sensor
|
||||||
|
|
||||||
|
Detects PM1, PM2.5, PM10 particulates
|
||||||
|
|
||||||
|
Sourcces:
|
||||||
|
-
|
||||||
|
https://shop.pimoroni.com/products/pms5003-particulate-matter-sensor-with-cable
|
||||||
|
- https://github.com/pimoroni/pms5003-python/blob/main/pms5003/__init__.py
|
||||||
|
- https://github.com/vogelrh/pms5003c/tree/master
|
||||||
|
*/
|
||||||
|
|
||||||
|
void pms5003_init(pms5003_config *new_config, uart_inst_t *uart, uint8_t tx_pin,
|
||||||
|
uint8_t rx_pin) {
|
||||||
|
uart_init(uart, 9600);
|
||||||
|
gpio_set_function(tx_pin, UART_FUNCSEL_NUM(uart, tx_pin));
|
||||||
|
gpio_set_function(rx_pin, UART_FUNCSEL_NUM(uart, rx_pin));
|
||||||
|
new_config->uart = uart;
|
||||||
|
}
|
||||||
|
|
||||||
|
pms5003_reading pms5003_read(pms5003_config *config) {
|
||||||
|
pms5003_reading reading;
|
||||||
|
reading.pm1 = 0;
|
||||||
|
reading.pm2_5 = 0;
|
||||||
|
reading.pm10 = 0;
|
||||||
|
return reading;
|
||||||
|
}
|
||||||
20
pms5003.h
Normal file
20
pms5003.h
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef PMS5003_H
|
||||||
|
#define PMS5003_H
|
||||||
|
#include "hardware/uart.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float pm1;
|
||||||
|
float pm2_5;
|
||||||
|
float pm10;
|
||||||
|
} pms5003_reading;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uart_inst_t *uart;
|
||||||
|
} pms5003_config;
|
||||||
|
|
||||||
|
void pms5003_init(pms5003_config *config, uart_inst_t *uart, uint8_t tx_pin,
|
||||||
|
uint8_t rx_pin);
|
||||||
|
|
||||||
|
pms5003_reading pms5003_read(pms5003_config *config);
|
||||||
|
#endif /* PMS5003_H */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue