Science Technology

STONE TFT LCD Module + STM32 + Ultrasonic Dstance Measurement

  This project shows how to use the STONE display, STM32 microcontroller, ultrasonic sensors, and a servo. The purpose of the project is to be able to display the distance measured by ultrasound in real-time through the STONE display.

  Supplies used in the project:

  The display uses an 8-inch STONE screen, 8-inch intelligent TFT-LCD (thin-film transistor – liquid crystal display) industrial display module.

  8-inch intelligent TFT-LCD (thin-film transistor – liquid crystal display) industrial display module

  The intelligent TFT LCD module with Cortex-M4 32-bit CPU can be controlled by Any MCU through simple Hex commands via the UART port.
STONE provides TOOLBOX software for engineers to easily and visually set up various functions on the GUI, such as text, numbers, curves, image switching, keyboard, progress bar, slider, dial, clock, and touch buttons, data storage, USB download, video & audio.
Engineers can easily adopt the TFT-LCD color user interface and touch functions on various industrial devices and also reduce a lot of development time and cost.

  Easy to use:

Design a set of beautiful “graphical user interfaces” and use our toolbox software to set various application functions on the GUI.
Connect directly to customer MCU via RS232, RS485, or TTL level, plug, and play.
Write the MCU program to control the TFT LCD module with 4 simple Hex commands.

  For example, the Image switch command:
Send “0xA5 0x5A 0x04 0x80 0x03 0x00 0x01” to display image-01
0xA50x5A: frame header of each instruction
0x04: data length
0x80: write register instruction
0x03: Image switch instruction
0x000x01: Image_ID, the serial number of the image storage location
Application areas: medical and beauty equipment, engineering machinery and vehicle equipment, electronic instruments, industrial control systems, electric power industry, civil electronic equipment, automation equipment, transportation equipment, etc.

  Product Advantages

  Touch terminal, thin-film transistor-LCD display system
Any microcontroller can be controlled by a simple instruction set
Cost-effective HMI (Human Machine Touch Terminal)

  Operation steps

  Design a set of custom user interfaces.
Connect the device to the TFT-LCD module through RS232/RS485/TTL serial port.
Write a control program in any microcontroller with an instruction set (included in the product) to control the TFT-LCD module.

  Auxiliary Software

  We provide three software programs to assist in the operation of the TFT-LCD module.

