初学者
10 分钟

通过 ESP-WROOM-02 和 PIC32MZ2048EFM100 为您的项目提供无线连接

用强大的 WiFi 助力您的物联网生态系统!

WiFi ESP Click with Curiosity PIC32 MZ EF

已发布 6月 25, 2024

点击板

WiFi ESP Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

将您的环境转变为智能绿洲,使用我们的 WiFi 模块,它能够轻松集成到您的项目中,为您的联网生活方式提供连接支持。

A

A

硬件概览

它是如何工作的?

WiFi ESP Click 基于 ESP-WROOM-02,这是来自 Espressif 的一款完全集成的 WiFi 模块。它采用了广为人知的工作马 ESP8266EX,这是一款高度集成的 SoC 解决方案,满足了行业对高效能源使用、紧凑设计和可靠性能的持续需求。除了 WiFi 功能外,ESP8266EX 还集成了 Tensilica 的 L106 Diamond 系列 32 位处理器的增强版和片上 SRAM,以及天线开关、RF balun、功率放大器、低噪声接收放大器、滤波器和电源管理模块。该模块还包括 2MB 的 SPI 闪存,用于存储用户程序。凭借完整和自成一体的 WiFi 网络功

能,它可以作为独立应用程序(WROOM 模块本身)或作为 MCU 主机的从属设备运行,这是 Click 板作为一个整体的主要意图。因此,这块 Click 板可以通过 UART 接口(mikroBUS 引脚插座上的 RX、TX 线)作为 WiFi 适配器应用于任何微控制器设计。WiFi ESP Click 配备了模块的 5 个 GPIO,这些 GPIO 是模块的 HSPI/GPIO 接口的一部分。GPIO0 通过与旁边的 GND 缩短来进入 ESP8266EX 的 UART 下载模式。这样,您可以升级模块的固件或上传自定义固件。WiFi ESP Click 通过 UART 接口与主 MCU 通信,

其默认通信协议为 115200 波特率。除了标准的 UART RX 和 TX 线外,主 MCU 还通过 EN 和 RST 线与 WiFi ESP Click 连接。前者在逻辑低电平时关闭模块,而后者用于重置 ESP8266EX。您还可以使用 UART 接口通过 AT 命令集与 ESP-WROOM-O2 模块进行通信。这个 Click 板™ 只能在 3.3V 逻辑电压水平下操作。在使用具有不同逻辑电平的 MCU 之前,板必须执行适当的逻辑电压水平转换。此外,它还配备了包含函数和示例代码的库,可以作为进一步开发的参考。

WiFi ESP Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RA9
RST
Chip Enable
RPD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
UART TX
RPD10
TX
UARTRX
RPD15
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

WiFi ESP Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
Thermo 28 Click front image hardware assembly
Prog-cut hardware assembly
Curiosity PIC32 MZ EF MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Curiosity PIC32 MZ EF MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

这个库包含 WiFi ESP Click 驱动的 API。

关键功能:

  • wifiesp_send_cmd - 向模块发送 AT 命令。

  • wifiesp_generic_write - 通用写入函数

  • wifiesp_generic_read - 通用读取函数。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * \file 
 * \brief wifiesp Click example
 * 
 * # Description
 * This example connects to the desired WiFi network and then
 * creates web server on the IP address assigned to the click board.
 * The user can connect to the server via web browser.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes driver and wifi communication, then connects to the desired WiFi network
 * and creates web server on the IP address assigned to the click board.
 * 
 * ## Application Task  
 * Waits for the client request (paste IP address in your web browser and 
 * refresh to send a request).
 * The click board will respond by sending a page content to the client.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "wifiesp.h"
#include "string.h"
#include "conversions.h"

#define APP_SSID                            "MikroE Public"
#define APP_PASSWORD                        "mikroe.guest"

#define PROCESS_BUFFER_SIZE                 610

// ------------------------------------------------------------------ VARIABLES

uint8_t page[ ] = "<a href=\"https://www.mikroe.com/\">MikroElektronika</a>\
<h1 style=\"color:red;\">WiFi ESP click board</h1>";
uint8_t page_len[ 10 ] = { 0 };
uint8_t send_buf[ 10 ] = { 0 };
static uint8_t link_id[ 2 ] = { 0 };

static wifiesp_t wifiesp;
static log_t logger;

static char app_buf[ PROCESS_BUFFER_SIZE ]  = { 0 };
static int32_t app_buf_len                  = 0;

static err_t app_error_flag;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void wifiesp_clear_app_buf ( void )
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void wifiesp_log_app_buf ( void )
{
    for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
    {
        log_printf( &logger, "%c", app_buf[ buf_cnt ] );
    }
}

static err_t wifiesp_process ( void )
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t rx_size = 0;
    rx_size = wifiesp_generic_read( &wifiesp, rx_buf, PROCESS_BUFFER_SIZE );
    if ( rx_size > 0 ) 
    {
        int32_t buf_cnt = app_buf_len;
        if ( ( ( app_buf_len + rx_size ) > PROCESS_BUFFER_SIZE ) && ( app_buf_len > 0 ) ) 
        {
            buf_cnt = PROCESS_BUFFER_SIZE - ( ( app_buf_len + rx_size ) - PROCESS_BUFFER_SIZE );
            memmove ( app_buf, &app_buf[ PROCESS_BUFFER_SIZE - buf_cnt ], buf_cnt );
        }
        for ( int32_t rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ buf_cnt++ ] = rx_buf[ rx_cnt ];
                if ( app_buf_len < PROCESS_BUFFER_SIZE )
                {
                    app_buf_len++;
                }
            }
        }
        return WIFIESP_OK;
    }
    return WIFIESP_ERROR;
}

