Design of Control System Based on Bluetooth and Android Devices

The Android operating system is a mobile operating platform developed by Google based on the open source Linux operating system. It consists of an operating system, middleware, user interface and application software. It is an open and complete mobile operating system specially designed for mobile terminals. The Android software platform includes layers such as Java ApplicaTIon, ApplicaTIon Framework, Libraries, RunTIme, and LinuxOS. Users can tailor the system according to the different needs of the product, so as to adapt to a variety of product requirements, the Android system is like a building block to achieve different application products by combining different hardware and software. The emergence of Bluetooth provides a convenient and fast choice for the interconnection of mobile devices. The connection between the Android device and the controller with the microcontroller as a processor complements the functions of the two.

1 system architecture

The control system based on Bluetooth and Android devices consists of an Android device and a lower computer. Android devices (Android smartphones or Android tablets) are installed with specially crafted software. The lower computer is based on ATMEGA 8 of ATMEL's efficient RISC core and integrates the Bluetooth serial module as the communication channel. The Android device sends the data to the lower computer through Bluetooth, and the lower computer completes the corresponding control function according to the received data, and uploads the processing result, realizing real-time monitoring and real-time control functions. The lower computer is only responsible for data collection and implementation control functions, and data storage and processing is implemented on Android devices.

2 lower position machine design

2.1 Control module design

The lower position machine is composed of ATMEAG8, digital temperature sensor, motor drive circuit, etc., and the CPU part circuit is shown in Figure 1. The lower computer processor serial port is connected to the Bluetooth module. The digital temperature sensor converts the current temperature directly into a digital signal. The Bluetooth module is set to slave mode.

Figure 1 CPU circuit schematic

Figure 1 CPU circuit schematic

After the system is powered on, the Bluetooth module is waiting for connection. When the Android device makes a connection request for the first time, it needs to input the built-in password of the Bluetooth module. If you connect later, you do not need to enter a password. Only after the password is successfully matched, the Bluetooth connection can be successfully established. The Bluetooth module is a communication channel between the Android device and the ATMEAG8, and realizes a bidirectional data connection between the Android device and the lower computer. The user sends a command to the lower computer through the Android device, and after receiving the command, the lower computer controls the corresponding execution module to implement the set control function. K1 and K2 are low level, the voltage across the motor is 0V, the motor stops; K1 is high level, K2 is low level, the motor is 5V at both ends, the motor rotates in the positive direction; K1 is low level, K2 is high level The motor is -5V at both ends, and the motor rotates in the opposite direction; K1 and K2 cannot be high at the same time, the motor drive circuit is shown in Figure 2.

Figure 2 Schematic diagram of the motor drive circuit

Figure 2 Schematic diagram of the motor drive circuit

2.2 Bluetooth module

The Bluetooth module model is IDS-BM4A. The module has two master/slave modes. The PIO2 level is used to select the module's operation. PIO2 is high and the module works in slave mode. The module can be used in two ways. Mode 1: The module starts working when the module is powered on. The user can find the module through the Android device. The module device name is “SPP”. After the device is selected, the connection is selected, and the computer will prompt for the password. When you enter "0000", the computer will establish a transparent connection with the module. Mode 2: Two Bluetooth modules are required. One is set to master mode and one is set to slave mode. It is connected to two MCUs respectively. After power-on, the master-slave module will automatically pair and connect. After the connection is successful, the master-slave module will establish transparent data transmission. The two devices can directly send data to each other.

Working status indication: Module PIO0 is used to connect LEDs to indicate the current working mode.

Main mode: not connected, LED flashes 2 times quickly in 1 second interval; connected, LED is always on.

Slave mode: not connected, the LED flashes quickly; connected, the LED is always on.

Connection status indication: Module PIO1 is the connection status indication. When the connection is successful, PIO1 is high, and the connection is disconnected and PIO1 is low.

Baud rate setting table:

3 Android device software design

Android2.2 version or above can support Bluetooth function very well. The application on Android is generally developed in Java language, and the programming environment generally adopts Eclipse.

Android applications require Bluetooth, and two permissions must be requested in AndroidManifest.xml: BLUETOOTH_ADMIN and BLUETOOTH. The specific format is as follows:

"uses-permissionandroid:na

Me=“android.permission.BLUETOOTH”/

The BLUETOOTH_ADMIN permission allows Android apps to launch discovery devices or settings for Bluetooth functionality; BLUETOOTH permissions are permissions that Android applications must have to perform Bluetooth communication, such as accepting connections and transmitting data. Most applications require this permission to find a local Bluetooth device.

Due to the need to connect to the Bluetooth module of the lower computer, the main device function needs to be implemented in the application. The specific connection process is:

(1) Check if the Bluetooth function of the device is enabled in the application, if it is not enabled, turn on the Bluetooth function;

(2) Find a Bluetooth device waiting to be connected near the device, and display the physical address of the found Bluetooth device (the device that has not been connected before) or the name of the Bluetooth device;

(3) Select the Bluetooth device you want to connect to. If the target device is connected for the first time, the system will automatically initiate a pairing process. The dialog box for entering the connection password will pop up, enter “0000”, wait for the other party to verify the password, and complete the pairing. Then connect.

(4) After the application receives the connection successfully, it can transmit data through the generated BluetoothServerSocke and the lower computer. The Bluetooth module that needs to be connected is the Bluetooth serial port, so the UUID defined in the application must conform to the UUID of the Bluetooth serial port, so the connection will be accepted. Because the accept() call is a blocking call, all of the application's response will be blocked before the call returns, so it must not be called in the main thread, usually doing all the work in a new thread to avoid the application master. Blocking of threads. The main code is as follows;

(5) Close the server socket, release the serversocket and the resources it occupies, and end the application.

Vibratory Motor

Xinxiang Mina Import & Export Co., Ltd. , https://www.mina-motor.cn

This entry was posted in on