Giter Site home page Giter Site logo

ebiroll / esp32_weather Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 2.0 1.67 MB

Collect data from bosh/sparkfun BME280 i2c and internal temperature sensor. Send data to thingspeak.com and go back to sleep.

License: MIT License

Makefile 0.54% C 93.60% GDB 5.30% CMake 0.55%

esp32_weather's Introduction

esp32_weather

Collect data from bosh/sparkfun BME280 & Si7021 over i2c and the internal esp32 temperature sensor. Send data to thingspeak.com and go back to sleep.

Here are the reuslts. https://thingspeak.com/channels/209116 https://thingspeak.com/channels/212260 For the first dataseries I opened the window, closed the window, used a hair-drier and then just let is sit with the window closed. For the second channel I put the esp32 in a box that I placed outside.

I also solved the problem with bootcount being lost during sleep.

    esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);

That statement was missing in the 06_sntp example. Now I will let the board run on a 7800mAh battery and continue to update this thingspeak channel https://thingspeak.com/channels/212260 I also added pressure to this feed. As measurements indoors wasnt so exciting I moved the data collection outside.

For temperature measurements, I used the adafruit si7021 temperature humidity board & Sparkfun BME280 board.

https://cdn-learn.adafruit.com/assets/assets/000/035/931/original/Support_Documents_TechnicalDocs_Si7021-A20.pdf Both are i2c boards, here is the output when running.screenlog The esp32 will wakeup every 6 seconds and check the boot_count. This is done as otherwise the battery will switch off. Every minute wifi will be started and the collected data will be logged on http://thingspeak.com

#i2c_init Before the modules can be used, this must be called.

/**
 * @brief i2c master initialization
 */
void i2c_init()
{
    int i2c_master_port = I2C_MASTER_NUM;
    i2c_config_t conf;
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = I2C_MASTER_SDA_IO;
    conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
    conf.scl_io_num = I2C_MASTER_SCL_IO;
    conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
    conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
    i2c_param_config(i2c_master_port, &conf);
    i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}

#i2c_scan Simple but useful to see the assigned adresses of the i2c devices.

/**
 * _____________________________
 * | start | slave_addr  + sack | 
 * --------|--------------------|
 *
 */
esp_err_t i2c_master_check_slave(i2c_port_t i2c_num,uint8_t addr)
{
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, ( addr << 1 ) , ACK_CHECK_EN);
    i2c_master_stop(cmd);
    esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000 / portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
    return ret;
}

void i2c_scan() {
    int address;
    int ret;
    int foundCount = 0;
    for (address=1; address<127; address++) {
        ret=i2c_master_check_slave(I2C_MASTER_NUM,address);
        if (ret == ESP_OK) {
            printf("Found device addres: %02x\n", address);
           foundCount++;
        }
    }
    printf("Done scanning.. found %d devices\n",foundCount);
}

#The si7021 board https://cdn-learn.adafruit.com/downloads/pdf/adafruit-si7021-temperature-plus-humidity-sensor.pdf Future enhancements could be to add heating function to enhance humidity sensing.

    i7021.humidity=i2c_7021_read_rh();
    i7021.temp=i2c_7021_read_temp();

#The BME280 weather data board https://github.com/sparkfun/SparkFun_BME280_Arduino_Library https://github.com/BoschSensortec/BME280_driver To save battery, we use this sensor in forced mode. i2c_bme280_begin(); puts the sensor in normal run mode. After calling i2c_bme280_force_readings(); the sensor does one measurement and then goes back to sleep mode. (0)

    i2c_bme280_begin();
    i2c_bme280_force_readings();
    bme280.temp=i2c_bme280_read_temp();
    pressure=i2c_bme280_read_pressure();
    bme280.humidity=i2c_bme280_read_rh();
    printf("RH %d Temp %d , pressure %f\n",bme280.humidity,bme280.temp,pressure/100.0);
    printf("power mode %x\n",i2c_bme280_get_power_mode());

Running all day box and night night

esp32_weather's People

Contributors

ebiroll avatar sunnet-si avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

liqin123 xtile

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.