Assistant software: for uploading pictures, files and demonstrating the instruction set.
Touch Control software: for generating touch control files.
Font software: for generating font files.

  Working Principle

  Through the existing command set provided by the product, this TFT-LCD module can generate command transmission and recognition with the main controller. The main controller receives the commands from the TFT-LCD module to operate the industrial equipment.

  Note: The engineer can use any microcontroller to design the main controller.


  STM32F411 Micro-controller core board




  Ultrasonic sensors


  Ultrasonic principle analysis

  Ultrasonic (waves):

  The human ear can hear the frequency of sound waves for 20HZ ~ 20KHz. when the vibration frequency of sound waves is greater than 20KHz or less than 20Hz, we can not hear the sound waves. Therefore, we put the frequency higher than 20KHz sound waves called “ultrasonic”. Because of its good directionality, strong penetrating ability, ease to get more concentrated sound energy, in the water to spread far, can be used for measuring distance, measuring speed, cleaning, welding, stone crushing, sterilization, etc. There are many applications in medicine, the military, industry, and agriculture. Such as ultrasonic cleaning machine, ultrasonic humidifier, medical examination B ultrasound, color ultrasound, ultrasonic flaw detector, etc. Sound is generated by vibration, the device that can produce ultrasonic waves is the ultrasonic transducer, customarily called ultrasonic transducer, or ultrasonic probe. The ultrasonic probe is mainly composed of a piezoelectric chip, which can both emit and receive ultrasonic waves. There can be many different materials that make up the chip. The size of the chip, such as the diameter and thickness also varies, so the performance of each probe is different, and its performance must be understood in advance before using it.

  Commonly used is the piezoelectric ultrasonic generator, which works by using the resonance of a piezoelectric crystal. Inside the ultrasonic sensor, probes are two piezoelectric chips and a resonant plate. When its two poles applied a pulse signal, its frequency is equal to the inherent oscillation frequency of the piezoelectric chip, the piezoelectric chip will resonate, and drive the resonance plate vibration, it will produce ultrasonic waves. Conversely, if the voltage is not applied between the two electrodes when the resonance plate receives ultrasonic waves, the piezoelectric chip will vibrate, converting mechanical energy into electrical signals, and then it becomes an ultrasonic receiver.  Ultrasonic sensor uses the principle of the piezoelectric effect to convert electrical energy and ultrasound into each other, that is, in the emission of ultrasound, the electrical energy will be converted into ultrasound emission; and in the reception, the ultrasonic vibration will be converted into an electrical signal.

  Ultrasonic distance measurement principle:

  The most commonly used method of ultrasonic distance measurement is the echo detection method, as follows, the ultrasonic transmitter launches ultrasound to a certain direction, at the moment of launch while the counter began timing, ultrasound propagation in the air, the way to encounter the obstacle surface blocking immediately reflected back, the ultrasonic receiver received back the reflected ultrasound immediately stop timing. Ultrasonic waves in the air propagation speed of 340m/s, according to the time recorded by the timer t, you can calculate the launch point from the obstacle surface distance s, that is: s = 340t/2

  Ultrasonic emission circuit: by the 555 timers to generate 40KHZ pulse signal, added to the pins of the ultrasonic probe so that the internal resonance of the piezoelectric chip can be generated to emit ultrasonic waves outward.

  Ultrasonic receiving circuit: As the electrical signal generated by the ultrasonic receiving probe is very weak, it needs to be amplified and processed. In the figure below, the transistor and operational amplifier LM324 constitute the amplifier circuit, which amplifies the received signal and then drives the relay. Generally, use an integrated signal amplifier chip to amplify the signal. CX20106 is a special integrated preamplifier from SONY, which consists of a preamplifier, limiting amplifier, band-pass filter, detector, integrator, and rectifier circuit. One of the preamplifiers has an automatic gain control function, which can ensure that when the ultrasonic sensor receives weak voltage which outputs from the reflected signal in the long-distance, the amplifier has a high gain when the input signal is strong in the near distance, the amplifier will not be overloaded.

  The ultrasonic wave is also a kind of sound wave, its sound speed V is related to the temperature. When used, if the temperature of the propagation medium does not change much, the ultrasonic velocity can be approximated as being essentially constant during the propagation process. If the distance measurement accuracy requirements are very high, the measurement results should be numerically corrected by the method of temperature compensation. v = 331.4 + 0.607T, where T is the actual temperature in ℃, v is the speed of ultrasound propagation in the medium in m/s, the actual measurement will generate several special cases, and lead to wrong measurement results due to the different angles of the sensor and the measured object, and the surface of the measured object may not be flat, as follows, it can be solved by rotating the probe angle several times to measure.

  The main performance indicators of ultrasonic sensors include:

Operating frequency. Operating frequency is the resonant frequency of the piezoelectric chip. When the frequency of the AC voltage is added to both ends of it and the resonant frequency of the chip is equal, the output energy is the largest and the sensitivity is the highest.
Operating temperature. Because the Curie point of piezoelectric materials is generally high, especially with ultrasonic probe diagnosis, using less power, so the operating temperature is relatively low, it can work for a long time without failure. The temperature of medical ultrasound probes is relatively high and requires separate cooling equipment.
Sensitivity. It mainly depends on the manufacturing chip itself. The electromechanical coupling coefficient is large and the sensitivity is high.

  Ultrasonic distance measurement module: There are many good measurement modules on the market, with different price performances.

  HC-SR04 ultrasonic distance measurement module can provide a 2cm-400cm non-contact distance sensing function, the accuracy of distance measurement up to 3mm; the module includes an ultrasonic transmitter, receiver, and a control circuit.

  Basic working principle:

  The IO port TRIG is used to trigger the distance measurement, giving a high-level signal of at least 10us;
The module automatically sends 8 square waves of 40khz and automatically detects whether there is a signal return.
There is a signal return, output a high level through the IO port ECHO, the high-level duration is the time from emission to return of ultrasonic wave.

  Test distance = (high level time * speed of sound (340M/S))/2;

  Servo principle:

  Servo (called Servo in English): It is a set of automatic control systems consisting of a DC motor, reduction gear set, sensor, and control circuit. By sending a signal, the output axis rotation angle is specified. Servo generally has a maximum rotation angle (such as 180 degrees.) The difference with ordinary DC motors is mainly in that DC motors rotate in a circle, and servos can only rotate within a certain angle, not in a circle (digital servos can switch between servo mode and motor mode without this problem). THE ordinary DC motor can not feedback the rotation angle information, while the servo can do it. The applications are also different, as ordinary DC motors are generally used for powering the whole rotation, while servos are used to control the rotation of an object at a certain angle (such as the joints of a robot).
