Skip to main content

How to use Nextion LCD #2 - Programming and application

How to use Nextion LCD #2 - Programming and application

How to use Nextion LCD Series
#1 Start Nextion LCD
#2 Programming and application
#3 - Practice for use with a transceiver
#4 Applied to HF Transceiver
#5 Advanced Application (Applied to various sizes)




I do not know much about Nextion LCD. During the production of uBITX Firmware which is HF Transceiver, I was introduced by several OMs, The ultimate goal of this article is to create a GUI for the HF Transceiver.

uBITX CEC Version officially supports Nextion LCD from version 1.09.
I will support 2.4 "and 2.8" LCD by default. You do not need to understand everything below to connect uBITX Nextion LCD. Just use the Nextion Editor to load the firmware on the Nextion LCD. If you want to create your own GUI, please read these articles.


1.Create Project
 - Execute Nextion Editor
 - New

-Select your LCD Type

- Select Display direction (90)

- Font Generator (You can also add a font file that you have already created)

- Select Height, Code, Font, Font Name
  (32, ascii, MS Gothic, msgothic_32)
- Click the 'Generate font' button

-Input Font Name (msgothic32)

- OK

- OK

- you can see the added font


2.Text Control
Click the 'Text' control in Toolbox

Move and Resize t0 control (Text Control)

- Click the Attribute

- Changed txt_maxl 10 -> 20
- Changed txt "Hello World"

You will see 'Hello World' marked as below


3.Number type
Click the 'Number' control in Toolbox

Click the Attribute window

Change xcen (Center -> Right)

You will see that n0 is right justified.

Let's change the name of n0
Perhaps you should give a special name to most Controls when you are working on Nextion LCD, not practice.

changed the name of the n0 control to nfreq.



Click the 'Debug' Button

You will see the following screen

trype nfreq.val=14074000 and the press Enter Key

Close the Debug window

Changed nmode's format field (Decimal -> Currency)

trype nfreq.val=14074000 and the press Enter Key

4.Button
Click the 'Button' Control in Toolbox

A button will be added to LCD window as below

Changed Button name (b0 -> bmode)

 

Changed the Button's txt (newtxt -> Mode)


With the button selected, look at the bottom of the Nextion Editor.
You will see the Event input window.

type t0.txt="Press!!!" in Touch Press EVent

Click the 'Debug' Button

Now you have an LCD program that allows you to input as well as output.

Click the 'Mode' in LCD Screen


'Hello World' -> 'Press !!!'

There are many other properties. Please try to operate variously. It will be fun.
You can also specify the color when the button is pressed.


5.Image
Most of the Nextion LCD's controls support images.
You need a picture file for your resolution to test the Image on the Nextion LCD.

Below is a 320 * 240 image file I created. If you are working with a 320 * 240 resolution LCD, download and use the image below.


Look at the bottom left part of Nextion Edit.
Picture / Fonts windows will appear.

Select the 'Pictures' tab below.

Click then '+' Button in Pictures Window
Select Background Image




If the resolution of the picture file is compatible with the size of your LCD, the following success message is displayed.

Click the '+' button again

Select Other Image (enabled image)

If the resolution of the picture file is compatible with the size of your LCD, the following success message is displayed.

In order to practice, two picture files should be added as below.
Picture files do not have to be cool, 

Click the LCD Window
The Attribute Window for Page0 appears as shown below.

Change the 'sta' field from solid_color to image.

If you change to image as below, 'pic' field appears.

double click the 'pic' field

A window for selecting the image file shown below appears.
Select the first picture file and press the 'OK' button.

A picture will appear on your LCD screen.
However, the background color of the Controls will obscure the picture as shown below.

Let's make it more beautiful.
Select the 'nfreq' control

In the properties of nfreq control, change sta from 'solid_color' to 'crop_image'.

Double-click the pic field, select the first image, and click OK.
The nfreq control now looks transparent.
but, The font color is black and is not displayed on the screen.

click the 'pco' field, ant select whit or gray color

Nfreq will look nice as shown below.
Most Controls on the Nextion LCD can use Picture in this way.

-Button with picture
 'Button' control can be used for a bit more variety of pictures.
Select the 'bmode' control

