Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Nextion Display works with bascom

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sat Jul 15, 2017 2:34 pm    Post subject: Nextion Display works with bascom Reply with quote

Hi
Nextion is a HMI system, more than a simple screen, it is both faster, draw its own user interfaces and all this with only 4 wires:
2 for power supply and 2 for serial communication.
In addition to Bascom, I have prepared a ".inc" file with all the sub and useful functions.
The video example shows only part of its possibilities
What impresses most is speed.



and the video
[/img]https://www.youtube.com/watch?v=YcqzFNcBxMw&feature=youtu.be

In add file : a .zip with all you need to start program doc, datasheet font...

Bon courage
JP Wink
Back to top
View user's profile Visit poster's website
aphawk

Bascom Member



Joined: 23 Jan 2010
Posts: 168
Location: Brazil

brazil.gif
PostPosted: Sat Jul 15, 2017 7:52 pm    Post subject: Reply with quote

Hi, Duval,

Very nice !!!
Where you bought this display ?

Thanks !

Paulo
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sat Jul 15, 2017 8:30 pm    Post subject: Reply with quote

Hello JP,

I see you progressed very well. Thank you for sharing your project and the nice video demo.
This is indeed a great display for user interface projects. Well that also depends on the price and availability of course Very Happy
It seems simpler to use than the FT8xx series. (which have great speed as well)

_________________
Mark
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Sun Jul 16, 2017 9:49 am    Post subject: Reply with quote

hi,

It is designed ??? and sold by [/url]https://www.itead.cc/[url] It is not a giant company.
The forum is reactive , but the response are sometime a little bit strong... And the help and doc are poor..

The price seems good, 28€ for the 3.5" and 62€ for the 5" compare to the "normal" 5" plus interface to adjust the voltage 38+5=43€. It is a bit more expensive than a normal screen but the difference is reasonable considering the possibilities.


Now I have to do a project with it !

JP Wink [/url]
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Mon Nov 12, 2018 3:15 pm    Post subject: Reply with quote

I add all sub for display time and date

A video is available here :https://youtu.be/YryQtV-_AOs

all the files needed are in add file

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Mon Nov 12, 2018 8:06 pm    Post subject: Reply with quote

Hello JP,

Nice to see your project here. Thanks for sharing and for making the video. I enjoyed watching it.

_________________
Mark
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Aug 09, 2019 10:45 am    Post subject: Reply with quote