Servos come in a dazzling variety of shapes and sizes and can be roughly divided into the following categories (as shown in the figure)


  The one on the far right is a common standard servo, the two small ones in the middle are micro servos, and the lanky one on the left is a large-torque servo. These servos are all controlled by three wires. The following servos are commonly used for making robots, and each of them is fixed in a different way. If you change from one model to another, the whole mechanical structure needs to be redesigned. The first one is MG995, which has the advantages of cheap price, metal gears, and good durability. The disadvantage is that the torque is relatively small, so the load can not be too large, if you do bipedal robots and the like, this servo is not very suitable, because the legs are too much force. Doing ordinary six-legged, or robotic is still good.


  The second is SR 403, this servo is found by the net friend xqi2 because using the MG995 to do bipedal robot is shaking too much. After testing, the SR 403 makes a good bipedal robot, and at least not shaking. The advantage is the torque is large, all-metal gears, the price is also quite cheap, the disadvantage is that the workmanship is very cottage. Another disadvantage is waiting for feedback.


  The third is the legendary digital servo AX12+, which is a special servo for the tried and tested robot. In addition to the high price, the use of RS485 serial communication (the control board will have to change the digital servo dedicated control board), the other is all advantages.


  The following diagram is an exploded view of a common analog servo, whose components are mainly gear sets, motors, potentiometers, motor control boards, and housings.


  A motor control board is mainly used to drive the motor and receive information back from the potentiometer. The motor is the source of power, this does not need too much explanation. The role of the potentiometer here is mainly to send the signal back to the motor control board through the change of resistance which is generated by its rotation so that it can judge whether the output axis angle is output correctly. The role of the gear set is mainly to amplify the force so that the small power motor can generate large torque.


  The bottom shell of the servo can be seen after dismantling, mainly the motor and control board.


  The bottom of the control board is the potentiometer that is connected to the control board after picking it up.


  Looking at the motor and potentiometer from the top, the first stage amplifier gear is directly connected to the motor gear.


  After being amplified by the first stage gear, it then passes through the second, third, and fourth stage amplifying gears before finally being output through the output axis.


  Through the above two pictures can be clearly seen, this servo is a 4-stage gear amplification mechanism, a small power is amplified layer by layer so that a small motor can have 15KG of torque.

  The servo control method :

  The servo system of the servo is controlled by variable width pulses, and the control line is used to transmit the pulses. The parameters of the pulse are minimum, maximum, and frequency. Generally, the reference signal of the servo is 20ms in period and 1.5ms in width. And the position defined by this reference signal is the middle position. The servo has a maximum rotation angle, and the middle position is defined as the exact same amount from this position to the maximum angle as the minimum angle. The most important point is that the maximum rotation angle may not be the same for different servos, but the width of the pulse at its middle position is certain, which is 1.5ms. As follows:


  The angle is generated by a continuous pulse from the control line. This method of control is called pulse modulation. The length of the pulse determines how far the servo will turn. For example, a 1.5-millisecond pulse will go to the middle position of rotation (for a 180° servo, it is the 90° position). When the control system sends a command to let the rudder move to a certain position and let it keep this angle, this time the influence of external forces will not let its angle change, but this has the upper limit, the upper limit is its maximum torque.  Unless the control system keeps sending out pulses to stabilize the angle of the servo, the angle of the servo will not remain unchanged.

  When the servo receives a pulse that is less than 1.5ms, the output axis will counterclockwise rotate a certain angle with the middle position as the standard. The opposite case is received pulses greater than 1.5ms. Different brands, or even different servos of the same brand, will have different maximum and minimum values. Generally, the minimum pulse is 1ms and the maximum pulse is 2ms. As follows:


  Small summary:

  First of all, the servo leads, generally for three-wire control (No contact with a servo that is not a three-wire control), red for power, brown for ground, yellow for the signal. When controlling the servo, you need to constantly give PWM waves so that the servo has torque at a certain angle.

  STM32 core board:




  The microcontroller program uses the firmware library to program the STM32CUDEMX.

  Pinout diagram:


  Hour hand configuration:


  Hardware connection:


  Schematic diagram of the connection between ultrasound and servo:


  The J17 jumper on the back of the STONE screen is disconnected and selected to the TLL level and the microcontroller communicates:


  Import GUI-generated files into the touch screen:


  Source code analysis:

  The microcontroller uses serial port 1 and touch screen communication, using a baud rate of 115200.

STONE TFT LCD Module + STM32 + Ultrasonic Dstance Measurement