U-BLOX NINA W E PlatformIO - ESP-IDF
O objetivo deste BLOG é demonstrar como é possível utilizar o PlatformIO para programar o módulo U-BLOX NINA W com framework ESP-IDF. Foi utilizado o EVK-NINA-W para o teste.
1) Baixe e instale o Visual Studio Code
2) Execute o Visual Studio Code
3) Na opção EXTENSIONS (canto esquerdo), procure por PlatformIO e Instale. Aguarde!
4) Uma vez instalado o PlatformIO, vá em PIO Home e crie um Novo Projeto e digite os parâmetros abaixo e então Finish
Aguarde alguns minutos para instalação do SDK. A instalação do SDK ficará em
C:\Users\USER\.platformio>
e os fontes em
C:\Users\USER\Documents\PlatformIO\Projects\blink-idf\src\main.cpp
5) Na opção EXPLORER você verá o projeto, então voce deverá adicionar o código fonte.
Com o notepad, crie um arquivo blink.c (pode ser vazio) e copie para a pasta
C:\Users\USER\Documents\PlatformIO\Projects\blink-idf\src\
Olhe novamente para o explorer, o seu arquivo blink.c vai aparecer na lista.
6) Observe o arquivo Platformio.ini que foi criado, você pode futuramente mudar para aceitar outro tipo de framework, como exemplo, Arduino. Adicione nele a última linha.
[env:nina_w10]
platform = espressif32
board = nina_w10
framework = espidf
board_build.partitions = partitions_singleapp.csv
7) Insira o código para
/* Blink Example
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 "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
/* Can run 'make menuconfig' to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
#define BLINK_GPIO 23 //nina w gpio (LED)
void blink_task(void *pvParameter)
{
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
while(1) {
/* Blink off (output low) */
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
/* Blink on (output high) */
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
xTaskCreate(&blink_task, "blink_task", configMINIMAL_STACK_SIZE, NULL, 5, NULL);
}
8) Compile (seja paciente), a primeira vez demora mais tempo.
9) Faça o UPLOAD (pressione tecla BOOT e então RESET) e você verá o LED alterando de estado a cada 1 segundo!
10) Questões: suporte@smartcore.com.br
FONTES:
https://platformio.org/
https://github.com/espressif/esp-idf/blob/master/examples/get-started/blink/main/blink.c
https://github.com/espressif/esp-idf/blob/master/examples/get-started/blink/main/blink.c