800 views|0 replies

19

Posts

3

Resources
The OP
 

【DigiKey Creative Contest】Realization of Porch Light - Work Submission [Copy link]

 

Work title: Realization of porch lights
Author: Your family eats

Introduction of a work

This work is a realization of a self-made intelligent control module center. It mainly uses stm32mp1 as the control center. As a development board, it has a good integration and a comprehensive network module. It uses the wired network of the development board to create a TCP server and realize 100 client locations, which is convenient for future control module expansion.

The control center sends control commands to control the lighting effects of the porch lights.

The controlled module designed is a porch light module. The module uses an esp32 chip. In addition to basic lighting effect control, it also uses the wireless function of the module to create a TCP client, connect to the control center, and receive control instructions from the control center.

Currently, the lighting effects can be displayed in digital form. You can continue to expand the lighting effects according to your preferences in the future.

2. System Block Diagram

The porch light control chip and the porch light are integrated into a module to realize the main functions. After creating the client, it always monitors the control instructions sent by the server and realizes the corresponding lighting effects.

After the control center creates the server, it receives commands input by the user. Currently, it uses the console to input control commands and sends the commands to the first client handle.

The following is the module diagram of the porch light, which mainly has an ESP32 chip and a 4*5 light panel. The light uses ws2812b lamp beads, and one line can control all the lights. A MOS tube is designed to turn the light on and off. However, during the test, it was not debugged, so the MOS tube was temporarily shorted and the switch function of the light panel was deleted.

3. Functional description of each part

3.1 Control Center

The STM32MP157 development board is used. The STM32MP157 is a dual-core main processor + real-time coprocessor SoC. The main processor uses ARM Cortex-A7, the frequency can reach 650MHz, and the real-time coprocessor uses Cortex-M4, the frequency can reach 209Mhz. It supports up to 1GByte of DDR3/3L and has Gigabit Ethernet. Components other than Cortex-A7 and Cortex-M4 are called external peripherals or on-chip peripherals. For example, GPIO, USART (serial port), I2C, SPI, etc. are all called on-chip peripherals.

The main functions in the above figure can be classified into: Cortex A7 core, Cortex M4 core coprocessor, bus, volatile storage, persistent storage, clock, timer, power management, high-speed communication, low-speed communication, network, multimedia, analog signal processing, LCD controller, security and IO input and output, etc.

3.2 esp32

The porch light module uses the ESP32WROVERE module. The ESP32-WROVER universal Wi-Fi + Bluetooth + Bluetooth LE MCU module is powerful and versatile. It can be used for low-power sensor networks and demanding tasks such as voice encoding, audio streaming, and MP3 decoding. It uses a PCB onboard antenna. The CPU clock frequency can be adjusted from 80 MHz to 240 MHz. Users can turn off the power of the CPU and use the low-power coprocessor to monitor the state changes of peripherals or whether certain analog quantities exceed the threshold. ESP32 also integrates a wealth of peripherals, including capacitive touch sensors, SD card interfaces, Ethernet interfaces, high-speed SPI, UART, I2S, and I2C. Wi-Fi supports a wide range of communication connections and also supports direct connection to the Internet through a router; while Bluetooth allows users to connect to mobile phones or broadcast Bluetooth LE Beacons for signal detection. The sleep current of the ESP32 chip is less than 5 A, making it suitable for battery-powered wearable electronic devices. The module supports data transmission rates up to 150 Mbps, and the antenna output power reaches 20 dBm, which can achieve the maximum range of wireless communication. Therefore, this module has industry-leading technical specifications and excellent performance in terms of high integration, wireless transmission distance, power consumption, and network connectivity. The module block diagram is as follows.

The design block diagram of esp32 is as follows, realizing a minimum system.

The number of lamp beads designed is 4*9 matrix lamp panel, and 4*5 are currently used to realize digital display. The block diagram is as shown below.

The power supply part is designed as follows, using the power supply of the type-c interface and the ams1117-3.3 chip to obtain a 3.3 volt voltage to power the esp32.

4. Source Code

Embedded software source code:

Porch light code.zip (32.51 KB, downloads: 0)

Upper computer software source code:

控制中心code.zip (20.78 KB, downloads: 0)

Porch Light Hardware Schematic

WS2812B-硬件原理图.zip (6.69 MB, downloads: 0)
创建tcp服务器

int createTcpSvr()
{
    logINO("ql_socket_service_create--");
    int ql_socket_id = 0;
    char ret = 0;
    int sk_port = 1111;

    /**************creat socket handle**********/
    if((ql_socket_id = socket(AF_INET,SOCK_STREAM,0)) < 0){
        perror("socket");
        return -1;
    }
    /**********************set socket addr reuse**********************/    
    int reuseaddr = 1;
    if(setsockopt(ql_socket_id, SOL_SOCKET, SO_REUSEADDR,(const void *)&reuseaddr,(socklen_t)sizeof(int)) == -1){
         perror("setsockopt\n");
         logRED("setsockopt----errno[%d]",errno);
         return -1;
    }else{
        printf("setsockopt\n");
    }

    /********************set socket property*************************/
    struct sockaddr_in service_addr;
    bzero(&service_addr,sizeof(service_addr));
    service_addr.sin_family=AF_INET;
    service_addr.sin_port=htons(sk_port);
    service_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    /**********************bind socket addr and port**********************/
    if (bind(ql_socket_id,(struct sockaddr *)&service_addr,sizeof(struct sockaddr)) == -1){
        perror("bind");
        return -1;
    }else{
        logGRE("bind success--sk_port[%d]",sk_port);
    }
    if(listen(ql_socket_id, PENDING_QUEUE) == -1){
        perror("listen");
        return -1;
    }else{
        logGRE("listen success");
    }    
    return ql_socket_id;
}
实现控制指令的下发

void ParsrPorchLightMode(char* inputStr)
{
	logWHI("ParsrPorchLightMode [%s]",inputStr);
	if(netInfo[1][1]){
		send(netInfo[1][0],inputStr,1,0);
	}
}
实现循环检测客户端的断连	

while(1){
        tempo_tv = dl_tv;
        FdsTempR = client_rset;    
        FdsTempW = client_wset;

        fdsFlag = select(maxFd+1,&FdsTempR,&FdsTempW,NULL,&tempo_tv);
        memset(data_buffer,0,DATA_BUF);
        switch(fdsFlag)
        {
        case -1:
            logPURP("error data len[%d]",fdsFlag);
            return -1;
        case 0:
            logPURP("time out ");
            break;
        default:
            if(FD_ISSET(netInfo[0][0],&FdsTempR)){
				logPURP(" there one client connected");
				new_sk = accept(netInfo[0][0] ,(struct sockaddr*)&CliInfo,&CLiLen);
				inet_ntop(AF_INET,&CliInfo.sin_addr,(char*)MyIP,IP_LEN);
				MyPort = ntohs(CliInfo.sin_port);
				logPURP(" there is a new client,fd[%d][%s][%d]",new_sk,MyIP,MyPort);
				for(int i = 0;i < FD_CNT;i++){
					if(netInfo[i][1] == 0){
						netInfo[i][0] = new_sk;
						netInfo[i][1] = 1;
						maxFd = new_sk > maxFd?new_sk:maxFd;
					    FD_SET(new_sk, &client_rset);
					    FD_SET(new_sk, &client_wset);

						break;
					}
				}
			}else{
				for(int i = 1;i < FD_CNT && netInfo[i][1];i++){
					if(FD_ISSET(netInfo[i][0],&FdsTempR)){
		                rec_len = recv(netInfo[i][0],data_buffer,DATA_BUF,0);
		                switch (rec_len)
		                {
		                case -1:
		                     logPURP(" error[%s]errno[%d]",strerror(errno),errno);                    
		                     return -1;
		                 case 0:
						 	netInfo[i][1] = 0;
							FD_CLR(netInfo[i][0], &FdsTempR);    
							FD_CLR(netInfo[i][0], &FdsTempW);    
		                    logPURP("client socket diconnect!!!sk[%d]",netInfo[i][0]);
		                    break;
		                default:
		                    logPURP("rec_len [%d]data_buffer[%s]",rec_len,data_buffer);
		                    break;
		                }
					}
		        }
			}
		}
	}
获取键盘输入,并发送数据到第一个客户端

void server_operate_cmd(void* buff)
{
	logWHI("server_operate_cmd");
	char inputStr[64] = {0};
	while(1){
		scanf("%s", inputStr);
		logWHI("inputStr [%s]",inputStr);
		ParsrPorchLightMode(data_buffer);
	}
}

5. Demonstration video of the work’s functions

d6b54212ebf06320e9320708e3214892

6. Project Summary

This event was great, but I was a bit rushed because I was on a business trip, which wasted a lot of time. After returning from the trip, I hurriedly started writing code, implementing hardware welding and code debugging, as well as the implementation of the control center. Especially the burning of esp32, which took several days. In the end, I found that it was my serial port version that was faulty. It was a very simple and stupid fault. To be honest, the wireless module of esp32 is really well implemented, and it can quickly and easily implement the network.

The structure of this project is relatively simple. The code for the porch light is relatively easy to implement. The control center only needs to send the control command. There is no design for the control protocol, and it is sent directly in plain text.

With a little modification, you can control the porch light with your phone. It is convenient and quick to turn on the porch light with one click before going home.

At the end of the report, I would like to express my gratitude to DigiKey and EEWORLD for organizing this event, providing a platform for many electronics enthusiasts and professionals, and helping the majority of electronics ers to realize their ideas.

智慧门廊灯的实现.doc

637.5 KB, downloads: 3

This post is from DigiKey Technology Zone
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list