This section covers GLCD devices that use the serially attached Nextion graphics displays.
Nextion includes hardware part (a series of TFT boards) and software part (the Nextion editor (http://nextion.itead.cc/)).
The Nextion TFT board uses only one serial port to communicate. It lets you avoid the hassle of wiring. Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich your interface design. And, the drag-and-drop function ensures that you spend less time in programming
The Nextion displays are 2.4 to 7.0 inches and range from 320*240 to 800*480 pixels. The connections are 5v, 0v, SerialIn and SerialOut. GCBASIC supports hardware and software serial connectivity.
See GITHUB for the set of GCBASIC demonstrations fro the Nextion displays. See Nextion demonstrations on GITHUB.
To use the Nextion driver simply include the following in your user code. This will initialise the driver.
Setup for Hardware Serial
' ----- Configuration 'Chip Settings. #chip 16f18855,32 #option explicit ' ----- Set up the Nextion GLCD #include <glcd.h> #define GLCD_TYPE GLCD_TYPE_Nextion ;VERY IMPORTANT!! ;Change the width and height to match the rotation in the Nextion Editor #define GLCD_WIDTH 320 'could be 320 | 400 | 272 | 480 but any valid dimension will work. #define GLCD_HEIGHT 240 'could be 240 | 480 | 800 but any valid dimension will work. ;VERY IMPORTANT!! ;Fonts installed in the Nextion MUST match the fonts parameters loading to the GLCD. ;Obtain parameters from Nextion Editor/Font dialog. #define NextionFont0 0, 8, 16 'Arial 8x16 #define NextionFont1 1, 12, 24 '24point 12x24 charset #define NextionFont2 2, 16, 32 '32point 16x32 charset ' ----- End of set up for Nextion GLCD ' ----- Set up for Hardware Serial ;VERY IMPORTANT!! ;The Nextion MUST be setup for 9600 bps. #define USART_BAUD_RATE 9600 #define USART_BLOCKING ;VERY IMPORTANT!! ;These two are optional. These constants are set in the library. #define GLCD_NextionSerialPrint HSerPrint #define GLCD_NextionSerialSend HSerSend ' ----- End of set up for Serial 'Generated by PIC PPS Tool for GCBASIC 'PPS Tool version: 0.0.5.11 'PinManager data: v1.55 ' 'Template comment at the start of the config file ' #startup InitPPS, 85 Sub InitPPS 'Module: EUSART RXPPS = 0x0016 'RC6 > RX 'Module: EUSART RC0PPS = 0x0010 'TX > RC0 TXPPS = 0x0010 'RC0 > TX (bi-directional) RC5PPS = 0x0010 'TX > RC5 TXPPS = 0x0015 'RC5 > TX (bi-directional) End Sub 'Template comment at the end of the config file ' ----- Main program starts ....
Setup for Software Serial
' ----- Configuration 'Chip Settings. #chip 16f18855,32 #option explicit ' ----- Set up the Nextion GLCD #include <glcd.h> #define GLCD_TYPE GLCD_TYPE_Nextion ;VERY IMPORTANT!! ;Change the width and height to match the rotation in the Nextion Editor #define GLCD_WIDTH 320 'could be 320 | 400 | 272 | 480 but any valid dimension will work. #define GLCD_HEIGHT 240 'could be 240 | 480 | 800 but any valid dimension will work. ;VERY IMPORTANT!! ;Fonts installed in the Nextion MUST match the fonts parameters loading to the GLCD. ;Obtain parameters from Nextion Editor/Font dialog. #define NextionFont0 0, 8, 16 'Arial 8x16 #define NextionFont1 1, 12, 24 '24point 12x24 charset #define NextionFont2 2, 16, 32 '32point 16x32 charset ' ----- End of set up for Nextion GLCD ' ----- Set up for Software Serial - this is optional - shown to explain the method. ;Remove Hardware Serial before using Software serial ;You MUST also remove PPS setup, for hardware serial, when using Software serial #include <SoftSerial.h> ; ----- Config Serial UART for sending: #define SER1_BAUD 9600 ; baudrate must be defined #define SER1_TXPORT PORTC ; I/O port (without .bit) must be defined #define SER1_TXPIN 5 ; portbit must be defined ;VERY IMPORTANT!! ;These two constants are required to support the the library. #define GLCD_NextionSerialPrint Ser1Print #define GLCD_NextionSerialSend Ser1Send ' ' ----- End of set up for Serial ' ----- Main program starts
The GCBASIC constants shown below control the configuration of the Nextion controller. The GCBASIC constants for control and data line connections are shown in the table below.
Constants | Controls | Options |
---|---|---|
|
|
|
|
Default is |
Required |
|
Default is |
Required |
The GCBASIC constants for control display characteristics are shown in the table below.
Constants | Controls | Default |
---|---|---|
|
Mandated. The width parameter of the GLCD |
|
|
Mandated. The height parameter of the GLCD |
|
The GCBASIC Nextion specific commands supported for this GLCD are shown in the table below. Always review the appropiate
library for the latest full set of supported commands.
Command | Purpose | Example |
---|---|---|
|
Print string of characters on GLCD using Nextion font set |
|
|
Locate the screen coordinates at a specific location. |
|
|
Print string of characters on GLCD using Nextion font set |
|
|
Print string of characters on GLCD using Nextion font set adding a newline and carriage return to move cursort to start of next line. |
|
|
Send the Nextion display a specific command and a specific value |
|
|
Update a Nextion display object with a specific value |
|
|
A function that returns a long, that can be treated as word variable, value of the Touch event.. As follows:
"tch1" for current y co-ordinate touched "tch2" for last x co-ordinate touched "tch3" for last y co-ordinate touched
1. Checks for three bytes of 0xFF. If Four 0xff are received then exit = non-block. 2. If at any time a 0x71 is recieved then we have data for the event. 3. If seven bytes arrive, but the method did not receive a 0x71 then exit = non-block. 4. The method supports software and hardware serial. As does all the other methods. 5. The method uses a function to receive the data not a sub-routine. 6. The method returns 0xBEEF if there is an invalid read, and, functional value for GLCDGetTouch_Nextion will also be set to 0xDEADBEEF |
myReturnedWordValue = GLCDGetTouch_Nextion( "tch2") or, myReturnedWordValue = GLCDGetTouch_Nextion( "tch3") |
The GCBASIC commonn commands supported for this GLCD are shown in the table below. Always review the appropiate library
for the latest full set of supported commands.
Command | Purpose | Example |
---|---|---|
|
Clear screen of GLCD |
|
|
Print string of characters on GLCD using GCB font set |
|
|
Print character on GLCD using GCB font set |
|
|
Print characters on GLCD using GCB font set |
|
|
Draw a box on the GLCD to a specific size |
|
|
Draw a box on the GLCD to a specific size that is filled with the foreground colour. |
|
|
Draw a line on the GLCD to a specific length that is filled with the specific attribute. |
|
TFT_BLACK 'hexidecimal value 0x0000 TFT_RED 'hexidecimal value 0xF800 TFT_GREEN 'hexidecimal value 0x0400 TFT_BLUE 'hexidecimal value 0x001F TFT_WHITE 'hexidecimal value 0xFFFF TFT_PURPLE 'hexidecimal value 0xF11F TFT_YELLOW 'hexidecimal value 0xFFE0 TFT_CYAN 'hexidecimal value 0x07FF TFT_D_GRAY 'hexidecimal value 0x528A TFT_L_GRAY 'hexidecimal value 0x7997 TFT_SILVER 'hexidecimal value 0xC618 TFT_MAROON 'hexidecimal value 0x8000 TFT_OLIVE 'hexidecimal value 0x8400 TFT_LIME 'hexidecimal value 0x07E0 TFT_AQUA 'hexidecimal value 0x07FF TFT_TEAL 'hexidecimal value 0x0410 TFT_NAVY 'hexidecimal value 0x0010 TFT_FUCHSIA 'hexidecimal value 0xF81F
For more help, see
GLCDCLS
Supported in <GLCD.H>