Hello Mr Duval JP (Jean Pierre ? I`m from Poland but I was learn four years French Very Happy) I really like it Very Happy
"Regard la bas, se Philipe , nes pas?" ahahahaha this is the quote from the first page of our primer-french-book Very Happy

To the point
I have 7" K series Nextion and want to comunicate both ways. So I really appreciate your work that`s why I publish here how to parse data from Nextion.
I think this is better, non blocking solution Very Happy
Look how "Overlay" can be used multiple times on one buffer.

This example can be launched on Mega 2560. Nextion on Com2(RX1/TX1) rest like describes "#USB" it will be on RX0/TX0

Code:
$regfile = "m2560def.dat"                                   '8K SRAM | 4K EEPROM
$crystal = 16000000
$hwstack = 256
$swstack = 128
$framesize = 256
$baud = 115200
$baud1 = 9600

Debug On

Config Submode = New

Const Max_usb_in_command_len = 50
Const Max_nex_command_len = 50
'*****************************************************************
'*         CONFIG BUFFERED USART FOR DEBUG via USB               *
'*****************************************************************

Config Com1 = 115200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
 Echo Off

 Config Serialin0 = Buffered , Size = Max_usb_in_command_len       'RX from Terminal
  Dim Char As Byte , Cmd_timeout1 As Byte , Got_str1 As Byte
  Dim Command1 As String * Max_usb_in_command_len

 'Config Serialout0 = Buffered , Size = Max_usb_out_command_len       'TX to the Terminal
  Open "COM1:" For Binary As #1
    Const Usb = 1
'*****************************************************************
'*           CONFIG BUFFERED USART FOR NEXTION                   *
'*****************************************************************

Config Com2 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

 Config Serialin1 = Buffered , Size = Max_nex_command_len   'RX
  Dim Cmd_timeout As Byte , Got_str As Byte
'unnecessary
  Dim Command As String * Max_nex_command_len

 'Config Serialout1 = Buffered , Size = Max_nex_command_len         'TX
  Open "COM2:" For Binary As #2
   Const Nex = 2

'*****************************************************************
'*                TIMER2 FOR TIME BASE                           *
'*****************************************************************
Config Timer2 = Timer , Prescale = 1024 , Compare_a = Disconnect , Compare_b = Disconnect , Clear_timer = 1
 Compare2a = 155                                            '10ms @16MHz/1024



'BARTek multipurpose
Dim Helpb As Byte , Helpstr As String * 30 , N As Byte , Tempb As Byte , Helpl As Long

Enable Interrupts                                           'buffered USART

Print #usb , "Program restarted"

'NEXTION RETURN DATA                                        LENGTH
Const Invalid_instruction = &H00                            '4
Const Instruction_okay = &H01                               '4
Const Invalid_component_id = &H02                           '4
Const Invalid_page_id = &H03                                '4
Const Invalid_picture_id = &H04                             '4
Const Invalid_font_id = &H05                                '4
Const Invalid_file_operation = &H06                         '4
Const Invalid_crc = &H09                                    '4
Const Invalid_baud_rate = &H11                              '4
Const Invalid_vaweform_id = &H12                            '4
Const Invalid_variable_name = &H1A                          '4
Const Invalid_variable_operation = &H1B                     '4
Const Assignement_failed = &H1C                             '4
Const Eeprom_operation_failed = &H1D                        '4
Const Invalid_parameters_quantity = &H1E                    '4
Const Io_operation_failed = &H1F                            '4
Const Escape_char_invalid = &H20                            '4
Const Variable_name_to_long = &H23                          '4
'return codes valid  in all cases
'00 00 00 FF FF FF =>Nextion starup                          '6
Const Serial_buff_overflow = &H24                           '4
Const Touch_event = &H65                                    '7
' 65 00 01 01 FF FF FF
' |   |  |  |
' |   |  |  event 01=press, 00=release
' |   |  component ID
' |   page number
' touch event
Const Curr_page_num = &H66                                  '5 second byte is page num
Const Touch_awake_coordinate = &H67                         '9
Const Touch_sleep_coordinate = &H68
 'first two bytes is X
 'next two bytes is Y
 'last byte is event 01=press, 00=release
 'eg. 67 00 7A 00 1E 01 FF FF FF
Const String_data = &H70                                    'varied len eg.70 xx xx xx xx xx xx FF FF FF
Const Numeric_data = &H71                                   '8 eg.71 xx xx xx xx FF FF FF  <-4bytes 32bit value, little endian
Const Auto_sleep = &H86                                     '4
Const Auto_awake = &H87                                     '4
Const Nextion_ready = &H88                                  '4
Const Micro_sd_upgrade = &H89                               '4
Const Transp_data_finished = &HFD                           '4
Const Transp_data_ready = &HFE                              '4

Macro Nexend                                                'to end a tx sequence--------------------------
     Printbin #nex , &HFF ; &HFF ; &HFF
End Macro

Macro Nexq                                                  ' to send quote before or after a sentence---------
     Printbin &H22
End Macro

Sub Set_return_level()
  'how much return will be sent over serial
  'LEVEL (2 is default)
  '0=no return command will be sent
  '1=only confirm succes commands
  '2=only if command failed
  '3=all return command from &H00 to &H23 will be sent
   Print #nex , "bkcmd=1";
   Nexend
End Sub

Dim Nex_buff(30) As Byte , Nex_idx As Byte , End_cnt As Byte , Min_len As Byte
Dim New_long As Long At Nex_buff(2) Overlay
Dim New_string As String * 29 At Nex_buff(2) Overlay
'for touch event
Dim Touch_page As Byte At Nex_buff(2) Overlay
Dim Touch_id As Byte At Nex_buff(3) Overlay
Dim Touch_state As Byte At Nex_buff(4) Overlay              '1=press , 0=release
'for coordinates
Dim New_x As Word At Nex_buff(2) Overlay
Dim New_y As Word At Nex_buff(4) Overlay

Call Set_return_level


Do



  '--[ USART0 COM1 USB ]------------------------
  If 0 < Ischarwaiting(#usb) Then

   Char = Inkey(#usb)
    Cmd_timeout1 = 10                                       '

   Select Case Char
    Case 10 : Got_str1 = 1
    Case 13
    Case Else
     Command1 = Command1 + Chr(char)

   End Select

   If Len(command1) > 49 Then Got_str1 = 1

   If Got_str1 = 0 Then Cmd_timeout1 = 50                   '50x10ms

   'end if Ischarwaiting
  End If

  '--[ PARSE COM1 USB ]-------------------------
  If Got_str1 = 1 Then


        If 0 < Instr(command1 , "AT+RST") Then

          Print #usb , "Reseting in progress..."
                 
          Config Watchdog = 16
          Start Watchdog
          Do : Loop

        Elseif 0 < Instr(command1 , "AT+ON") Then

           Print #nex , "sendxy=1";
           Nexend

        Elseif 0 < Instr(command1 , "AT+OFF") Then

           Print #nex , "sendxy=0";
           Nexend

        End If

      Got_str1 = 0
    Command1 = ""
   Cmd_timeout1 = 0


  End If

 '--[ USART1 COM2 nex ]---------------------
  If 0 < Ischarwaiting(#nex) Then

    Incr Nex_idx
     Nex_buff(nex_idx) = Waitkey(#nex)
     Cmd_timeout = 10                                       'unnecessary

    If Nex_idx = 1 Then                                     'check what type of msg we receiving
     Select Case Nex_buff(1)

      Case 0
       'it can be 4bytes Invalid_instruction
       'or 6 bytes Nextion_startup (may be after reset)
        Min_len = 1

      Case Touch_event
        Min_len = 4
      Case Touch_awake_coordinate                           '9 bytes
        Min_len = 6
      Case Touch_sleep_coordinate                           '9 bytes
        Min_len = 6

      Case String_data                                      'it will be string with variable len
        Min_len = 2
      Case Numeric_data                                     'there can be FF`s so we must wait for 8 bytes
        Min_len = 5

      Case Else
        Min_len = 1                                         'rest of return`s have one byte followed three FF`s

     End Select

    Else
                                                        'msg continue
     If Nex_buff(nex_idx) = &HFF Then
      If Nex_idx > Min_len Then

       If End_cnt < 2 Then
        Incr End_cnt

       Else                                                 'we received third FF

'         '-----------------------------[ DEBUG ]----------
'          Debug #usb , "Debug=> ";
'          For N = 1 To Nex_idx
'           Debug #usb , Hex(nex_buff(n)) ; " ";
'          Next
'          Debug #usb , ""
'         '------------------------------------------------

         'parse
          Select Case Nex_buff(1)

           Case Invalid_instruction

            If Nex_idx = 4 Then
             Debug #usb , "Invalid instruction!"
            Elseif Nex_idx = 6 Then
             Debug #usb , "Nextion rebooted OK"
            End If

           Case Instruction_okay
             Debug #usb , "Command accepted"
           Case Invalid_variable_name
             Debug #usb , "Variable or component NAME not recognized!"

           Case Touch_event
             If Touch_state = 0 Then
              Debug #usb , "Relased object " ; Touch_id ; " on page " ; Touch_page
             Else
              Debug #usb , "Pressed object " ; Touch_id ; " on page " ; Touch_page
             End If

           Case Touch_awake_coordinate To Touch_sleep_coordinate

              Swap New_x                                    'big endian order received
              Swap New_y
              Debug #usb , "Coordinates are: X=" ; New_x ; " Y=" ; New_y

           Case String_data
             Helpb = Nex_idx - 2
             Nex_buff(helpb) = 0                            'add string terminator
             Debug #usb , "New string=> " ; New_string


              'You can parse commands/data here


           Case Numeric_data
             Debug #usb , "New value=> " ; New_long

             'If you expect numeric data from Nextion then it will be here

          End Select




          Nex_idx = 0
          End_cnt = 0
       End If

      End If
     End If

    End If


  End If


 '--[ TIMER2 10ms ]----------------------------
 If Tifr2.ocf2a = 1 Then
  Tifr2.ocf2a = 1

  If Cmd_timeout1 > 0 Then
   Decr Cmd_timeout1
   If Cmd_timeout1 = 0 Then
     Command1 = ""
   End If
  End If

  If Cmd_timeout > 0 Then
   Decr Cmd_timeout
   If Cmd_timeout = 0 Then
    Nex_idx = 0
    End_cnt = 0
   End If
  End If



  '10ms
 End If


Loop
End
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Aug 09, 2019 2:49 pm    Post subject: Reply with quote

congratulations, I have not managed to operate a nextion with an Arduino
you did it !

I would like you to send me your private email address
I would like to discuss with you on a topic of development
JP yes Jean-Pierre Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Aug 09, 2019 3:10 pm    Post subject: Reply with quote

EDC,

I forgot to give me mine : jp030405 at yahoo.fr

JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Jerry

Bascom Member



Joined: 25 May 2004
Posts: 40
Location: New York

usa.gif
PostPosted: Wed Nov 27, 2019 5:51 pm    Post subject: Reply with quote

Fantastic work.
I just ordered a 10.1" Nextion display, looking forward to learning how to use. Thank you very much for the information.
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Nov 29, 2019 6:50 pm    Post subject: @EDC Reply with quote

hi dear professor EDC Wink

with a arduino2560
your idea to use port 0 as a control screen is great with Debug
but unfortunately I don't understand your program:
we are in an endless Do___loop loop
in my program I open a page and then wait for an event to occur as it is pressed on a window or field
in return I get the device number and the values that correspond to the field. In your program I don't know where to find these indications

example
Code:


'*******************************************************************************
' get a value from a tool sending a value from byte to long
'*******************************************************************************
Function Nex_onevalue(byval Text_id As String) As Long
   Local Gtext As String * 15
   Local Xvalue As Integer
   Local Lvalue As Long
   Local Lvalue2 As Long
   Gtext = "get " + Text_id + ".val"                        'Request The Actual Value
   Print Gtext;
   Nexend                                                   'macro which send &hFF,&hFF,&hFF
   Call Nex_return()

   Xvalue = Tabreturn(3) * 256
   Lvalue = Tabreturn(4) * 65536
   Lvalue2 = Tabreturn(5) * 16777216
   Nex_onevalue = Xvalue + Tabreturn(2)
   Nex_onevalue = Nex_onevalue + Lvalue
   Nex_onevalue = Nex_onevalue + Lvalue2
End Function
 


do you want to explain to me?
what is timer2 used for?
and where is the sub Set_return_level()


I lost half of my hair Crying or Very sad
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum