ESP32-C3 Mini Smart Voice Lighting

I. Overview

2. Hardware schematic design

3. Hardware PCB software design

4. Software Design

5. Structural Design

6. Summary

I. Overview

This design is a mini intelligent lighting product designed using ESP32-C3 chip, combined with TP4057 lithium battery charging management chip, SIQ-02FVS3 rotary encoder, offline voice recognition module, passive buzzer, and TYPE-C interface.

Features:

  1. One-button switch on and off, absolutely power off when shutting down.

  1. The rotary switch controls the four LEDs (upper 1206 LEDs). Turning left to operate the LED will gradually brighten, and turning right to operate the LED will gradually dim. Press the button down to turn the LED on or off.

  1. The passive buzzer realizes the sound of power-on and power-off, and can also play music.

  1. The voice recognition module controls the LED to turn on and off,

  1. Control the lower RGB LED for different color display.

  1. Front 0.96-inch OLED display.

  1. The 3.7V lithium battery at the bottom is used for power supply.

  1. The appearance is exquisite and small, 5cm X 3.2cm

  1. Overcurrent protection, 1A resettable fuse.

Renderings:

Physical map:

2. Hardware Design

1. Main chip

The main chip directly adopts the ESP32-C3 module, the peripheral circuit is simple, and there is also a USB-to-serial port IC left, and the C3 has its own USB.

2. Rotary encoder

Use the internal pull-up of the MCU to reduce the complexity of the peripheral circuit, use the button (S pole) GPIO9 multiplex download mode, and save a power-on reset button.

3、LED

1206 white LED and RBG LED, the former uses PWM to control the brightness of the LED, and the latter uses RBG code to control the color. Because the RBG LED has a standby current, a MOS tube is added for switch control to reduce power consumption.

4. TYPE-C interface and charging management IC

Adopt the mainstream TYPE-C interface, and use TP4057 IC for lithium battery charging management.

5. Passive buzzer

6. Speech recognition module

Configure the SKD online, download it to the voice module, and control the corresponding IO when the set voice is recognized. Since the quiescent current of the voice module is not low during operation, a key switch is added for power control.

7、0.96 OLED

Similarly, in order to ensure standby power consumption, a power supply switch is also added.

8. One-button switch circuit

The power supply is self-locking through GPIO1, F1 is a 1A resettable fuse, and the system is powered by 3.3V through AMS1117.

9. Battery power detection

The 100nF filter capacitor needs to be as close as possible to the pins of the chip.

3. Hardware PCB software design

PCB采用两层板设计,采用多个模块堆叠的方式,保证整个设计尽量小巧迷你,OLED堆叠在ESP32-C3模组之上,实体采用胶布进行隔离。

顶层:

四个1206LED于左上,旋转编码器于右上,唯一与外界的下载接口在右侧中央,中间为无源蜂鸣器,下方还有四个RGB LED可产生各种颜色,右下角为语音模块的供电开关。

底层:

锂电池根据板子的规格购买,刚好能嵌入到底层,语音识别模块也在板子底部,还有各种器件。

四、软件设计

采用Arduino IDE进行软件代码编写。

软件逻辑:
1.一键开关机

上电后对供电进行自锁,收到关机指令后释放自锁,以实现一键开关机功能。

2.十秒无操作熄屏省电

采用millis()函数进行计数,如下代码,以每秒进行累加,十秒以内如果没有操作旋转开关(若操作旋转开关,会对sreen变量进行重新幅值),则screen会累加到10,进行关闭OLED的操作。

3.低电量自动关机

