esp32的arduino扩展开发方式

1.下载开发工具,配置mysys32,并把esp-idf配置成为sdk的目录 “ $IDF_PATH “

2.用例程创建一个idf的工程目录。

3.进入工程目录输入下面的命令:

mkdir -p components && 
cd components && 
git clone https://github.com/espressif/arduino-esp32.git arduino && 
cd .. && 
make menuconfig

4.利用make menuconfig设置arduino的启动模式:

(1)设置arduino通用的启动方式:(setup loop 模式)

在菜单中选择 ”Autostart Arduino setup and loop on boot"

后面写arduino程序就用以下这个模板

//file: main.cpp
#include "Arduino.h"

void setup(){
  Serial.begin(115200);
}

void loop(){
  Serial.println("loop");
  delay(1000);
}
(2)使用cpp常用的方式开发,就使用c++的模板
//file: main.cpp
#include "Arduino.h"

extern "C" void app_main()
{
    initArduino();
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);
    //do your own thing
}

注意:文件名必须是
main.cpp
,否则通不过编译。

5.下面贴一个我写的例程

//file: main.cpp
#include <Arduino.h>
#include <esp_task_wdt.h>
#include <esp_int_wdt.h>

extern "C"{
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
}

#if 0
void setup(){
  Serial.begin(115200);
  esp_task_wdt_init();
  esp_int_wdt_init();
  Serial.println("Start !");
}

void loop(){
  Serial.println("loop");
  delay(1000);
}
#endif



void SendTest(void *pvParameter){
	
	while(1){		
		Serial.println("loop");
		delay(1000);
	}
}

extern "C" void app_main()
{
  initArduino();	
  Serial.begin(115200);
  Serial.println("Start !");
  
  xTaskCreate(&SendTest, "SendTest", 2048, NULL, 5, NULL);
}


经验分享 程序员 微信小程序 职场和发展