close

2017.11.22(星期三)

這個文件用來記錄ESP-IDF的安裝及使用過程, Espressif IoT Development Framework (esp-idf). 是使用 ESP32 晶片所發展 Internet-of-Things (IoT)應用程式的正式開發架構。

Get Started

需要的材料

  • PC 有Windows, Linux or Mac 作業系統。
  • Download and Install VirtualBox 5.2 & Ubuntu 16.04   (參考http://blog.xuite.net/yh96301/blog/432341564) 
  • Toolchain 建造ESP32的應用程式。
  • ESP-IDF 包括ESP32必須要使用的API。
  • 文字編輯器(e.g. Eclipse)寫C語言 。
  • ESP32 開發板和連到PC的USB cable 

undefined

          ESP32 發展環境三個步驟

  1. 安裝Toolchain。  (參考 https://dl.espressif.com/doc/esp-idf/latest/get-started/windows-setup.html)
  2. 從GitHub得到ESP-IDF。 (參考 https://dl.espressif.com/doc/esp-idf/latest/get-started/index.html#guides)
  3. 設定路徑至ESP-IDF。 (參考 https://dl.espressif.com/doc/esp-idf/latest/get-started/index.html#guides)
  4.  

ESP32 應用程式開發四個步驟

  1. 配置一個專案及程式碼。(參考 https://dl.espressif.com/doc/esp-idf/latest/get-started/index.html#guides)
  2. 編譯專案及連結至應用程式。
  3. 燒錄應用程式至ESP32晶片內。(參考 https://dl.espressif.com/doc/esp-idf/latest/get-started/make-project.html)
  4. 監控及除錯應用程式。

測試程式: Hello World
參考https://exploreembedded.com/wiki/Hello_World_with_ESP32_Explained

  1. /* Hello World Example*/
  2. #include <stdio.h>
  3. #include "freertos/FreeRTOS.h"
  4. #include "freertos/task.h"
  5. #include "esp_system.h"
  6.  
  7. void hello_task(void *pvParameter)
  8. {
  9. printf("Hello world!\n");
  10. for (int i = 10; i >= 0; i--) {
  11. printf("Restarting in %d seconds...\n", i);
  12. vTaskDelay(1000 / portTICK_RATE_MS);
  13. }
  14. printf("Restarting now.\n");
  15. fflush(stdout);
  16. esp_restart();
  17. }
  18.  
  19. void app_main()
  20. {
  21. nvs_flash_init();
  22. xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
  23. }

另一個LED  On/Off 程式

  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "esp_system.h"
  5. #include "driver/gpio.h"
  6.  
  7. #define BLINK_GPIO 13 
  8.  
  9. void hello_task(void *pvParameter)
  10. { 
  11. while(1)
  12. {
  13. printf("Hello world!\n");
  14. vTaskDelay(100/portTICK_RATE_MS);
  15. }
  16. }
  17.  
  18. void blinky(void *pvParameter)
  19. {
  20.   gpio_pad_select_gpio(BLINK_GPIO); /* Set the GPIO as a push/pull output */
  21. gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
  22. while(1) {   /* Blink off (output low) */
  23. gpio_set_level(BLINK_GPIO, 0);
  24. vTaskDelay(1000/portTICK_RATE_MS);   /* Blink on (output high) */
  25. gpio_set_level(BLINK_GPIO, 1);
  26. vTaskDelay(1000/portTICK_RATE_MS);
  27. }
  28. }
  29.   
  30. void app_main()
  31. {
  32. nvs_flash_init();
  33. xTaskCreate(&hello_task, "hello_task", 2048, NULL, 5, NULL);
  34. xTaskCreate(&blinky, "blinky", 512,NULL,5,NULL );
  35. }

參考資料:

https://dl.espressif.com/doc/esp-idf/latest/index.html
ESP32: Hello World
ESP32 Bluetooth: Using the BTstack library

 

  

 

 

 

arrow
arrow
    全站熱搜

    stanley 發表在 痞客邦 留言(0) 人氣()