概述
经典款是有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();
}
}
实际效果