Distance Measurement with Stone-HMI Display


Stone Technologies is a professional Manufacturer of HMI Intelligent TFT LCD modules.  Depending on the application the Stone Technologies offers Industrial Type, Advanced type, and Civil Type Intelligent TFT LCD modules available in different sizes. Visit Here .

In this project I am going to measure the distance and will display it on Stone HMI display. Here I am using STWI056WT/N-01 model for our in this project, if you want to understand data frame and how it is working? you can download the Datasheet from here .

Component List

[1] STONE-HMI Display [STWI056WT/N-01]

[2] Raspberry-Pi

[3] TTL to USB converter

[4] Ultrasonic Sensor

[5] USB cables

[6] Jumper Wires

GUI Designing

Let’s start first with interface designing but before that you have to install Stone Designer and the Driver for USB so let see how to install these software.

Step-1 :- Go to this website and download these software and then install them in your computer.

Website Link :- https://www.stoneitech.com/support/download/software

After installed , go to to Stone-Designer icon and click on that after that designer software will open and you will get this type of interface as shown in image.

After opened you have to create a new project for this select ‘Project’ from top and from that select ‘new’ and you will ask for the some details as shown in the below figure , now give the name of project and select screen size as per your display size, here I’m using 640X480 size display , and select project path also after done with filling all the details click on ‘Create’ .

After done with above part select the background image for the project for this follow steps as shown in the figure.

step-1 :- Select ‘image’ from Resources to upload the image.

Step-2:- Click on Add button to add a new image in it , so I added an image as you can see in the above image as name ‘background’.

Step-3:- Now drag image widget from top and put it in the edit section.

Step-4:- Now go to at properties and select image as ‘1’ and click on enter.

Step-5:- Select font size as per your choice.

After done with this ,drag Labels from top as shown in above figure .Drag for each distance as per the steps given in above figure.

Note:- Here we have selected widget as ‘label1’ & ‘label2’ and it type is ‘label .

name :- label1 & for Ambient temperature name:- label2

type:– label

Step-6:- This step is important because you have to remember some data from there and this data we will use for further steps or I can say for coding part.

Then compile the design by click on compile button. Now plug USB with your PC and copy that ‘default’ folder in memory of Display. For more details see the YouTube video. So now let’s move further to understand how code is working.

Now we have done with Design part now let’s move to coding and working part.

Working & Raspberry-Pi coding

Let’s First understand how ultrasonic sensor is working?

The ultrasonic sensor (or transducer) works on the same principles as a radar system. An ultrasonic sensor can convert electrical energy into acoustic waves and vice versa. The acoustic wave signal is an ultrasonic wave traveling at a frequency above 18kHz. The famous HC SR04 ultrasonic sensor generates ultrasonic waves at 40kHz frequency.

Typically, a microcontroller is used for communication with an ultrasonic sensor. To begin measuring the distance, the microcontroller sends a trigger signal to the ultrasonic sensor. The duty cycle of this trigger signal is 10┬ÁS for the HC-SR04 ultrasonic sensor. When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts and initiates a time counter. As soon as the reflected (echo) signal is received, the timer stops. The output of the ultrasonic sensor is a high pulse with the same duration as the time difference between transmitted ultrasonic bursts and the received echo signal.

Raspberry-Pi Code :-

import RPi.GPIO as GPIO
import time
import serial
serialcomm = serial.Serial('/dev/ttyUSB0', 115200)
        pinTrigger = 13
        pinEcho = 11
        GPIO.setup(pinTrigger, GPIO.OUT)
        GPIO.setup(pinEcho, GPIO.IN)
        GPIO.output(pinTrigger, GPIO.LOW)
        GPIO.output(pinTrigger, GPIO.HIGH)
        GPIO.output(pinTrigger, GPIO.LOW)
        while GPIO.input(pinEcho)==0:
            pulseStartTime = time.time()
        while GPIO.input(pinEcho)==1:
            pulseEndTime = time.time()
        pulseDuration = pulseEndTime - pulseStartTime
        cm = round(pulseDuration * 17150, 2)

As you can see ultrasonic sensor connected with GPIO 13 & 11, and there is below code in which I have done distance calculation with the help of formulas.

As you can see in the above image , this frame we will send to Stone-Display and display will show the temperature reading.

These are the frame which we are sending through Raspberry-Pi. First is for Distance in cm and second is for Distance in inche.



And here are the two variable through which we are sending the values, first one is ‘cm ‘ and second one is ‘inch ‘ . And these two frames sending with the help of serial communication between raspberry-Pi and Stone-HMI display .

Now connect Raspberry -Pi through VNC server and paste that code which is given above and it will look like this as given in below image. Open thonny IDE in Raspberry-Pi and paste that code in this IDE as given in below code.

Now before run the code connect the circuit as per the circuit diagram.

After connection now everything is ready now you can run the code , by click on Run button. We have we have completed with this project let’s see the output video, find video below.

Output Video

Thankyou so much to read the article till now there is YouTube video on this project so please go through that video to understand the whole procedure in a better manner there is link for video go and check it out.

Leave a Reply

Your email address will not be published.