MartinFowler

[Training Camp_Advanced Class] OLED Smart Socket

 
Overview

write in front

1. If anyone is interested in this sensor project and plans to make it by himself, please read the "8. Known Issues" section of this article carefully. If you have any questions, please communicate with me.

2. The code is being refactored, and will be released after the refactoring is completed (gu gu gu).

3. There are 4 empty boards left. If you need them, please contact me and I will pay for the postage.

OLED three-hole smart socket

Rendering

image.png

Physical map

image.png

Physical picture with shell

image.png

image.png

image.png

1. Characteristics

Design load 2000W

3 independent jacks

OLED multi-level menu

EC11 encoder control

Button quick control

Alibaba Cloud Internet of Things

2. Application examples

1. Welding workbench

When performing welding operations, you need to use air guns, soldering irons, exhaust fans and other equipment. The total power of these equipment is not high, and misoperation will not cause serious effects. After connecting these equipment to this smart socket, you can use the The button can be used to quickly switch on and off, which can record the duration of welding operations and shut down the equipment regularly to avoid burning the equipment due to long-term power-on due to forgetfulness.

2. Smart aquarium

Using this smart socket, you can transform the aquarium into a smart aquarium with functions such as automatic feeding, automatic oxygenation, automatic water change, and light management.

3. Design Key Points

1. Strong current part

(1) Use 10A 5*20 fuse for protection

(2) Slotting to prevent electricity creepage

(3) Opening windows and applying tin to increase overcurrent capability

(4) Use card-type embedded sockets and integrate the sockets onto the board by welding

2. Weak current part

(1) WiFi module is powered separately

(2) Use ACDC module HLK-5M05 to convert AC 220V into DC 5V to power the control system

(3) Button hardware debounce processing

(4) Interaction using a combination of OLED and EC11

3. Program part

(1) Program layered design to reduce coupling and improve portability

(2) Real-time task scheduler is implemented using timer

(3) Serial port echoes all data, sets triplet, PC to EMW3080 transparent transmission

(4) Multi-level menu

4. Hardware selection

1. MCU minimum system

image.png

The project uses STM32F103C8T6 (product number: C8734) as the main control. This MCU is a relatively low-end product in ST's F1 series. It is extremely cost-effective and is a classic 32-bit MCU.

The BOOT0 jumper is designed to allow the program to be programmed through the serial port.

A reset button is designed to perform a hard reset of the system.

The SWD interface is reserved to facilitate device simulation and program burning.

A button battery slot is reserved, and the function of restoring operation after power failure will be added in subsequent development.

2. WiFi module

image.png

The project uses the EMW3080V2-E WiFi module EMW3080 series recommended by Lingyao, and has an external antenna.

After the ILOP firmware is burned into the module, the MCU can use AT commands to access the Alibaba Cloud Feiyan platform through the serial port.

3. USB to serial port circuit

image.png

The USB to UART chip is CH340E (product number: C99652) in MSOP10 package. The chip is extremely small and has a built-in crystal oscillator.

The USB interface chooses the 16pin type-C (product number: C393939) interface, which is easy to find matching wires.

4. SPI FLASH memory chip

image.png

Use W25Q32 (product number: C179173) to store configuration information, fonts, and picture data.

You need to pay attention to the packaging type when purchasing.

5. DS1302 clock chip

image.png

In order to develop functions that allow the device to be used normally when offline, the circuit of the DS1302 real-time clock chip is reserved.

You need to pay attention to the packaging type when purchasing.

6. OLED display module

image.png

A 7pin 0.96-inch 128*64 resolution OLED is used as the display screen, and with multi-level menus, it can display rich content.

7. 5V to 3.3V

image.png

ASM1117 is used to convert the filtered 5V power supply into 3.3V to power the microcontroller, OLED, serial port chip and wifi module.

WiFi module is powered separately.

8. Indicator light

image.png

The product has an opaque shell, and long-legged LEDs are used as status indicators to display the system status to the outside through the reserved holes in the shell.

9. Buttons

image.png

The tact switch with a button model of 6*6*22 uses an RC circuit for hardware filtering. (The resistance and capacitance values ​​still need to be adjusted)

10. EC11 rotary encoder

image.png

EC11 adopts the model with extended plum blossom handle, and the AB phase and buttons use RC circuit for hardware filtering. (The resistance and capacitance values ​​still need to be adjusted)

11. Socket control circuit (partial)

image.png

Use relay SRD-05VDC-SL-C (No. C35449) to isolate the AC220V controlled circuit and the 5V control circuit.

Use the inductive load driver chip NUD3105 (product number: C146811) recommended by Lingyao to drive the relay.

An LED indicator light is designed, and the indicator light will also light up when the normally open contact of the relay is closed.

Actual picture of card-embedded socket:

image.png

Socket connection: https://item.taobao.com/item.htm?spm=a1z0d.6639537.1997196601.44.24dc7484EByGt5&id=559327402212

12. 220V to 5V ACDC circuit

image.png

Use HLK-5M05 ACDC finished module (product number: C209907) to convert 220V mains power into 5V DC power supply.

HLK-5M05 physical picture:

image.png

Power consumption estimate:

Relay (SRD-05VDC-SL-C): 0.36W*3 = 1.0W

image.png

WiFi module (EMW3080V2-E): 300mA*3.3V = 1.0W

image.png

STM32 minimum system: 363mA*3.3V = 1.2W

image.png

Total: 3.2W

HLK-5M05 has a load capacity of 5W, with enough margin

5. PCB Layout

image.pngimage.png

6. Program structure

1. Program level

program level abbreviation full name illustrate example
application layer APL Application Layer Business logic
Function module layer FML Functional Module Layer In unit of function module Read and write files
Hardware module layer HML Hardware Module Layer Taking hardware modules as units, the functions of the hardware modules are encapsulated into functions. SD card
hardware abstraction layer HAL Hardware Abstract Layer Encapsulate microcontroller peripherals into platform-independent interfaces SPI
Hardware driver layer HDL Hardware Driver Layer Simply encapsulate library functions (can be omitted) Bitband operation
Board support package BSP Board Support Package Library functions provided by the manufacturer, similar to the STD library of STM32 STD library
System function library SLB System Library Standard library or some functions similar to the standard library implemented by yourself stdint.h

image.png

The program is divided into six levels: APL, FML, HML, HAL, HDL, BSP and a System Library.

image.png

The upper layer calls the lower layer resources through the limited interface opened to the upper layer by the lower layer, and the lower layer triggers the upper layer response by calling back the functions registered by the upper layer.

Extensive use of callback functions to isolate the upper layer from the lower layer

2. Simple real-time task scheduler

Use a timer to generate an interrupt of 1k~~~~Hz, and query whether there are tasks that need to be executed in the interrupt. In principle, time-consuming tasks will not be executed.

Task types are:

image.png

This is achieved through the following functions:

image.png

Create a task instance:

image.png

3. OLED Chinese display, Chinese and English mixed display, graphic and text mixed display, etc.

Based on the routines given by Zhongjingyuan, the OLED driver library has been improved, the Chinese character display mode has been modified, and functions such as mixed display of Chinese characters and English, and mixed display of icons and texts have been added.

Chinese character library

image.png

Chinese character display:

image.png

Through traversal, the data of the current Chinese character is retrieved in the Chinese character font and displayed on the OLED. Currently, it is still troublesome to establish the Chinese character font. In the future, it is considered to put the GB2312 Chinese character font into the W25Q32 chip.

Mixed display of Chinese and English:

image.png

4. Implementation of multi-level menu

Five structures are designed to store menu information. The member type of item_t identifies the type of this form. The optional types include menuForm_t menu window type, settingForm_t setting window type, showForm_t display window type and operation_t operation type. The member name of item_t identifies the name of this form, which will be displayed in its parent window. The member obj of item_t points to the window structure.

