ESP32 – Check temperature with DS18B20

One of my goals when playing with these chips is to enhance elements of smart home. One of features is measurement of home parameters including temperature. Earlier I have integrated it with Fibaro sensor, now I’ll check it with ESP32 and DS18B20.

Application setup

First step is to get empty project as described here and rename it to temperature for example. Update Makefile, set serial port and remove main.c file.

Now we need to add support for DS18B20. On GitHub there is already component which handles it but it will require minor update to compile seamlessly. Each project may contain several components organized in components subdirectory. Components are simply pieces of code which are compiled into static library and then linked into our application. Some of them are available in ESP-IDF but we can create also ours. For purpose of handling DS18B20 I used component from FeelFreeLinux, there are 2 small changes which must be applied.

cd components
git clone --recursive
cd ds18b20
mkdir include
mv ds18b20.h include

Read More

ESP32 – Hello world reinvented

In previous post I have described Hello World example coming from ESP_IDF environment. Now let’s build Hello World from the scratch.

Template application

First of all let’s grab template application. It is available on GitHub under espressif project.

cd ~/esp
git clone --recursive

Rename esp-idf-template directory to hello_world2.

mv esp-idf-template hello_world2
cd hello_world2

Edit Makefile and change value of PROJECT_NAME variable to hello_world2.

Main files of the projects are located in main directory, additional components will be located in components by default. So let’s got to main and remove source file main.c. This file contains example how to connect to wireless network and will be interesting in future. Create the easiest existing example hello_world2.c as below. Name of the file does not matter but one of source files must contain void app_main(void) function:

#include <stdio.h>

void app_main(void)
  printf("Hello world\n");

Remember to run make menuconfig to set serial flasher connection and then flash and monitor. At the end of the results you will see something like:

mode:DIO, clock div:2
ho 0 tail 12 room 4
0x40080000: _iram_start at ??:?
entry 0x40080034
0x40080034: _iram_start at ??:?
Hello world

It works. Now as general rule tasks should be created in form of endless loop and this peace of code hasn’t got loop. But task can delete themselves when finished. But where this task from app_main is deleted? When you quickly look into cpu_start.c file from esp-idf/components/esp32 folder you will see that right after app_main ends the task is deleted:

static void main_task(void* args)
    // Now that the application is about to start, disable boot watchdogs
    //Enable allocation in region where the startup stacks were located.