I purchased the Internet of Things Projects with ESP32 book by Agus Kurniawan and have been working through getting the ESP-IDF setup and working. I followed the tutorial in the Getting Started section of the the Espressif documentation and managed to get a working development system on the Raspberry Pi 3 using the ESP32 Wrover Kit.
The books first example is a blinking program which I have not been able to compile. Can someone point out what I may be doing incorrectly? I rechecked the code against the book and all looks complete. Here is the code.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#define LED1 12
#define LED2 14
#define LED3 26
void app_main()
{
xTaskCreate(&blinking_task, "blinking_task",
configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
void blinking_task(void *pvParameter)
{
// set gpio and its direction
gpio_pad_select_gpio(LED1);
gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED2);
gpio_set_direction(LED2, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED3);
gpio_set_direction(LED3, GPIO_MODE_OUTPUT);
int current_led = 1;
while(1) {
turn_on_led(current_led);
vTaskDelay(1000 / portTICK_PERIOD_MS);
current_led++;
if(current_led>3)
current_led=1;
}
}
void turn_on_led(int_led)
{
// turn off all leds
gpio_set_level(LED1, 0);
gpio_set_level(LED2, 0);
gpio_set_level(LED3, 0);
switch(led)
{
case 1:
gpio_set_level(LED1, 1);
break;
case 2:
gpio_set_level(LED2, 1);
break;
case 3:
gpio_set_level(LED3, 1);
break;
}
}
Here is the error:
pi@raspberrypi:~/esp/blinking $ make all
Toolchain path: /home/pi/esp/crosstool-NG/builds/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from /home/pi/esp/esp-idf/requirements.txt are satisfied.
Project is not inside a git repository, will not use 'git describe' to determine PROJECT_VER.
App "blinking" version: 1
CC build/main/blinking.o
/home/pi/esp/blinking/main/blinking.c: In function 'app_main':
/home/pi/esp/blinking/main/blinking.c:13:15: error: 'blinking_task' undeclared (first use in this function)
xTaskCreate(&blinking_task, "blinking_task",
^
--------------------------
There is a small carrot under "(&blinking_task,...") that begins the first indication of the error. Does anyone know why this is happening? Thanks for your help.
Blinking Program Not Compiling
Re: Blinking Program Not Compiling
That's because you're referencing blinking_task before it's been declared or defined. Either forward declare it or put the definition of blinking_task before (i.e. above) your app_main.
-
- Posts: 5
- Joined: Sun Apr 21, 2019 1:42 am
Re: Blinking Program Not Compiling
ESP_Dazz,
Thank you for your reply. Your solution makes sense. I followed the link to Forward Declaration and read about it.
IMHO, since I'm inexperienced, I think the best bet for me would be to declare it at the beginning.
I'll get to work figuring out how to do this and recompile.
I appreciate your help.
V/r,
SN
Thank you for your reply. Your solution makes sense. I followed the link to Forward Declaration and read about it.
IMHO, since I'm inexperienced, I think the best bet for me would be to declare it at the beginning.
I'll get to work figuring out how to do this and recompile.
I appreciate your help.
V/r,
SN
-
- Posts: 5
- Joined: Sun Apr 21, 2019 1:42 am
Re: Blinking Program Not Compiling
ESP_Dazz,
I ended up trying several different things, but in the end, this arrangement of the code worked! Thanks again for getting me pointed in the right direction!
V/r,
SN
----------------
[Codebox]
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#define LED1 12
#define LED2 14
#define LED3 26
void turn_on_led(int led)
{
// turn off all leds
gpio_set_level(LED1, 0);
gpio_set_level(LED2, 0);
gpio_set_level(LED3, 0);
switch(led)
{
case 1:
gpio_set_level(LED1, 1);
break;
case 2:
gpio_set_level(LED2, 1);
break;
case 3:
gpio_set_level(LED3, 1);
break;
}
}
void blinking_task(void *pvParameter)
{
// set gpio and its direction
gpio_pad_select_gpio(LED1);
gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED2);
gpio_set_direction(LED2, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED3);
gpio_set_direction(LED3, GPIO_MODE_OUTPUT);
int current_led = 1;
while(1) {
turn_on_led(current_led);
vTaskDelay(1000 / portTICK_PERIOD_MS);
current_led++;
if(current_led>3)
current_led=1;
}
}
void app_main()
{
xTaskCreate(&blinking_task, "blinking_task",
configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
[/Codebox]
I ended up trying several different things, but in the end, this arrangement of the code worked! Thanks again for getting me pointed in the right direction!
V/r,
SN
----------------
[Codebox]
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
#define LED1 12
#define LED2 14
#define LED3 26
void turn_on_led(int led)
{
// turn off all leds
gpio_set_level(LED1, 0);
gpio_set_level(LED2, 0);
gpio_set_level(LED3, 0);
switch(led)
{
case 1:
gpio_set_level(LED1, 1);
break;
case 2:
gpio_set_level(LED2, 1);
break;
case 3:
gpio_set_level(LED3, 1);
break;
}
}
void blinking_task(void *pvParameter)
{
// set gpio and its direction
gpio_pad_select_gpio(LED1);
gpio_set_direction(LED1, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED2);
gpio_set_direction(LED2, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(LED3);
gpio_set_direction(LED3, GPIO_MODE_OUTPUT);
int current_led = 1;
while(1) {
turn_on_led(current_led);
vTaskDelay(1000 / portTICK_PERIOD_MS);
current_led++;
if(current_led>3)
current_led=1;
}
}
void app_main()
{
xTaskCreate(&blinking_task, "blinking_task",
configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
[/Codebox]
Who is online
Users browsing this forum: No registered users and 63 guests