static err_t wifiesp_rsp_check ( char * response )
{
    uint32_t timeout_cnt = 0;
    uint32_t timeout = 120000;
    wifiesp_clear_app_buf( );
    wifiesp_process( );
    while ( ( 0 == strstr( app_buf, response ) ) &&
            ( 0 == strstr( app_buf, WIFIESP_RSP_ERROR ) ) )
    {
        wifiesp_process( );
        if ( timeout_cnt++ > timeout )
        {
            wifiesp_clear_app_buf( );
            return WIFIESP_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms( 5 );
    wifiesp_process( );
    if ( strstr( app_buf, response ) )
    {
        return WIFIESP_OK;
    }
    else if ( strstr( app_buf, WIFIESP_RSP_ERROR ) )
    {
        return WIFIESP_ERROR_CMD;
    }
    return WIFIESP_ERROR_UNKNOWN;
}

static void wifiesp_error_check( err_t error_flag )
{
    switch ( error_flag )
    {
        case WIFIESP_OK:
        {
            wifiesp_log_app_buf( );
            break;
        }
        case WIFIESP_ERROR:
        {
            log_error( &logger, " Overflow!" );
            break;
        }
        case WIFIESP_ERROR_TIMEOUT:
        {
            log_error( &logger, " Timeout!" );
            break;
        }
        case WIFIESP_ERROR_CMD:
        {
            log_error( &logger, " CMD!" );
            break;
        }
        case WIFIESP_ERROR_UNKNOWN:
        default:
        {
            log_error( &logger, " Unknown!" );
            break;
        }
    }
    log_printf( &logger, "\r\n-----------------------------------\r\n" );
    Delay_ms( 500 );
}

void wifi_communication_init( void )
{
    wifiesp_process( ); // dummy read
    wifiesp_clear_app_buf( );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_CHECK, NULL );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_RESTORE, NULL );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    uart_clear ( &wifiesp.uart );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_CHECK_FIRMWARE, NULL );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_SET_MODE, "1" );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_clear_app_buf( );
    strcpy ( app_buf, "\"" );
    strcat ( app_buf, APP_SSID );
    strcat ( app_buf, "\",\"" );
    strcat ( app_buf, APP_PASSWORD );
    strcat ( app_buf, "\"" );
    app_buf_len = strlen ( app_buf );
    wifiesp_send_cmd( &wifiesp, WIFIESP_CONNECT, app_buf );
    wifiesp_clear_app_buf ( );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_SET_MULTIPLE_CONNECTION, "1" );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_SET_AS_SERVER, "1,80" );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
    
    wifiesp_send_cmd( &wifiesp, WIFIESP_GET_IP, NULL );
    app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
    wifiesp_error_check( app_error_flag );
}

static void wifiesp_str_cut_chr ( uint8_t *str, uint8_t chr )
{
    uint16_t cnt_0 = 0;
    uint16_t cnt_1 = 0;
    for ( cnt_0 = 0; cnt_0 < strlen( str ); cnt_0++ )
    {
        if ( str[ cnt_0 ] == chr )
        {
            for ( cnt_1 = cnt_0; cnt_1 < strlen( str ); cnt_1++ )
            {
                str[ cnt_1 ] = str[ cnt_1 + 1 ];
            }
        }
    }
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    wifiesp_cfg_t cfg;
    
    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    // Click initialization.
    wifiesp_cfg_setup( &cfg );
    WIFIESP_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    wifiesp_init( &wifiesp, &cfg );
    wifiesp_default_cfg( &wifiesp );
    Delay_ms( 1000 );
    
    // Communication initialization
    wifi_communication_init( );
    
    uint16_to_str ( strlen( page ), page_len );
    wifiesp_str_cut_chr ( page_len, ' ' );
    
    log_info( &logger, "Please connect to the IP address listed above.\r\n" );
}

void application_task ( void )
{
    if ( WIFIESP_OK == wifiesp_rsp_check( WIFIESP_RECEIVE ) ) 
    {
        link_id[ 0 ] = *( strstr( app_buf, WIFIESP_RECEIVE ) + 5 );
        strcpy ( send_buf, link_id );
        strcat ( send_buf, "," );
        strcat ( send_buf, page_len );
        wifiesp_str_cut_chr ( send_buf, ' ' );
        wifiesp_log_app_buf( );
        wifiesp_clear_app_buf( );
        Delay_ms( 100 );
        wifiesp_process( );
        wifiesp_log_app_buf( );
        wifiesp_send_cmd( &wifiesp, WIFIESP_SEND, send_buf );
        app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_READY_FOR_SEND );
        wifiesp_log_app_buf( );
        Delay_ms( 100 );
        wifiesp_generic_write( &wifiesp, page, strlen( page ) );
        app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_SEND_OK );
        wifiesp_error_check( app_error_flag );
        wifiesp_send_cmd( &wifiesp, WIFIESP_CLOSE, link_id );
        app_error_flag = wifiesp_rsp_check( WIFIESP_RSP_OK );
        wifiesp_error_check( app_error_flag );
        wifiesp_clear_app_buf( );
        
        wifiesp_process( );
        wifiesp_log_app_buf( );
        wifiesp_clear_app_buf( );
        uart_clear ( &wifiesp.uart );
        Delay_ms( 100 );
    }
}

void main ( void )
{
    application_init( );
    
    for ( ; ; )
    {
        application_task ( );
    }
}


// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。