changed stat field 'solid color -> crop image'
The bmode button should be transparent.

Move the bmode button to the appropriate position.

Double-click the picc field.

Select the first picture

double click the picc2 field

select the second picture

Perhaps the properties of the Button should look like this

Click the 'Debug' button

-Press the Mode Button
When the button is clicked, it will change as shown below.

6.Timer
Using the Timer properly on the Nextion LCD, you can create a very dynamic GUI.

Click the 'Timer' in Toolbox

A control named tm0 would have been created under the LCD window as shown below.

A timer is a control that executes commands periodically.
Change the tim field (500)
Tm0 will now execute the command at 0.5 second intervals.

Select a timer and look at the Event input window.

Enter the following in Timer Event.
tm0 will execute the following command at 0.5 second intervals.

Click the 'Debug' button

Watch the screen now.
The number will increase every 0.5 seconds.

Is not it nice to have an LCD that works by itself without any MCU connection?
In this way, you can minimize what you have to process on the MCU.


7.Variable
Nextion LCD supports such as If, For, etc.
The only thing to note is that there is no separate variable declaration inside the programming. To use these variables, you must use the 'Variable' control.

click the 'Variable' control

You will see that va0 has been created.

There are only two variable types in the Nextion Editor.
(String, Number)
If you select String, you can put or get values into the 'txt' entry.
If you select Number, you can put or get values in the 'val' field.

Select Number at 'sta' field

Modify the timer event as follows.
nfreq.val=va0.val

Each time a timer event is fired, you put the value of va0.val into nfreq.val.

Click the 'Debug' button

Enter the following in the command input window.
va0.val=7000

It will be displayed as below.

In this way, the value passed to the Variable control can be used for calculations or displayed on the screen.

8.Other Control
Nextion LCD supports 12 Controls. If you have practiced this, you probably will be able to handle other controls in a similar way.

I write this document to apply the Nextion LCD to the HF-Transceiver which is the final goal. You will find some additional examples in the upcoming 2.4 "Nextion LCD firmware that I will be releasing.

Click on the link below to see various examples of controls.
https://nextion.itead.cc/resources/download/tooles-pages/


Below is a test video for this post



Comments

  1. Anxiously waiting to see a demo-video of the Nextion Display in action.

    ReplyDelete
    Replies
    1. Today I will upload a video about S-Meter and frequency input

      Delete
  2. Nice work, nextion are more expensive than tft lcd from aliexpress, but i dont know any friendly use software for tft like for that nextions :) 2.8 inch is really good, but what about biggers ? Could i will use it without hardware modifications ?, btw i see the tft is next BIG step in ubitx software, meybe next is STM32 with nextion and waterfall suport etc, like M0NKA trx :P Great WORK Briliant Development.

    ReplyDelete
    Replies
    1. Yes, that's right. It is more expensive than normal TFT, This is one of the reasons I hated this type of LCD. Customers are very sensitive to $ 1 :)
      The second is too restrictive. It is too restrictive to be easy to use.
      I have never used this kind of LCD for reasons.

      But when I tried Nextion LCD, I knew I was wrong. It is cheaper than existing HMIs and has its own programming.

      And now the firmware that supports Nextion LCD is in beta testing.

      No hardware modifications are required to use the Nextion LCD.
      Remove the existing LCD and connect the Nextion LCD.

      If you have Nextion LCD, please send your e-mail address to the following e-mail address. I'll send you some materials for testing
      (kd8cec@gmail.com)

      Delete
  3. As usual, excellent work.
    I have just received my nextion display - 3.2" enhanced version and am learning the editor. The displays do cost more but the potential for beautiful functional display are great.
    I have worked with VU2SPF - SP Bhatnagar with a touch colour TFT. We found out that mapping out the touch control and display was a huge amount of work . If the display changed, many times the drivers on the new display also changed and made it difficult to find a solution. At least with the Nextion that is not an issue and graphic enhancements are much easier , especially when troubleshooting
    I look very much forward to working with your designs.. and my ubitx running KD8CEC v1.08

    73
    joe
    VE1BWV

    ReplyDelete
    Replies
    1. joe
      One of the motivations for supporting Nextion LCD is your work.
      Many users wanted to support Nextion LCD and I was able to find your Youtube. Your work did not use the Nextion LCD, but I found that the touchscreen was sufficient.
      Your email address is what you used to be? (joe...@gmail.com)

      Delete
    2. Ian,

      Your programming skills are outstanding and provides a great resource to the Amateur Radio world. Many of us are not as gifted in your ability to work the code but offer skills and testing in other areas.

      I think the ability to have the Nextion as addon Display with various Buttons to call up various operational screens is very appealing and offers another extension and versatility.

      I see a main menu Screen, with buttons pointing to other screens.

      Operational main screen - with freq control, vfo selection, band selection, mode - just like your latest hrd look screen ( which looks great)


      Setup screen - for calibration etc

      Memory screen- where a user presses a button and up comes a new screen with all the mem channels making it quick and instant to get to it.
      and the list goes on......

      All this being done with nearly zero demand on the nano.

      The extra benefit of the Nextion Display is also the ability for other users like myself, to be able to use the nextion editor to easily add graphic enhancements to the cosmetics of the screens.
      With any other displays this is extremely difficult and time consuming.

      At 67 years old, and retired, I am thankful for your willingness to share!
      You sure keep me busy testing your stuff Lol... Fun stuff!

      Thanks
      Joe
      VE1BWV
      joeman2116@gmail.com





      Delete

