基于Arduino ATmega328人脸识别IOT演示开关

Posted 卓晴

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于Arduino ATmega328人脸识别IOT演示开关相关的知识,希望对你有一定的参考价值。

 

§01 Arduino ATmega328 测试电路


根据 Arduino门禁人机接口调试 Version 1.0 基于Groove Beginner的背板的设计基础上,按照 从0 开始 DIY你的Arduino UNO 设计方法,将ATmega328直接与接口电路设计成一个单一的电路板,便可以大大简化系统的构成了。

1、电路设计

▲ 图1-1 最小系统原理图

▲ 图1-1 最小系统原理图

▲ 图1-2 ESP8266子系统电路

▲ 图1-2 ESP8266子系统电路

▲ 图1-3 接口电路

▲ 图1-3 接口电路

▲ 图1-4 USB下载电路接口

▲ 图1-4 USB下载电路接口

2、接口说明

根据下图所示的Arduino管脚的定义,结合前面的原理图设计,可以分别确定按键LED模块舵机语音模块人脸模块ESP8266模块的接口

▲ 图2-1 Arduino 管脚定义

▲ 图2-1 Arduino 管脚定义

(1)按键接口

按键的行扫描与列扫描分别使用 D4D5D6D7D8D9D18D19。键盘的读取参考程序参见:

/*
**==============================================================================
** TESTKEY.C:             -- by Dr. ZhuoQing, 2021-05-25
**
**==============================================================================
*/

//------------------------------------------------------------------------------

#define KEYLINE_1       4
#define KEYLINE_2       5
#define KEYLINE_3       6
#define KEYLINE_4       7
#define KEYCODE_1       8
#define KEYCODE_2       9
#define KEYCODE_3       18
#define KEYCODE_4       19

#define KEY_NULL        0xff
#define KEY_1           0x47
#define KEY_2           0x4B
#define KEY_3           0x4D
#define KEY_4           0x37
#define KEY_5           0x3B
#define KEY_6           0x3D
#define KEY_7           0x27
#define KEY_8           0x2B
#define KEY_9           0x2D
#define KEY_0           0x17
#define KEY_A           0x4E
#define KEY_B           0x3E
#define KEY_C           0x2E
#define KEY_D           0x1E
#define KEY_E           0x1D
#define KEY_F           0x1B

void keyLineSet(unsigned char ucLine) {
    if(ucLine & 0x1)    digitalWrite(KEYLINE_1, HIGH);
    else digitalWrite(KEYLINE_1, LOW);
    
    if(ucLine & 0x2)    digitalWrite(KEYLINE_2, HIGH);
    else digitalWrite(KEYLINE_2, LOW);
    
    if(ucLine & 0x4)    digitalWrite(KEYLINE_3, HIGH);
    else digitalWrite(KEYLINE_3, LOW);
    
    if(ucLine & 0x8)    digitalWrite(KEYLINE_4, HIGH);
    else digitalWrite(KEYLINE_4, LOW);        
}

void keySetup(void) {
    pinMode(KEYLINE_1, OUTPUT);
    pinMode(KEYLINE_2, OUTPUT);
    pinMode(KEYLINE_3, OUTPUT);
    pinMode(KEYLINE_4, OUTPUT);
    pinMode(KEYCODE_1, INPUT_PULLUP);
    pinMode(KEYCODE_2, INPUT_PULLUP);
    pinMode(KEYCODE_3, INPUT_PULLUP);
    pinMode(KEYCODE_4, INPUT_PULLUP);        
    
    keyLineSet(0x0);
}

unsigned char keyReadCode(void) {
    keyLineSet(0xe);
    if(keyCode() != 0xf) return 0x10 | keyCode();
    
    keyLineSet(0xd);
    if(keyCode() != 0xf) return 0x20 | keyCode();
    
    keyLineSet(0xb);
    if(keyCode() != 0xf) return 0x30 | keyCode();
    
    keyLineSet(0x7);
    if(keyCode() != 0xf) return 0x40 | keyCode();
    
    return 0xff;
}

unsigned char keyCode(void) {
    unsigned char ucCode;
    ucCode = 0x0;
    if(digitalRead(KEYCODE_1) == HIGH) ucCode |= 0x1;
    if(digitalRead(KEYCODE_2) == HIGH) ucCode |= 0x2;
    if(digitalRead(KEYCODE_3) == HIGH) ucCode |= 0x4;
    if(digitalRead(KEYCODE_4) == HIGH) ucCode |= 0x8;
    return ucCode;
}

//------------------------------------------------------------------------------
unsigned char Hex2Text(unsigned char ucCode) {
    if(ucCode < 10) {
        return '0' + ucCode;
    }
    
    return 'A' + ucCode - 10;

}

void SendHEX8(unsigned char ucCode) {
    Serial.write(Hex2Text(ucCode >> 4));
    Serial.write(Hex2Text(ucCode & 0xf));
}

