View previous topic :: View next topic |
Author |
Message |
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Sat Jul 15, 2017 2:34 pm Post subject: Nextion Display works with bascom |
|
|
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 |
|
Back to top |
|
|
aphawk
Joined: 23 Jan 2010 Posts: 168 Location: Brazil
|
Posted: Sat Jul 15, 2017 7:52 pm Post subject: |
|
|
Hi, Duval,
Very nice !!!
Where you bought this display ?
Thanks !
Paulo |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Sat Jul 15, 2017 8:30 pm Post subject: |
|
|
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
It seems simpler to use than the FT8xx series. (which have great speed as well) _________________ Mark |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Sun Jul 16, 2017 9:49 am Post subject: |
|
|
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 [/url] |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Mon Nov 12, 2018 3:15 pm Post subject: |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Mon Nov 12, 2018 8:06 pm Post subject: |
|
|
Hello JP,
Nice to see your project here. Thanks for sharing and for making the video. I enjoyed watching it. _________________ Mark |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 1038
|
Posted: Fri Aug 09, 2019 10:45 am Post subject: |
|
|
Hello Mr Duval JP (Jean Pierre ? I`m from Poland but I was learn four years French ) I really like it
"Regard la bas, se Philipe , nes pas?" ahahahaha this is the quote from the first page of our primer-french-book
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
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Fri Aug 09, 2019 2:49 pm Post subject: |
|
|
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 _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
Posted: Fri Aug 09, 2019 3:10 pm Post subject: |
|
|
EDC,
I forgot to give me mine : jp030405 at yahoo.fr
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
Jerry
Joined: 25 May 2004 Posts: 40 Location: New York
|
Posted: Wed Nov 27, 2019 5:51 pm Post subject: |
|
|
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
|
Back to top |
|
|
mkcreta
Joined: 10 Dec 2006 Posts: 16
|
Posted: Sat Jun 29, 2024 4:40 am Post subject: problem with serial and ds3231 |
|
|
hello i try to use on my program some of Duval JP code i am using bascom avr 2.0.8.6 when i use the include ds3231 the com port stop transmitting i try the code with 3 differed Arduino uno boards and with ATmega2560 board.
on ATmega2560 i have an error with the Const Pink = 65017 in declarations.inc the error is Error : 13 Line : 115 CONST already specified [PINK] , in File : declarations.inc
, if i remark this line i can compile the program with no errors but in the IDE when i use color=pink the word PINK is capitalized by the IDE and the color of the word pink is the same with the PORT.
i believe this is a bug the compiler think is the PIN[K] and not the color pink
This is the code
Code: | $regfile = "m2560def.dat "
$crystal = 16000000
$hwstack = 40
$swstack = 16
$framesize = 32
$baud = 115200
Pump1 Alias Porte.4
Pump2 Alias Porte.5
Flow Alias Portg.5
Demand Alias Porte.3
Beep Alias Porth.3
$lib "i2c_twi.lbx"
Config Pump1 = Output
Config Pump2 = Output
Config Flow = Input
Config Demand = Input
Config Beep = Output
Config Scl = Portd.0
Config Sda = Portd.1
Config 1wire = Porth.4
Config I2cdelay = 5
Config Twi = 400000
Config Clock = User
Config Date = Dmy , Separator = /
Const Ds3231r = &B11010001 'Ds3231 is very similar to DS1307 but it include a precise crystal
Const Ds3231w = &B11010000
Dim S_second As String * 4 , S_minute As String * 4 , S_hour As String * 4
Dim S_dow As String * 8 , Dow As Byte , A As String * 20
Dim Color As Word
$include "declarations.inc"
$include "macros.inc"
$include "ds3231.inc"
Nxtinit
Waitms 500
'Serin A , 0 , Portd , 2 , 115200 , 0 , 8 , 1 : Print A
'Input A : Print A
Print "time.txt=" ; : Nxtq : Print " 6/16/2024 5:10 PM" ; : Nxtq : Nxtend
Waitms 500
Color = pink
Print "p1onoff.bco=" ; Color ; : Nxtend
Waitms 500
Print "p1onoff.txt=" ; : Nxtq : Print "ON " ; : Nxtq : Nxtend
Print "here"
Do
Color = Green
'Print "set " ; " color = " ; Color
Print "p1onoff.bco=" ; Color ; : Nxtend
Waitms 500
Print "p1onoff.txt=" ; : Nxtq : Print "ON " ; : Nxtq : Nxtend
Set Pump1
Print "p2onoff.bco=" ; Color ; : Nxtend
Waitms 500
Print "p2onoff.txt=" ; : Nxtq : Print "ON " ; : Nxtq : Nxtend
Set Pump2
Wait 10
Color = Red
'Print "reset" ; " color = " ; Color
Print "p1onoff.bco=" ; Color ; : Nxtend
Waitms 500
Print "p1onoff.txt=" ; : Nxtq : Print "OFF" ; : Nxtq : Nxtend
Reset Pump1
Print "p2onoff.bco=" ; Color ; : Nxtend
Waitms 500
Print "p2onoff.txt=" ; : Nxtq : Print "OFF" ; : Nxtq : Nxtend
Reset Pump2
Wait 2
Loop
|
and this is a print screen because when i post the code the color = pink is looking normal
|
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1173 Location: France
|
|
Back to top |
|
|
mkcreta
Joined: 10 Dec 2006 Posts: 16
|
Posted: Sat Jun 29, 2024 2:12 pm Post subject: |
|
|
Quote: | hi,
yes it's disturbing this pink, I changed in my last versions with "rose" which is the French translation |
You right JP i didn't thing about it, in my language we use the French name "POZ (ROZ)" for PINK
JP
why when i include "ds3213.inc" the arduino uno or 2560 freeze this file is a copy from your file "I2C-DS3231.inc" i just rename it
any idea why dose that?
Thanks
Mike |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 6025 Location: Holland
|
Posted: Sat Jun 29, 2024 3:27 pm Post subject: |
|
|
it is not a bug. PINA, PINB, etc. are port registers. you should never create a constant with the name of a port/ddr/pin register !
And it is a good idea to begin a constant with the letter c : const cPink=whatever , that will work. _________________ Mark |
|
Back to top |
|
|
|
|
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
|
|