Post a Comment

Popular posts from this blog

How to upgrade uBITX Firmware

uBITX is based on Arduino Nano. So uBITX's firmware upgrade method is the same as Arduino.
There are two ways to upgrade the firmware of uBITX.

The first is to compile the source from the Arduino IDE, and the second is to upload the compiled hex file using the Firmware Upgrade Tool.

I'll show you how to upload a compiled hex file as a second method.

1.Connect the uBITX's USB cable to the computer.


2.Run Device Manager on your computer.
  The way to open the Device Manager for each OS Version differs slightly.
  In most Windows, you can easily launch the Device Manager by running.

  On your computer, press the Windows key + R.



 Type devmgmt.msc and press OK Button.




On most operating systems, there will be a serial port named Ports with CH340. If so, the next step is skipped.

If the serial port is not installed as below, you need to install the driver.



Included in uBITX is the Adonano, which uses the CH340 USB To UART part.

Download the latest CH340 driver from the Internet.

CAT Support uBITX Firmware CEC Version 1.06 Release (Added WSPR)

uBITX Firmware CEC Version v1.06 (changed v1.061)

I deployed 1.06 and received feedback from WSPR's beta tester, Philip (G7JUR).
It was a problem that the LPF was not automatically selected according to band selection during WSPR transmission.

Version 1.08 has been released.
http://www.hamskey.com/2018/05/ubitx-firmware-cec-version-108-release.html

I modified it soon and changed uBITX Firmware CEC Version to 1.061.
uBITX Manager also changed Version to 1.01.

-----------------------------------------------------------------------------------

I released version 1.06 which added WSPR function to uBITX.
Beta testers have been very helpful when embedding WSPR functionality. WSPR will continue to improve in the future.

By using WSPR before and after QSO, you can check where your uBITX is spreading all over the world.  If uBITX Manager is used to put WSPR information into uBITX, uBITX no longer needs any external device to transmit WSPR.

The uBITX group's excellent tester also shared a …

CAT Support uBITX Firmware CEC Version 1.01 Release(Changed from v1.0)

CAT Support uBITX Firmware CEC Version 1.01  Release (Changed from v1.0)

uBITX Firmware CEC Version 1.06 has been released.
Please click the link below.
http://www.hamskey.com/2018/03/cat-support-ubitx-firmware-cec-version_24.html

This version of the concept is an upgrade without hardware modifications. No hardware modifications are required to use this firmware. Continuous release and testing has been done in the uBITX group. I tried to put only the basic functions that an HF transceiver should have. The features have been upgraded with the advice of people who have great ideas in the uBITX group.
It was a project that started to contribute to the original source in github. The project was intended to fix some simple bugs and request merge to the original source. And I was planning to delete the project. At the beginning of the project there was a bit of discussion about this in the uBITX group.
Since then, I've keeping the original source type to allow code share with any user fork…