Add ds18b20 driver and example.
This commit is contained in:
parent
61ba3317e8
commit
1da8626e6e
9 changed files with 868 additions and 0 deletions
3
examples/ds18b20_onewire/Makefile
Normal file
3
examples/ds18b20_onewire/Makefile
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
PROGRAM=ds18b20_onewire
|
||||
EXTRA_COMPONENTS = extras/onewire extras/ds18b20
|
||||
include ../../common.mk
|
||||
51
examples/ds18b20_onewire/ds18b20_onewire.c
Normal file
51
examples/ds18b20_onewire/ds18b20_onewire.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* ds18b20 - Retrieves temperature from ds18b20 sensors and print it out.
|
||||
*
|
||||
* This sample code is in the public domain.,
|
||||
*/
|
||||
#include "espressif/esp_common.h"
|
||||
#include "esp/uart.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#include "queue.h"
|
||||
|
||||
// DS18B20 driver
|
||||
#include "ds18b20/ds18b20.h"
|
||||
|
||||
void print_temperature(void *pvParameters)
|
||||
{
|
||||
int delay = 500;
|
||||
uint8_t amount = 0;
|
||||
uint8_t sensors = 2;
|
||||
DSENSOR t[sensors];
|
||||
|
||||
// Use GPIO 13 as one wire pin.
|
||||
uint8_t GPIO_FOR_ONE_WIRE = 13;
|
||||
|
||||
while(1) {
|
||||
// Search all DS18B20, return its amount and feed 't' structure with result data.
|
||||
amount = readDS18B20(GPIO_FOR_ONE_WIRE, t);
|
||||
|
||||
if (amount < sensors){
|
||||
printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
|
||||
}
|
||||
|
||||
for (int i = 0; i < amount; ++i)
|
||||
{
|
||||
printf("Sensor %d report: %d.%d C\n",t[i].id, t[i].major, t[i].minor);
|
||||
}
|
||||
printf("\n");
|
||||
vTaskDelay(delay / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
xTaskCreate(&print_temperature, (signed char *)"get_task", 256, NULL, 2, NULL);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue