Shenzhen ZTRON Microelectronics Co., Ltd
Telephone
0755-8299 4126

Internet of things

Bluetooth remote control PCBA design and development


In recent years, with the rapid rise of smart phones, Bluetooth remote controls should greatly change our way of life. Mobile phones are no longer just for making calls and sending text messages as in the past. We pay more attention to leisure and entertainment functions, making most people inseparable from mobile phones. Among them, Android mobile phones have become the sweet pastry among smart phones, accounting for more than 70% of the market. Google has open sourced it, providing a good development space for many manufacturers and developers. For computers, the mouse seems to be an indispensable partner, but in many occasions, such as business trips, tourism and other occasions, it is not very convenient to directly carry and use the mouse. This paper designs a mobile phone Bluetooth controller, through which the computer and the Android mobile phone are connected, and the basic functions of the mouse can be realized directly through the mobile phone.


1. The overall design of the Bluetooth remote control


The functions to be realized mainly include: 1) Mobile phones with bluetooth function: Generally speaking, most mobile phones now have bluetooth function. This is commonly referred to as the client, and an app is designed on it to obtain the data of the desired computer action, and then send the data to the server via Bluetooth. 2) The hardware part with Bluetooth receiving function: there must be a slave terminal, which is used to directly connect with the mobile phone, and directly receive the data sent by the mobile phone; then forward these data to the controller, and use the controller to analyze data. 3) Controller part: used to analyze the data transmitted by the Bluetooth module, and this part must also be connected to the computer, send these data to the computer through the USB communication protocol, and communicate directly with the computer in real time to achieve our control Purpose. 4) Personal computer: This is the part we want to control. The whole structure is shown in Figure 1.


图 1 蓝牙遥控器系统结构框图


2. Bluetooth remote control system hardware design


If you directly use the Bluetooth adapter of the wireless mouse, this is the most direct and convenient hardware part, which is to replace the wireless mouse with the mobile phone. But it is not easy to implement. Generally, each wireless mouse has a specific Bluetooth adapter in order to eliminate the interference of other Bluetooth devices. That is to say, they have a one-to-one relationship, and you need to know the communication protocol between the Bluetooth adapter and the specific mouse.


If you directly use a general-purpose USB adapter to communicate with the computer, the computer USB port has already implemented L2CAP, SDP, RFCOMM communication protocols, but under this protocol, you must have your own computer client driver. This design uses a combination of software and hardware, and uses a Bluetooth module + controller to realize the wireless mouse adapter function, making the function more simple and reliable.


2.1 Bluetooth module design


The Bluetooth module is connected to the mobile phone as a slave device, and has a serial port to send data back to the controller. The Bluetooth module used in this design does not have strict requirements. In terms of speed, after setting the baud rate to 115200, it is completely sufficient for transmitting a small amount of data. Power is also not as demanding as wearables. The effective distance is within 20 meters. Therefore, under the comparison of performance and price, I chose HC-05 with master-slave mode, which has full functions and low price. The LED light on the PIO8 pin will show the current state of the Bluetooth. If it flashes once, it means that it is not connected normally. If it flashes twice, it means that the Bluetooth has been successfully connected.


As a transfer station for data, the microcontroller is most simply processed by a 51 single-chip microcomputer. However, there are not too many resources in the single-chip microcomputer, and the data processing speed is not fast enough. So choose the embedded chip: STM32F103RCT6 as the controller chip. Including, read out the data sent back from the HC-05 serial port frame by frame by interrupting the serial port, and then take out the information such as the position and keys inside, and send the data out after establishing USB communication with the computer to complete the control process. The function of this chip is to use the serial port interrupt 1 to receive data from the Bluetooth serial port, and send the data to the computer through USB. Interface; Bluetooth serial port output RXD, TXD connected to PA9, PA10 of the chip respectively.


3. Bluetooth remote control software design


Currently, there are several Android software design platforms. The official development platforms launched by Google include Eclipse and Android studio. The Android software platform used here is: Eclipse. The mobile phone client is the key link. First, it needs to establish a data path with the Bluetooth module, so that data can be transmitted between them without hindrance. Then, the distance moved by the finger on the mobile phone screen and the status of each button can be obtained in real time, and sent to the Bluetooth module.


The idea of the interface design is: first, there must be several pages that can be switched. After connecting the Bluetooth module, we can switch to the mouse control or PPT page turning interface at any time. The connection status of Bluetooth. In order to make the interface more beautiful, Fragment+Tab is used as the main interface. The function of Tab is to locate and switch the Activity, just like the switch under WeChat. The entire main interface uses 3 interfaces, namely mou semov.xml (mouse sliding layout), pptlayout.xml (PPT page turning sliding layout), and settinglayout.xml (setting page layout).


Functional design: switch to the setting interface, immediately obtain the Bluetooth instance of the Android system, and then call the method of connecting other Bluetooth devices in the Bluetooth adapter. After using this method to connect to the target device, obtain the target Bluetooth address and use this address Establish the socket channel, the communication method of the socket is to directly use the data stream to read and write data, after the socket channel is established, the data can be directly converted into the form of Byte[] byte array, and then sent to the Bluetooth module.


Establishing a Bluetooth connection: To establish a Bluetooth connection, the Bluetooth service of the system must be invoked first. In Android, if you want to invoke security-related services, you must apply for system permissions in the AndroidManifest.xml file, and you can only operate after obtaining the permissions. .


Mouse program: The program of mouse movement is to obtain the current moving distance of the finger on the screen and the state of the left and right buttons of the mouse, the second is to package and send the data, and the third is to beautify the interface.


4. STM32 programming


The function of the STM32 program is to obtain the data transmitted from the mobile phone, and analyze it, and then send the data to the computer through the USB communication protocol, and the computer will make corresponding actions according to the data you give.


The first is to collect data. STM32 and MCU use serial port interrupts to collect external data, so that it will not consume too many resources and can respond in real time. To enable the serial port interrupt, you must do a series of configuration and initialization of STM32 internal resources, first of all, set the system clock, you can directly call the Stm32_Clock_Init() method under the SYSTEM>sys.c file in the project. After the initialization is completed, as soon as there is data, it will receive and store it in the data buffer of uart, and the data of the mobile phone can be obtained by reading the data in the buffer. The process of sending data to the computer is as follows: first reset the USB interface, then configure the USB interrupt processing method and interrupt priority, enable the USB clock, and initialize the driver required for communication; after completing all these steps, the serial port interrupt program can Send data from the Bluetooth module to the computer.


Summarize


In the market, TeamViewer is used by many people. This software is mostly used for remote control of computers, and mobile phones can also be used for remote control of computers. In fact, most of the principles in it are knowledge of network communication. After the channel, the image screen of the controlled computer will be sent back to the control terminal, and the action of the control terminal will be sent to the controlled terminal after packaging the data frame, and the corresponding action will be realized after the control terminal parses. There are other software such as Cheetah WIFI, which can control the computer through the LAN, the principle is the same as TeamViewer. Most of them are pure software implementations, which are different from the design and implementation principles of this article. You can further consider using the mobile phone to implement some functions of the keyboard, such as the Enter key, the up, down, left, and right keys, and the Esc key.


The above is the development example of the Bluetooth remote control control board introduced by Shenzhen Zuchuang Microelectronics Co., Ltd. for you. If you have Bluetooth remote control PCBA development needs, you can trust us. We represent a variety of single-chip microcomputers, voice chips, dual-mode Bluetooth ICs, and wifi chips. Brands include Songhan MCU, Yingguang MCU, Jerry Bluetooth, Ankai Bluetooth, Allwinner, and Realtek. Our technical services include: PCB design, microcontroller development, Bluetooth solutions, software and hardware custom development, APP development, small program development, WeChat official account development, etc. It can also undertake the design of intelligent electronic products, the development of living appliances, the research and development of beauty equipment, the application of Internet of things platform, the smart home control system, the development of TWS earphones, Bluetooth earphone speakers, the development of children's educational toys, the design of electronic education products, etc.

  • TOP