//------------------------------------------------------------------------------
void setup(void) {
    Serial.begin(115200);
    keySetup();
    
}

//------------------------------------------------------------------------------
void loop(void) {
    delay(250);
    
    SendHEX8(keyReadCode());
    Serial.write("\\r\\n");
}

//==============================================================================
//                END OF THE FILE : TESTKEY.C
//------------------------------------------------------------------------------

(2)点阵LED模块接口

控制点阵LED模块的四个IO口分别为 D14D15D16D17

对于LED模块控制参考程序为:

/*
**==============================================================================
** TESTLED.C:             -- by Dr. ZhuoQing, 2021-05-25
**
**==============================================================================
*/

#define LED_DATA1       14
#define LED_DATA2       15
#define LED_CLK1        16
#define LED_CLK2        17

//------------------------------------------------------------------------------
unsigned char g_ucLEDBuffer[4][16];

void ledSetup(void) {
    int i, j;
    for(i = 0; i < 4; i ++) {
        for(j = 0; j < 16; j ++) {
            g_ucLEDBuffer[i][j] = 0x0;
        }

    }

    pinMode(LED_DATA1, OUTPUT);
    pinMode(LED_DATA2, OUTPUT);
    pinMode(LED_CLK1, OUTPUT);
    pinMode(LED_CLK2, OUTPUT);        
    
    digitalWrite(LED_CLK1, HIGH);
    digitalWrite(LED_CLK2, HIGH);
    digitalWrite(LED_DATA1, HIGH);
    digitalWrite(LED_DATA2, HIGH);
    
}

void ledSetData12(unsigned char ucData12) {
    if(ucData12 & 0x1) 
        digitalWrite(LED_DATA1, HIGH);
    else digitalWrite(LED_DATA1, LOW);
    
    if(ucData12 & 0x2) 
        digitalWrite(LED_DATA2, HIGH);
    else digitalWrite(LED_DATA2, LOW);
}

void ledClock1(void) {
    digitalWrite(LED_CLK1, HIGH);       // clock up 7us
    digitalWrite(LED_CLK1, LOW);
}

void ledClock2(void) {
    digitalWrite(LED_CLK2, HIGH);
    digitalWrite(LED_CLK2, LOW);
}

void ledStart(void) {
    digitalWrite(LED_DATA1, LOW);
    digitalWrite(LED_DATA2, LOW);
    digitalWrite(LED_CLK1, LOW);
    digitalWrite(LED_CLK2, LOW);
    
}

void ledStop(void) {
    digitalWrite(LED_DATA1, LOW);
    digitalWrite(LED_DATA2, LOW);

    digitalWrite(LED_CLK1, HIGH);
    digitalWrite(LED_CLK2, HIGH);
    digitalWrite(LED_DATA1, HIGH);
    digitalWrite(LED_DATA2, HIGH);
    
}

void ledWriteData(unsigned char ucChar1, unsigned char ucChar2,
                  unsigned char ucChar3, unsigned char ucChar4) {

    unsigned char i;
    unsigned char ucMask;
    
    ucMask = 0x1;
    
    for(i = 0; i < 8; i++) {
        if(ucChar1 & ucMask) digitalWrite(LED_DATA1, HIGH);
        else digitalWrite(LED_DATA1, LOW);            
        if(ucChar2 & ucMask) digitalWrite(LED_DATA2, HIGH);
        else digitalWrite(LED_DATA2, LOW);            
        
        digitalWrite(LED_CLK1, HIGH);       // clock up 7us
        digitalWrite(LED_CLK1, LOW);
        
        if(ucChar3 & ucMask) digitalWrite(LED_DATA1, HIGH);
        else digitalWrite(LED_DATA1, LOW);            
        if(ucChar4 & ucMask) digitalWrite(LED_DATA2, HIGH);
        else digitalWrite(LED_DATA2, LOW); 
                   
        digitalWrite(LED_CLK2, HIGH);       // clock up 7us
        digitalWrite(LED_CLK2, LOW);
        
        ucMask = ucMask << 1;
        
    }

}

//------------------------------------------------------------------------------
#define LEDCMD_ADD_INC          0x40
#define LEDCMD_ADD_SET          0x44
#define LEDCMD_MODE_CLOSE       0x80
#define LEDCMD_MODE_OPEN        0x8a

//-------------------------------------------------------以上是关于基于Arduino ATmega328人脸识别IOT演示开关的主要内容,如果未能解决你的问题,请参考以下文章

Arduino Uno微控制器采用的是Atmel的ATmega328

基于ATMEGA8的Arduino Nano(UNO)开发板

我在将arduino网络中实现Atmega328计时器时遇到问题

Atmega328 模数转换器

使用 UDRE 和 ATmega328P 的中断驱动 USART

ATMEGA328P使用内部8MRC振荡器(2015-07-05 19:50:49)