mirror of
https://github.com/rzajac/esp-drv.git
synced 2025-06-07 14:20:15 +03:00
Update documentation and fix small issues.
This commit is contained in:
parent
45ab6f8e61
commit
931aee878b
@ -31,19 +31,22 @@ $ make install
|
||||
|
||||
## Examples.
|
||||
|
||||
- [DHT22 get temperature and humidity](examples/dht22_temp_hum)
|
||||
- [DHT22 get temperature and humidity](examples/dht22)
|
||||
- [DS18B20 get temperature](examples/ds18b20_temp)
|
||||
- [Search for DS18B20](examples/ds18b20_search)
|
||||
- [SHT21 get temperature and humidity](examples/sht21)
|
||||
|
||||
# Dependencies.
|
||||
|
||||
This library depends on:
|
||||
|
||||
- https://github.com/rzajac/esp-ecl
|
||||
- https://github.com/rzajac/esp-prot
|
||||
|
||||
to install dependency run:
|
||||
|
||||
```
|
||||
$ wget -O - https://raw.githubusercontent.com/rzajac/esp-ecl/master/install.sh | bash
|
||||
$ wget -O - https://raw.githubusercontent.com/rzajac/esp-prot/master/install.sh | bash
|
||||
```
|
||||
|
||||
|
@ -15,5 +15,5 @@
|
||||
|
||||
add_subdirectory(ds18b20_search)
|
||||
add_subdirectory(ds18b20_temp)
|
||||
add_subdirectory(dht22_temp_hum)
|
||||
add_subdirectory(sht21_example)
|
||||
add_subdirectory(dht22)
|
||||
add_subdirectory(sht21)
|
||||
|
@ -16,16 +16,16 @@
|
||||
find_package(esp_sdo REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(dht22_temp_hum main.c ${ESP_USER_CONFIG})
|
||||
add_executable(dht22_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(dht22_temp_hum PUBLIC
|
||||
target_include_directories(dht22_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(dht22_temp_hum
|
||||
target_link_libraries(dht22_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_dht22)
|
||||
|
||||
esp_gen_exec_targets(dht22_temp_hum)
|
||||
esp_gen_exec_targets(dht22_ex)
|
@ -7,6 +7,6 @@ Demonstrates how to get temperature and humidity from DHT22 sensor.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make dht22_temp_hum_flash
|
||||
$ make dht22_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
@ -14,67 +14,16 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <user_interface.h>
|
||||
|
||||
#include <esp_gpio.h>
|
||||
#include <esp_dht22.h>
|
||||
#include <mem.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
#include <mem.h>
|
||||
|
||||
os_timer_t timer;
|
||||
|
||||
/**
|
||||
* Rise base to power of.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* @param base The number.
|
||||
* @param exp The exponent.
|
||||
*
|
||||
* @return Product.
|
||||
*/
|
||||
static int ICACHE_FLASH_ATTR
|
||||
power(int base, int exp)
|
||||
{
|
||||
int result = 1;
|
||||
while (exp) {
|
||||
result *= base;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string representation of float.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* Warning: limited to 15 chars & non-reentrant.
|
||||
* e.g., don't use more than once per os_printf call.
|
||||
*
|
||||
* @param num The float to convert to string.
|
||||
* @param decimals The number of decimal places.
|
||||
*
|
||||
* @return The float string representation.
|
||||
*/
|
||||
static char *ICACHE_FLASH_ATTR
|
||||
ftoa(float num, uint8_t decimals)
|
||||
{
|
||||
static char *buf[16];
|
||||
|
||||
int whole = (int) num;
|
||||
int decimal = (int) ((num - whole) * power(10, decimals));
|
||||
if (decimal < 0) {
|
||||
// get rid of sign on decimal portion
|
||||
decimal -= 2 * decimal;
|
||||
}
|
||||
|
||||
char *pattern[10]; // setup printf pattern for decimal portion
|
||||
os_sprintf((char *) pattern, "%%d.%%0%dd", decimals);
|
||||
os_sprintf((char *) buf, (const char *) pattern, whole, decimal);
|
||||
|
||||
return (char *) buf;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
sys_init_done(void* arg)
|
||||
@ -90,8 +39,8 @@ sys_init_done(void* arg)
|
||||
return;
|
||||
}
|
||||
|
||||
os_printf("Temp: %s\n", ftoa(dev->temp, 2));
|
||||
os_printf("Hum: %s\n", ftoa(dev->hum, 2));
|
||||
os_printf("Temp: %s\n", esp_util_ftoa(dev->temp, 3));
|
||||
os_printf("Hum: %s\n", esp_util_ftoa(dev->hum, 3));
|
||||
os_printf("--------------------\n");
|
||||
os_free(dev);
|
||||
}
|
@ -18,20 +18,20 @@ find_package(esp_ow REQUIRED)
|
||||
find_package(esp_eb REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(ds18b20_search main.c ${ESP_USER_CONFIG})
|
||||
add_executable(ds18b20_search_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(ds18b20_search PUBLIC
|
||||
target_include_directories(ds18b20_search_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_ow_INCLUDE_DIRS}
|
||||
${esp_eb_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(ds18b20_search
|
||||
target_link_libraries(ds18b20_search_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_ow_LIBRARIES}
|
||||
${esp_eb_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_ds18b20)
|
||||
|
||||
esp_gen_exec_targets(ds18b20_search)
|
||||
esp_gen_exec_targets(ds18b20_search_ex)
|
||||
|
@ -7,6 +7,6 @@ Demonstrates how to search OneWire bus for DS18b20.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make ds18b20_search_flash
|
||||
$ make ds18b20_search_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
||||
|
@ -18,20 +18,20 @@ find_package(esp_ow REQUIRED)
|
||||
find_package(esp_eb REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(ds18b20_temp main.c ${ESP_USER_CONFIG})
|
||||
add_executable(ds18b20_temp_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(ds18b20_temp PUBLIC
|
||||
target_include_directories(ds18b20_temp_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_ow_INCLUDE_DIRS}
|
||||
${esp_eb_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(ds18b20_temp
|
||||
target_link_libraries(ds18b20_temp_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_ow_LIBRARIES}
|
||||
${esp_eb_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_ds18b20)
|
||||
|
||||
esp_gen_exec_targets(ds18b20_temp)
|
||||
esp_gen_exec_targets(ds18b20_temp_ex)
|
||||
|
@ -7,6 +7,6 @@ Demonstrates how to search OneWire bus for DS18b20.
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make ds18b20_temp_flash
|
||||
$ make ds18b20_temp_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
||||
|
@ -15,13 +15,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
#include <esp_ds18b20.h>
|
||||
#include <esp_gpio.h>
|
||||
#include <esp_eb.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
|
||||
// List of found devices on the OneWire bus.
|
||||
static esp_ow_device *root = NULL;
|
||||
|
@ -17,18 +17,18 @@ find_package(esp_sdo REQUIRED)
|
||||
find_package(esp_i2c REQUIRED)
|
||||
find_package(esp_util REQUIRED)
|
||||
|
||||
add_executable(sht21_example main.c ${ESP_USER_CONFIG})
|
||||
add_executable(sht21_ex main.c ${ESP_USER_CONFIG})
|
||||
|
||||
target_include_directories(sht21_example PUBLIC
|
||||
target_include_directories(sht21_ex PUBLIC
|
||||
${ESP_USER_CONFIG_DIR}
|
||||
${esp_sdo_INCLUDE_DIRS}
|
||||
${esp_i2c_INCLUDE_DIRS}
|
||||
${esp_util_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(sht21_example
|
||||
target_link_libraries(sht21_ex
|
||||
${esp_sdo_LIBRARIES}
|
||||
${esp_i2c_LIBRARIES}
|
||||
${esp_util_LIBRARIES}
|
||||
esp_sht21)
|
||||
|
||||
esp_gen_exec_targets(sht21_example)
|
||||
esp_gen_exec_targets(sht21_ex)
|
@ -10,6 +10,6 @@ Demonstrates how to:
|
||||
```
|
||||
$ cd build
|
||||
$ cmake ..
|
||||
$ make sht21_example_flash
|
||||
$ make sht21_ex_flash
|
||||
$ miniterm.py /dev/ttyUSB0 74880
|
||||
```
|
@ -14,70 +14,17 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <esp_sht21.h>
|
||||
#include <esp_sdo.h>
|
||||
#include <esp_util.h>
|
||||
#include <user_interface.h>
|
||||
#include <osapi.h>
|
||||
|
||||
#define SCL GPIO0
|
||||
#define SDA GPIO2
|
||||
|
||||
os_timer_t timer;
|
||||
|
||||
/**
|
||||
* Rise base to power of.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* @param base The number.
|
||||
* @param exp The exponent.
|
||||
*
|
||||
* @return Product.
|
||||
*/
|
||||
static int ICACHE_FLASH_ATTR
|
||||
power(int base, int exp)
|
||||
{
|
||||
int result = 1;
|
||||
while (exp) {
|
||||
result *= base;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string representation of float.
|
||||
*
|
||||
* From: http://bbs.espressif.com/viewtopic.php?t=246
|
||||
*
|
||||
* Warning: limited to 15 chars & non-reentrant.
|
||||
* e.g., don't use more than once per os_printf call.
|
||||
*
|
||||
* @param num The float to convert to string.
|
||||
* @param decimals The number of decimal places.
|
||||
*
|
||||
* @return The float string representation.
|
||||
*/
|
||||
static char *ICACHE_FLASH_ATTR
|
||||
ftoa(float num, uint8_t decimals)
|
||||
{
|
||||
static char *buf[16];
|
||||
|
||||
int whole = (int) num;
|
||||
int decimal = (int) ((num - whole) * power(10, decimals));
|
||||
if (decimal < 0) {
|
||||
// get rid of sign on decimal portion
|
||||
decimal -= 2 * decimal;
|
||||
}
|
||||
|
||||
char *pattern[10]; // setup printf pattern for decimal portion
|
||||
os_sprintf((char *) pattern, "%%d.%%0%dd", decimals);
|
||||
os_sprintf((char *) buf, (const char *) pattern, whole, decimal);
|
||||
|
||||
return (char *) buf;
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
||||
run_sht21()
|
||||
{
|
||||
@ -107,12 +54,12 @@ run_sht21()
|
||||
err = esp_sht21_get_rh(&value);
|
||||
if (err != ESP_I2C_OK) os_printf("Get RH error: %d\n", err);
|
||||
|
||||
os_printf("Humidity: %s%%\n", ftoa(value, 2));
|
||||
os_printf("Humidity: %s%%\n", esp_util_ftoa(value, 2));
|
||||
|
||||
err = esp_sht21_get_temp_last(&value);
|
||||
if (err != ESP_I2C_OK) os_printf("Get TEMP error: %d\n", err);
|
||||
|
||||
os_printf("Temperature: %s deg. C\n", ftoa(value, 2));
|
||||
os_printf("Temperature: %s deg. C\n", esp_util_ftoa(value, 2));
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR
|
@ -8,6 +8,5 @@ Before you can get the temperature and humidity from DHT22 you have to call
|
||||
`esp_dht22_init`. You need to call it only once unless you change the GPIO
|
||||
pin setup somewhere else in your code.
|
||||
|
||||
|
||||
See driver documentation in [esp_dht22.h](include/esp_dht22.h) header file
|
||||
for more details.
|
||||
See [example program](../../examples/dht22) and driver documentation
|
||||
in [esp_dht22.h](include/esp_dht22.h) header file for more details.
|
||||
|
@ -14,16 +14,17 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <esp_dht22.h>
|
||||
#include <esp_gpio.h>
|
||||
#include <mem.h>
|
||||
#include <user_interface.h>
|
||||
|
||||
#define BUS_LOW(gpio_num) (GPIO_OUT_EN_S = (0x1 << (gpio_num)))
|
||||
#define BUS_HIGH(gpio_num) (GPIO_OUT_EN_C = (0x1 << (gpio_num)))
|
||||
#define BUS_RELEASE(gpio_num) (GPIO_OUT_EN_C = (0x1 << (gpio_num)))
|
||||
#define BUS_READ(gpio_num) ((GPIO_IN & (0x1 << (gpio_num))) != 0)
|
||||
|
||||
|
||||
/**
|
||||
* Measure number of 10us slots the state was kept.
|
||||
*
|
||||
|
@ -14,6 +14,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ESP_DHT22_H
|
||||
#define ESP_DHT22_H
|
||||
|
||||
@ -40,6 +41,7 @@ typedef enum {
|
||||
void ets_isr_mask(unsigned intr);
|
||||
void ets_isr_unmask(unsigned intr);
|
||||
|
||||
|
||||
/**
|
||||
* Initialize DHT22.
|
||||
*
|
||||
|
@ -18,7 +18,7 @@ anymore.
|
||||
Most of the operations with the DS18B20 library is based on passing pointers
|
||||
to the `esp_ow_device` structure which has pointer to `esp_ds18b20_st`
|
||||
status structure. The `esp_ds18b20_st` keeps track of last scratch pad read
|
||||
the last temperature conversion.
|
||||
and last temperature conversion.
|
||||
|
||||
```
|
||||
esp_ow_device *device;
|
||||
@ -34,12 +34,11 @@ esp_ow_dev *device = esp_ds18b20_new_dev(rom);
|
||||
|
||||
```
|
||||
|
||||
With DS18B20 temperature measurement takes between 94 and 750ms depending
|
||||
on resolution. You don't want to block the CPU for that long waiting for
|
||||
example using some kind of delay. That's why library is using event bus
|
||||
(esp_eb) to emmit events when the temperature conversion is ready to read.
|
||||
Check [example program](../../examples/ds18b20_temp) to see how it should be
|
||||
done.
|
||||
Temperature measurement with DS18B20 takes between 94 and 750ms depending
|
||||
on resolution. You don't want to block the CPU for that long using some kind
|
||||
of delay. That's why library is using event bus (esp_eb) to emmit events when
|
||||
the temperature conversion is ready.
|
||||
|
||||
See driver documentation in [esp_ds18b20.h](include/esp_ds18b20.h) header file
|
||||
for more details.
|
||||
Check [example program](../../examples/ds18b20_temp) to see how it should be
|
||||
done and driver documentation in [esp_ds18b20.h](include/esp_ds18b20.h)
|
||||
header file for more details.
|
||||
|
@ -217,10 +217,15 @@ esp_ds18b20_search(uint8_t gpio_num, bool in_alert, esp_ow_device **list)
|
||||
esp_ow_device *ICACHE_FLASH_ATTR
|
||||
esp_ds18b20_new_dev(uint8_t *rom)
|
||||
{
|
||||
esp_ow_device *device = os_zalloc(sizeof(esp_ow_device));
|
||||
esp_ds18b20_st *st = os_zalloc(sizeof(esp_ds18b20_st));
|
||||
esp_ow_device *device = esp_ow_new_dev(rom);
|
||||
if (device == NULL) return NULL;
|
||||
|
||||
esp_ds18b20_st *st = os_zalloc(sizeof(esp_ds18b20_st));
|
||||
if (st == NULL) {
|
||||
os_free(device);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
os_memcpy(device->rom, rom, 8);
|
||||
st->last_temp = ESP_DS18B20_TEMP_ERR;
|
||||
st->retries = -1;
|
||||
device->custom = st;
|
||||
@ -228,7 +233,6 @@ esp_ds18b20_new_dev(uint8_t *rom)
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
esp_ow_device *ICACHE_FLASH_ATTR
|
||||
esp_ds18b20_get(uint8_t gpio_num)
|
||||
{
|
||||
|
@ -95,7 +95,7 @@ esp_ds18b20_search(uint8_t gpio_num, bool in_alert, esp_ow_device **list);
|
||||
*
|
||||
* @param rom The pointer to 8 byte ROM address
|
||||
*
|
||||
* @return The device.
|
||||
* @return The device or NULL on error.
|
||||
*/
|
||||
esp_ow_device *ICACHE_FLASH_ATTR
|
||||
esp_ds18b20_new_dev(uint8_t *rom);
|
||||
|
@ -29,5 +29,4 @@ target_include_directories(esp_sht21 PUBLIC
|
||||
|
||||
esp_gen_lib(esp_sht21
|
||||
${ESP_CMAKE_FIND_DIR}
|
||||
${esp_i2c_LIBRARIES}
|
||||
${esp_tim_LIBRARIES})
|
||||
${esp_i2c_LIBRARIES})
|
||||
|
@ -14,5 +14,5 @@ Before you can start communicating with SHT21 you have to call
|
||||
`esp_sht21_init`. You need to call it only once unless you change the GPIO
|
||||
pins setup somewhere else in your code.
|
||||
|
||||
See driver documentation in [esp_sht21.h](include/esp_sht21.h) header file
|
||||
for more details.
|
||||
See [example program](../../examples/sht21) and driver documentation in
|
||||
[esp_sht21.h](include/esp_sht21.h) header file for more details.
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
|
||||
#include <esp_sht21.h>
|
||||
#include <osapi.h>
|
||||
|
||||
static uint8_t ICACHE_FLASH_ATTR
|
||||
calc_crc(uint8_t init, const uint8_t *data, uint8_t len)
|
||||
|
@ -18,8 +18,8 @@
|
||||
#ifndef ESP_SHT21_H
|
||||
#define ESP_SHT21_H
|
||||
|
||||
#include <c_types.h>
|
||||
#include <esp_i2c.h>
|
||||
#include <c_types.h>
|
||||
|
||||
#define ESP_SHT21_ADDRESS 0x40
|
||||
// Measure relative humidity. Hold Master Mode.
|
||||
@ -56,6 +56,7 @@
|
||||
// RH: 11bit TEMP: 11bit
|
||||
#define ESP_SHT21_RES0 0x3
|
||||
|
||||
|
||||
/**
|
||||
* Initialize SHT21.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user