image.png

7. Production process

1. Hardware welding

(1) Plug-in placement test

In order to avoid the embarrassment of not being able to solder the plug-in due to packaging problems after the patch components are soldered, place the plug-in on the PCB for testing before welding. If serious packaging errors are found, the PCB needs to be redrawn.

image.png

(2) 3D printing “steel mesh”

Using 3D printing technology, a 3D printed "stencil" for applying solder paste was printed. 3D printed "stencil" tutorial https://www.bilibili.com/read/cv6741734 .

image.png

(3) Apply solder paste

Use a scraper to evenly apply the solder paste to the PCB through the "steel mesh".

image.png

(4) Place chip components

image.png

(5) Welding on the heating table

Adjust the temperature of the heating table to 250°C, place the PCB with the solder paste and the original components on it smoothly across a piece of A4 paper. Heat it until all the solder paste turns into shiny solder joints, then use tweezers and other tools to remove it smoothly. , put it in a ventilated place to cool. Tweezers can be used to fine-tune components during the heating process, especially to solve the problem of component tombstones.

image.pngimage.png

(6) Repair soldering with soldering iron

The precision of the 3D printed "steel mesh" is not high, and the uneven thickness of the solder paste may cause the pins to have joint soldering and other problems. A soldering iron needs to be used to deal with joint soldering, virtual soldering, etc.

image.png

(7) Plug-in welding

image.png

(8) Tinning the window pad

(9) Power-on test

image.png

(10) Clean PCB

2. 3D model production & shell production

For 3D model creation tutorials, see: Creating 3D models and rendering for LCEDA projects https://www.bilibili.com/read/cv6758801

A 3D model was created for the component for which the 3D model could not be found:

image.pngimage.png

8. Known issues

1. STM32 external interrupt line conflict

Problem: EC11 encoder item B is connected to the PA7 pin of STM32, and button 2 is connected to the PB7 pin of STM32. Both correspond to the EXTI_Line7 interrupt line, so they cannot use external interrupts at the same time.

Solution: In order to accurately obtain the EC11 input, the program uses two external interrupts to detect the AB phase of the EC11 encoder respectively. Therefore, the detection intelligence of button 2 is realized through polling detection. The program uses a real-time task that triggers once every 1ms to detect the corresponding button 2. The level of pin PB7 simulates the effect of external interrupt

2. The relay closes when power is turned on.

There is a problem with the relay drive circuit. When the STM32 is powered on, the IO port is in a high-impedance state, the normally open contact of the relay is closed, and the socket is connected. The improved circuit can avoid this situation. image.png

3. OLED packaging error

There is a problem with LCEDA's 0.96-inch OLED packaging. Common OLED modules on the market are not compatible. There is also a problem with the 3D packaging. It is suspected to be a 1.3-inch OLED 3D model.

4. LED pin length is insufficient

The LED pins must be at least 45mm long to protrude from the housing display. The blue and green LED pins are not long enough and need to be connected to another length.

image.png

5. The firmware version of EMW3080 Alibaba Cloud direct connection is too low.

Question: Refer to the program of Lingyao and the documents of Qingke official website to send AT commands to EMW3080. EMW3080 can return the information normally, but cannot enter the network distribution mode.

Solution: Use the AT command AT+FWVER? to check the EMW3080 firmware version number is 2.2. Try to upgrade the firmware and use it normally.

Firmware flashing tutorial: https://www.yuque.com/lingyao/jing/isdnec

Flying line flash firmware:

image.png

Firmware flashing successful:

image.png

The first network distribution was successful:

image.png

6. No test points left

Test points should be set aside to facilitate program debugging. For example, the serial port between STM32 and EMW3080 should lead to test points to facilitate debugging and programming of EMW3080.

9. Project related

1. If there are physical components, use 3D printing to verify the packaging before making the board.

2. Print part of the shell and conduct preliminary experiments to verify whether the shell is usable.

10. Demonstration video

参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-15 01:49:04

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号