合宙ESP32C3上手使用

ESP32C3是一款基于RISC-V架构的32位微控制器,具备GPIO、I2C、UART、SPI等多种接口。硬件资源包括160MHzCPU、320KBRAM和4MBFlash。文章还介绍了如何配置PlatformIO以及使用DFRobot_PAJ7620U2手势识别模块进行示例开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概述

经典款是有ch343 ttl 转usb 需要安装驱动 GPIO20/21

新款使用usb 直连不需要驱动 USB GPIO18/19

ESP32C3 是ESP-RISC-V CPU 是基于 RISC-V ISA 的 32 位内核,包括基本整数 (I),乘法/除法 (M) 和压缩 (C) 标准扩展。ESP-RISC-V CPU 内核具有 4 级有序标量流水线,针对面积、功耗、性能等进行了优化.

硬件资源

ESP32C3 160MHz, 320KB RAM, 4MB Flash (4MB Flash 为外置,可自己更换)

I2C 可以使用任意管脚

I2S 可以使用任意管脚

IR 可以使用任意管脚

//2 uart   uart0 下载  
#define    UART1_TX_PIN  0
#define    UART1_RX_PIN  1

//5 12bit adc  采样率 100k sps
#define    ADC0_PIN  0
#define    ADC1_PIN  1
#define    ADC2_PIN  2
#define    ADC3_PIN  3
#define    ADC4_PIN  4

// one  spi  支持主模式
#define   SPI_CK_PIN    2
#define   SPI_MOSI_PIN  3
#define   SPI_MISO_PIN  10
#define   SPI_CS_PIN    7

//(最大同时4路)4路pwm 任意gpio 0 1 12 18 19 13 2 3 10 6 7 11 5 4 8 9
//1 iic    
#define   I2C_SCL_PIN 5
#define   I2C_SDA_PIN 4
#define   LED1_PIN 12
#define   LED2_PIN 13
#define   BOOT_PIN 9

ESP32-C3FN4 和 ESP32-C3FH4 中的内置 flash 端口与芯片管脚对应关系为:

• CS# = SPICS0

• IO0/DI = SPID

• IO1/DO = SPIQ

• CLK = SPICLK

• IO2/WP# = SPIWP

• IO3/HOLD# = SPIHD

以上管脚不建议用于其他功能

详细硬件资料参考官网文档

platformio 配置

选择esp32-c3-devkitm-1开发板 flash mode选择dio

[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
board_build.flash_mode = dio
upload_port = COM8
lib_deps = dfrobot/DFRobot_PAJ7620U2@^1.0.1

这里使用PAJ7628 手势识别模块作为demo 进行测试

通过Wire 指定I2C 管脚地址

#include <Arduino.h>
#include "C3_PIN.h"
#include <DFRobot_PAJ7620U2.h>
DFRobot_PAJ7620U2 paj;

void setup()
{
    Serial.begin(115200);
    while (!Serial)
        ;
    Wire.setPins(I2C_SDA_PIN,I2C_SCL_PIN);
    while (paj.begin() != 0)
    {
        Serial.println("initial PAJ7620U2 failure!");
        delay(500);
    }
    Serial.println("PAJ7620U2 setup ok");
    
    /*Set fast detection mode
    *If the parameter is set to false, the module enters slow detection mode, and it
    detects one gesture every 2s. We have integrated
    *some gestures inside the module to make it convenient for beginners.
    *The slow mode can recognize 9 basic gestures and 4 expanded gestures: move left,
    right, up, down, forward, backward, clockwise,
    *counter-clockwise, wave, slowly move left and right, slowly move up and down,
    slowly move forward and backward,
    *wave slowly and randomly.
    *
    *
    *
    *If the parameter is set to true, the module enters fast detection mode.
    *The fast mode can recognize 9 gestures: move left, right, up, down, forward,
    backward, clockwise, counter-clockwise, wave
    *To detect the combination of these gestures, like wave left, right and left
    quickly, users needs to design their own algorithms logic.
    *Since users only use limited gestures in this mode, we are not going to integrate
    too much expanded gestures in the library.
    *If necessary, you can complete the algorithm logic in the ino file by yourself.
    */
    paj.setGestureHighRate(true);
    pinMode(LED1_PIN, OUTPUT);
    pinMode(LED2_PIN, OUTPUT);
}
void loop()
{

    DFRobot_PAJ7620U2::eGesture_t gesture = paj.getGesture();
    if(gesture != paj.eGestureNone ){
    /* Get the string descritpion corresponding to the gesture number.
    * The string description could be
    * "None","Right","Left", "Up", "Down", "Forward", "Backward", "Clockwise", "Anti-
    Clockwise", "Wave",
    * "WaveSlowlyDisorder", "WaveSlowlyLeftRight", "WaveSlowlyUpDown",
    "WaveSlowlyForwardBackward"
    */
    String description = paj.gestureDescription(gesture);//Convert gesture number into string description
    Serial.println("--------------Gesture Recognition System---------------------------");
    Serial.print("gesture code = ");Serial.println(gesture);
    Serial.print("gesture description = ");Serial.println(description);
    Serial.println();
    }
}

实际效果

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谢娘蓝桥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值