Giter Site home page Giter Site logo

esp32-am2302's Introduction

esp32-am2302

A small library for reading data from the Aosong AM2302 humidity and temperature sensor.

Including this library in your project

If not yet existant, create a components folder in your project root directory:

mkdir components

Then either

  • add this project as a submodule:
git submodule add https://github.com/smartjeff/esp32-am2302.git components/am2302
  • or clone it:
git clone https://github.com/smartjeff/esp32-am2302.git components/am2302

And if you're setting the COMPONENTS variable in your CMakeLists.txt, add it there:

set(COMPONENTS main esptool_py am2302)

Usage Example

app_main.c

#include <stdio.h>
#include "freertos/FreeRTOS.h"      // required for including task.h
#include "freertos/task.h"          // for vTaskDelay()
#include "am2302.h"

#define AM2302_DATA_PIN GPIO_NUM_23 // if your sensors data pin is connected to GPIO 23

void app_main() {
    while(1) {
        // wait one second between the readings
        vTaskDelay(1000 / portTICK_PERIOD_MS);

        // read the sensor data
        am2302_data_t data = am2302_read_data(AM2302_DATA_PIN);

        // check if the data has been receieved successfully
        if(data.error != ESP_OK)
            printf("reading data from am2302 returned an error!\n");

        // print the data
        printf(
            "%02.01f %% RH | %02.01f °C | parity: 0x%02hhx\n",
            (float) data.humidity / 10,
            (float) data.temperature / 10,
            data.parity
        );
    }
}

License

This project is licensed under the GNU General Public License v3.0, see LICENSE.

Special Thanks

We used esp32-websocket as a template for our am2302 component. Thanks to Blake Felt for creating it!

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.