ESP32 Onchip Sensor
来自Jack's Lab
(版本间的差异)
(→Overview) |
(→Quick Start) |
||
| 第58行: | 第58行: | ||
<br><br> | <br><br> | ||
| + | |||
| + | == Code == | ||
| + | |||
| + | <source lang=cpp> | ||
| + | /* | ||
| + | * MaiKe Labs (2016 - 2026) | ||
| + | * | ||
| + | * Written by Jack Tan <jiankemeng@gmail.com> | ||
| + | * | ||
| + | * This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
| + | * Unless required by applicable law or agreed to in writing, this | ||
| + | * software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
| + | * CONDITIONS OF ANY KIND, either express or implied. | ||
| + | * | ||
| + | */ | ||
| + | #include <stdio.h> | ||
| + | #include <stdlib.h> | ||
| + | #include "freertos/FreeRTOS.h" | ||
| + | #include "freertos/task.h" | ||
| + | #include "esp_wifi.h" | ||
| + | #include "esp_event_loop.h" | ||
| + | #include "esp_system.h" | ||
| + | #include "nvs_flash.h" | ||
| + | |||
| + | uint8_t temprature_sens_read(); | ||
| + | uint32_t hall_sens_read(); | ||
| + | |||
| + | void read_sens_task(void *pvParameters) | ||
| + | { | ||
| + | while (1) { | ||
| + | printf("ESP32 onchip Temperature = %d\n", temprature_sens_read()); | ||
| + | printf("ESP32 onchip Hall sensor = %d\n", hall_sens_read()); | ||
| + | vTaskDelay(4000 / portTICK_PERIOD_MS); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void app_main() | ||
| + | { | ||
| + | nvs_flash_init(); | ||
| + | system_init(); | ||
| + | printf("Welcome to Noduino Quantum\r\n"); | ||
| + | printf("Try to read the sensors inside the ESP32 chip ... \r\n"); | ||
| + | xTaskCreatePinnedToCore(&read_sens_task, "read_sens_task", 1024, NULL, 5, | ||
| + | NULL, 0); | ||
| + | } | ||
| + | </source> | ||
<br><br><br><br><br><br> | <br><br><br><br><br><br> | ||
2016年11月15日 (二) 13:37的版本
1 Overview
2 Quick Start
- Build
$ sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial $ wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux32-1.22.0-59.tar.gz $ mkdir -p toolchain $ tar -xzf xtensa-esp32-elf-linux32-1.22.0-59.tar.gz -C toolchain $ export PATH=$PATH:`pwd`/toolchain/xtensa-esp32-elf/bin $ $ git clone --recursive git://github.com/icamgo/esp-idf.git $ cd esp-idf/examples/09_onchip_sensor $ make menuconfig $ make flash
- Check serial
$ picocom -b 115200 /dev/ttyUSB0 ets Jun 8 2016 00:22:57 rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) ets Jun 8 2016 00:22:57 rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0x00 clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:QIO, clock div:1 load:0x3ffc0000,len:0 load:0x3ffc0000,len:920 load:0x40078000,len:3220 ho 0 tail 12 room 4 load:0x40080000,len:260 entry 0x40080034 I (63) heap_alloc_caps: Initializing heap allocator: I (63) heap_alloc_caps: Region 19: 3FFB45D8 len 0002BA28 tag 0 I (65) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1 I (74) cpu_start: Pro cpu up. I (80) cpu_start: Single core mode I (86) cpu_start: Pro cpu start user code rtc v118 Oct 19 2016 15:22:11 XTAL 40M I (121) cpu_start: Starting scheduler on PRO CPU. Welcome to Noduino Quantum Try to read the temperature sensor of the ESP32 onchip ... ESP32 onchip Temperature = 143 ESP32 onchip Hall sensor = 5247 ESP32 onchip Temperature = 145 ESP32 onchip Hall sensor = 5240
3 Code
/*
* MaiKe Labs (2016 - 2026)
*
* Written by Jack Tan <jiankemeng@gmail.com>
*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_system.h"
#include "nvs_flash.h"
uint8_t temprature_sens_read();
uint32_t hall_sens_read();
void read_sens_task(void *pvParameters)
{
while (1) {
printf("ESP32 onchip Temperature = %d\n", temprature_sens_read());
printf("ESP32 onchip Hall sensor = %d\n", hall_sens_read());
vTaskDelay(4000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
nvs_flash_init();
system_init();
printf("Welcome to Noduino Quantum\r\n");
printf("Try to read the sensors inside the ESP32 chip ... \r\n");
xTaskCreatePinnedToCore(&read_sens_task, "read_sens_task", 1024, NULL, 5,
NULL, 0);
}