ESP32-WROOM-32报错error: ‘ledcSetup‘ ‘ledcAttachPin’was not declared in this scope

当我想用ESP32-WROOM-32进行PWM调速时,我发现编译报错了,我以为代码有问题,换了个很简单的测试代码,发现还是报错

#define FREQ 2000 // 频率
#define CHANNEL 0 // 通道
#define RESOLUTION 8 // 分辨率
#define LED 32 // LED引脚

void setup() {
  // 设置频率
  ledcSetup(CHANNEL, FREQ, RESOLUTION);
  // 绑定通道号与引脚
  ledcAttachPin(LED, CHANNEL);
}

void loop() {
  
}

 后查阅官方资料发现,在新版本中arduino中这两个函数已经被弃用(官方链接

解决方案:直接用ledcAttach函数即可


ledcSetup等同于ledcAttach原型为:

bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution);
 
/*
·pin选择 LEDC 引脚。
 
·freq选择 pwm 的频率。
 
·resolution选择LEDC通道的分辨率。范围是 1-14 位(ESP32 为 1-20 位)。
 
·true如果配置成功,此函数将返回。如果false返回,则发生错误,LEDC 通道未配置。
*/

绑定通道与引脚用ledcWrite:设置LEDC引脚占空比

bool ledcWrite(uint8_t pin, uint32_t duty);
 
/*
·pin选择 LEDC 引脚。
 
·duty选择要为选定的 LEDC 引脚设置的占空比。
 
·true如果设置占空比成功,此函数将返回。如果false返回,则发生错误,并且未设置占空比。
*/

目前版本不需要进行通道与引脚的绑定
修改代码如下:

#define FREQ 2000 // 频率
#define PIN 32 // 通道
#define RESOLUTION 8 // 分辨率
#define LED 1 // LED引脚

void setup() {
  // 设置频率
  ledcAttach(PIN, FREQ,RESOLUTION);
}

void loop() {
    //设置占空比
    ledcWrite(PIN, 127);        
}

C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:39:31: error: 'GPIO_NUM_47' was not declared in this scope; did you mean 'GPIO_NUM_7'? 39 | #define DISPLAY_MOSI_PIN GPIO_NUM_47 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:73:30: note: in expansion of macro 'DISPLAY_MOSI_PIN' 73 | buscfg.mosi_io_num = DISPLAY_MOSI_PIN; | ^~~~~~~~~~~~~~~~ In file included from D:/Espressif/frameworks/esp-idf-v5.4.1/components/esp_driver_gpio/include/driver/gpio.h:12, from C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/common/backlight.h:6, from C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/common/board.h:11, from C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/common/wifi_board.h:4, from C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:1: C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:79:44: error: 'SPI3_HOST' was not declared in this scope; did you mean 'SPI2_HOST'? 79 | ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO)); | ^~~~~~~~~ D:/Espressif/frameworks/esp-idf-v5.4.1/components/esp_common/include/esp_err.h:116:30: note: in definition of macro 'ESP_ERROR_CHECK' 116 | esp_err_t err_rc_ = (x); \ | ^ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc: In member function 'void CompactWifiBoardLCD::InitializeLcdDisplay()': C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:43:31: error: 'GPIO_NUM_41' was not declared in this scope; did you mean 'GPIO_NUM_4'? 43 | #define DISPLAY_CS_PIN GPIO_NUM_41 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:88:33: note: in expansion of macro 'DISPLAY_CS_PIN' 88 | io_config.cs_gpio_num = DISPLAY_CS_PIN; | ^~~~~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:41:31: error: 'GPIO_NUM_40' was not declared in this scope; did you mean 'GPIO_NUM_4'? 41 | #define DISPLAY_DC_PIN GPIO_NUM_40 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:89:33: note: in expansion of macro 'DISPLAY_DC_PIN' 89 | io_config.dc_gpio_num = DISPLAY_DC_PIN; | ^~~~~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:95:50: error: 'SPI3_HOST' was not declared in this scope; did you mean 'SPI2_HOST'? 95 | ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI3_HOST, &io_config, &panel_io)); | ^~~~~~~~~ D:/Espressif/frameworks/esp-idf-v5.4.1/components/esp_common/include/esp_err.h:116:30: note: in definition of macro 'ESP_ERROR_CHECK' 116 | esp_err_t err_rc_ = (x); \ | ^ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:42:31: error: 'GPIO_NUM_45' was not declared in this scope; did you mean 'GPIO_NUM_5'? 42 | #define DISPLAY_RST_PIN GPIO_NUM_45 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:100:39: note: in expansion of macro 'DISPLAY_RST_PIN' 100 | panel_config.reset_gpio_num = DISPLAY_RST_PIN; | ^~~~~~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc: In constructor 'CompactWifiBoardLCD::CompactWifiBoardLCD()': C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:38:31: error: 'GPIO_NUM_42' was not declared in this scope; did you mean 'GPIO_NUM_4'? 38 | #define DISPLAY_BACKLIGHT_PIN GPIO_NUM_42 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:165:13: note: in expansion of macro 'DISPLAY_BACKLIGHT_PIN' 165 | if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) { | ^~~~~~~~~~~~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc: In member function 'virtual Led* CompactWifiBoardLCD::GetLed()': C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:31:33: error: 'GPIO_NUM_48' was not declared in this scope; did you mean 'GPIO_NUM_8'? 31 | #define BUILTIN_LED_GPIO GPIO_NUM_48 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:172:30: note: in expansion of macro 'BUILTIN_LED_GPIO' 172 | static SingleLed led(BUILTIN_LED_GPIO); | ^~~~~~~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc: In member function 'virtual Backlight* CompactWifiBoardLCD::GetBacklight()': C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/config.h:38:31: error: 'GPIO_NUM_42' was not declared in this scope; did you mean 'GPIO_NUM_4'? 38 | #define DISPLAY_BACKLIGHT_PIN GPIO_NUM_42 | ^~~~~~~~~~~ C:/Users/yuanx/Desktop/xiaozhi-esp32-1.6.0/main/boards/bread-compact-wifi-lcd/compact_wifi_board_lcd.cc:192:13: note: in expansion of macro 'DISPLAY_BACKLIGHT_PIN' 192 | if (DISPLAY_BACKLIGHT_PIN != GPIO_NUM_NC) { | ^~~~~~~~~~~~~~~~~~~~~ [1789/1796] Building CXX object esp-idf/main/CMakeFiles/__idf_main.dir/boards/common/wifi_board.cc.obj ninja: build stopped: subcommand failed. ninja failed with exit code 1, output of the command is in the C:\Users\yuanx\Desktop\xiaozhi-esp32-1.6.0\build\log\idf_py_stderr_output_6772 and C:\Users\yuanx\Desktop\xiaozhi-esp32-1.6.0\build\log\idf_py_stdout_output_6772
06-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值