Giter Site home page Giter Site logo

idf-pms5003's Introduction

idf-pms5003

Esp idf driver for pmsX003 sensor. This library can be used with multiple sensors at the same time. For each sensor you can choose between one shot or periodic data read.

Build

This component is compatible with esp-idf v3.x.x and v5.x.x It was not tested non esp-idf v4.x.x

Checkout the desired TAG

Configuration

Use idf.py menuconfig to configure RX_PIN, TX_PIN and SET_PIN of the sensor conected to your esp board.

How to use

static void pms_callback(pm_data_t *sensor_data) {
    ESP_LOGI(TAG, "pm10: %d ug/m3", sensor_data->pm10);
    ESP_LOGI(TAG, "pm2.5: %d ug/m3", sensor_data->pm2_5);
    ESP_LOGI(TAG, "pm1.0: %d ug/m3", sensor_data->pm1_0);
    ESP_LOGI(TAG, "particles > 0.3um / 0.1L: %d", sensor_data->particles_03um);
    ESP_LOGI(TAG, "particles > 0.5um / 0.1L: %d", sensor_data->particles_05um);
    ESP_LOGI(TAG, "particles > 1.0um / 0.1L: %d", sensor_data->particles_10um);
    ESP_LOGI(TAG, "particles > 2.5um / 0.1L: %d", sensor_data->particles_25um);
    ESP_LOGI(TAG, "particles > 5.0um / 0.1L: %d", sensor_data->particles_50um);
    ESP_LOGI(TAG, "particles > 10.0um / 0.1L: %d", sensor_data->particles_100um);
}


pmsx003_config_t pms_conf = {
    .sensor_id = 1,
    .uart_port = UART_NUM_2,
    .indoor = false,
    .enabled = true,
    .periodic = true,
    .periodic_sec_interval = 300, // every five minutes
    .callback = &pms_callback,
    .set_pin = CONFIG_SET_GPIO,
    .reset_pin = CONFIG_RESET_GPIO,
    .uart_tx_pin = CONFIG_TX_GPIO,
    .uart_rx_pin = CONFIG_RX_GPIO,
};

void app_main(void) {
    idf_pmsx5003_init(&pms_conf);
}

About the pmsx003_config_t config structure:

  • sensor_id: returned in the callback to identify the sensor that generated the data.
  • indoor: the sensor supports both indoor and outdoor data read.
  • enabled: when set to true the sensor data will be read.
  • periodic: true for periodic read. If set to false the sensor data will be read one time only.
  • periodic_sec_interval: defines how often the sensor will be read in seconds. Min value is 35 (the sensor needs 30 seconds to return reliable results).

idf-pms5003's People

Contributors

pgatti86 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.