After 3 months of continuous exploration, I finally completed the project practice content of the second phase of the 91arm Academy (the code in the video tutorial is not complete). I saved the relevant experience and code here for reference by myself and my classmates.
System Hardware:
Main control module: nanopi s2 (cortex-A9 quad-core s5p4418), 5v to 3.3v module, light sensor, sound sensor, 5v relay, breadboard and LED light, serial port to USB debugging interface, etc.
Wireless network module: tiny6410 (ARM11 Samsung S3C6410), infrared sensor, relay, breadboard and LED light
Let's look at the overall effect first. The main control program is znkg2018 and the network program is net_light
The main control and network end programs are as follows:
The web browser interface is as follows:
The main ideas of this project:
(1) The main control program znkg2018 (cross-compiled and ported to nanopi s2) contains four threads:
Thread 1: (used for inter-process communication) loops through shared memory and message queue data, and updates shared memory data to the main data structure memory in real time according to the message type of the message queue, or updates the main data structure memory to the shared memory;
Thread 2: (used to detect device online and offline) cyclically reads the data of the GPIO port of the development board connected to the 5V to 3.3V module. A high level indicates that the corresponding sensing device is connected to the system, and the level status of the GPIO port connected to the data line of the device can be read (the 5V to 3.3V module and the power line of the sensing device are connected together to achieve simultaneous plugging and unplugging, so that the plugging and unplugging of the corresponding sensing device can be detected through this thread);
Thread 3: (used to listen to the connection of network devices) This thread is the network server. First, it establishes a TCP data stream (socket~bind~listen ~ accetp) to loop and listen to the connection request of the network client. After receiving the request, it opens a new thread to communicate with the client, updates the network device status in the main data structure according to the client data, and sends corresponding commands to the network device according to the network device status in the main data structure. Network communication is based on the protocol, which is convenient for command classification and transmission verification.
Thread 4: (For lighting equipment switch control) This project has three small lights, two on the main control end and one on the network end. The switches are all controlled by relays, simulating 220V living room, study and office (remote) lights. Loop through the switch status of the lighting equipment in the main data structure, send write data commands to the corresponding relays to control the light switches. If the sensing device is bound to the lighting device, read the gpio port data of the sensing device and write the data to the gpio port of the relay. The network device only updates the network command status value, which is sent out by process three, and then processed by the network end program and controls its relay gpio, thereby controlling the corresponding light switch.
(2) The network client program net_light (cross-compiled and ported to tiny 6410) is just a main program:
The program connects to the network thread of the main control program on nanopi through the IP and port number, and updates the corresponding device status according to the network commands sent by the main control program.
(3) CGI program running on the boa server on nanopi:
After installing the boa server on nanopi, you can access the cgi program in nanopi through a browser. Put the index.html file in the www folder of boa, which is the welcome interface. The options in it are connected to different cgi programs. These programs open the shared memory and message queue managed by the main control program. By modifying the form and extracting the data in the form, updating the shared memory data, and notifying the main control device to update the shared memory or update the data in the shared memory to the main data structure memory through the message queue. After the main data structure memory is modified, the four threads of the main control device will take corresponding actions.
The editor uses the recommended source insight, which can automatically derive the declaration of variables and functions and their references to each other, making it easier to write and analyze programs (but the encoding format of the software I use is Ascill, not UTF-8, so it is garbled when compiled. It is OK to convert the encoding format with note pad ++)
Previous article:The most complete ARM instruction set in history
Next article:Answers to common questions for ARM embedded system beginners
Recommended ReadingLatest update time:2024-11-17 06:01
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- My EEWorld 2018 year-end summary @ [chat, laugh, make noise]
- Microsoft Vista reveals how to modify power management PC switches like home appliances
- Application of Embedded Target Module in DSP System Development
- Share the open source information of the creative Coke power bank I collected, including schematics, PCB, and code
- Real-time control technologies meet the demands of real-time industrial communications – Part 3
- Share a STMF105RBT6 and 103RCT6_keil_C++ source program
- MSP430 MCU Example 3 - Colored Light Control
- EEWORLD University-What is an isolated gate driver?
- Burning image and mounting USB disk with busybox file system failed
- Switching Circuit