每十秒进行电量的判断,如果低于百分之30,为保护电池寿命,自动进行关机。

  
static uint32_t oledtime = 0;
  if (millis() - oledtime > 1000) {  //定时一秒钟   十秒钟无操作,则关闭OLED供电
    oledtime = millis();             // 重新计时
    screen = screen + 1;
    if (screen >= 10) {     //每十秒没有操作,则关闭oled
      digitalWrite(21, 1);  //关闭OLED供电
       double analogVolts = analogReadMilliVolts(4);                   //引脚4读取ADC 电压模拟量
       double power = ((((analogVolts / 1000) * 2) - 3) / 1.2) * 100;  //从3.0V-4.2V换算成容量百分比

    if ((((((analogVolts/1000)*2)-3)/1.2)*100) < 30) {
      // Serial.printf(" LL\r\n");
          digitalWrite(1, 0);  //如果电量小于30  自动关机
          } 
    }
  }
4.编码器按键功能

每按一次,对LED的控制反向,同时,在开灯时显示电池电量,如果电量低于百分之50,显示L字样,同时置位OLED关闭的时间。

  
//编码器按键 控制开关
  if (digitalRead(key) == 0) {
    delay(120);
    if (digitalRead(key) == 0) {
      if (bright == 0) {
        bright = 255;
        ledcAnalogWrite(LEDC_CHANNEL_1, bright);
        ///只在开灯的时候,显示电量,关灯无动作
        digitalWrite(21, 0);  //打开OLED供电
        u8x8.begin();
       // u8x8.setPowerSave(0);
        u8x8.setFont(u8x8_font_chroma48medium8_r);
        double analogVolts = analogReadMilliVolts(4);   //引脚4读取ADC 电压模拟量
        double power = ((((analogVolts / 1000) * 2) - 3) / 1.2) * 100; //从3.0V-4.2V换算成容量百分比
        dtostrf(power, 2, 0, power_string);  //函数转换,double转换成字符串
        if (power < 50) {
        u8x8.drawString(10, 0, "L");  }
        u8x8.drawString(12, 0, power_string);
        u8x8.drawString(15, 0, "%");
           if (power < 30) {
          digitalWrite(1, 0);  //如果电量小于30  自动关机
          }
      } else {
        bright = 0;
        ledcAnalogWrite(LEDC_CHANNEL_1, bright);
      }
      screen = 1;  //每按一次按键,重置关闭屏幕的时间
    }
  }
5.无源蜂鸣器

输出不同的频率来实现特定的开机或关机声。


#define buzzer (6)
int freq = 2000;     //设置频率
int channel_sp = 0;  //通道号,取值0 ~ 15
int resolution = 8;  //计数位数,2的8次幂=256

void start_beep()  //开机声
{
  ledcWrite(channel_sp, 125);  //一半占空比
  ledcWriteTone(channel_sp, 2000);
  delay(100);
  ledcWriteTone(channel_sp, 2500);
  delay(100);
  ledcWriteTone(channel_sp, 3000);
  delay(250);
  ledcWriteTone(channel_sp, 0);
}

void off_beep()  //关机声
{
  ledcWrite(channel_sp, 125);  //一半占空比
  ledcWriteTone(channel_sp, 3000);
  delay(100);
  ledcWriteTone(channel_sp, 2500);
  delay(100);
  ledcWriteTone(channel_sp, 2000);
  delay(250);
  ledcWriteTone(channel_sp, 0);
}

五、结构设计

其实这个板子一开始使用的是嘉立创EDA自带的3D外壳设计,那个时候采用的是上下扣合的方式,后面为了美观一些,就直接采用亚克力板上下螺丝固定,螺丝孔大小为M3,将板子外形文件发给某宝定制亚克力。

六、总结

其实这个产品整体难度并不大,基本也就是大学时候做的电路设计差不多,复杂度并不高,不过其中有的细节却是结合了工作所学,读书期间,没有经历过一个电子产品完整的设计周期,设计的产品,可能说能用,但不会非常可靠,一个便携式电子产品不论从整体功耗还是静电防护,还是功能逻辑,还是系统可靠性,健壮性,都需要关注到位(当然了,这个板子的ESD IC我没加,主要是因为业余设计,物料能少就少,设计简单)。

Guess you like

Origin blog.csdn.net/weixin_42107954/article/details/128676845