Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Nextion reading a number or string from a object
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
rwlee

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Sun Aug 21, 2022 4:24 pm    Post subject: Reply with quote

Paulvk,
Thanks for your help, so presum that I use the get #1 command to retrieve the answer from the nextion, at some point need to clear the buffer ?

Thanks, Wayne
Back to top
View user's profile
rwlee

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Sun Aug 21, 2022 9:35 pm    Post subject: Reply with quote

I get a compile error

Error : 44 Line : 30 2 variables expected , in File : D:\MCS\Programs\Nextion-Test\Read RTC-2.bas

print #2 , num_test.val=10

Num_test.val is the objname in Nextion it's a number Box

I tried to separate the and assign to variables, I don't get any errors but there is nothing coming back from Nextion.

dim _Num as string * 12
_num = "Num_test.val="

call nextion

Sub Nextion
Printbin #2 , &HFF ; &HFF ; &HFF
Waitms 100

End Sub
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Mon Aug 22, 2022 8:15 am    Post subject: Reply with quote

sending , num_test.val=10 is not ok.
i think you need to send the ID (a number).

you can use inputbin to read the input.

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

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Mon Aug 22, 2022 12:08 pm    Post subject: Reply with quote

Ok have arrived somewhat unpacked.

Its best to start with a simple screen the button , text box and number box.
Then just write simple code to talk to the nextion.
Or do what I did first and use a terminal program , I used realterm with a rs232 to TTL adaptor on my PC
to send and receive commands its very suited to this as it has two send boxes
so you can keep the 0XFF 0XFF 0XFF in one and send it as a number while using
the other to send text commands .

Now there is really no advantage in "I tried to separate the and assign to variables"
if you do not want to write something many times in bascom you just assign it to a constant.

With the nextion if you create a button and under the touch press event you put prints "text001",0
the nextion should send text001 when you press the button you can then confirm if you have it
hooked up correctly I have a couple of rs232 to TTL units that had TX & RX marked the wrong way around
spent some minutes trying to work out why it was not working.

So best to confirm its working before trying to write a lot of code in bascom.

Regards Paul
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Thu Aug 25, 2022 10:30 am    Post subject: my contribution Reply with quote

Hi
i just give you a small example

and I add a zip file with
- program
- tuto in PDF and powerpoint
- picture files
- HMI file
the video :https://youtu.be/7T40DF3LYvw

i you need help ,I'm back from vacation I'm rested!
Wink
JP

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

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Fri Aug 26, 2022 2:19 pm    Post subject: Reply with quote

Thanks Duval JP,

I've been using Realterm and 2 MAX232CSE Modules to debug with , I noticed than in the send window from Nextion on the real term I was getting a CR and LF which was causing Nextion to not respond, after research I found that adding ; at the end of every print statement all started working, I think I'm on my way now I'm communicating with the Nextion very well now

Thanks, Wayne
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Fri Aug 26, 2022 4:18 pm    Post subject: time to give the way to see the time Reply with quote

Hi rwlee,
I add the time, (the date will come from monday
I do step by step because a lot of people come crazy with nextion, me too !


I use slicer because is funny, you can use button or what you want

So As yesterday I add
- program
- tuto in PDF and powerpoint
- picture files
- HMI file
no video, i'have no time, but sure it works ! Wink
I must say RTC of Nextion is not so good as DS3231 , and it is an efemism
Again you mus dim your var as long not byte Idea

_________________
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: Wed Aug 31, 2022 4:49 pm    Post subject: Continuation and end Reply with quote

Hi
I add the date today, again with nextion not so easy to read back the dates but the sub works well now
I hope it can help you

I clean the include "sub_macro_nextion_base.inc" , if you use it and found some mistake let me know

the video :
https://youtu.be/Lt85sGaZNOg

jp Wink

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

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Thu Sep 01, 2022 4:08 am    Post subject: Re: my contribution Reply with quote

[quote="Duval JP"]Hi
i just give you a small example

Thanks again for the Info

Wayne
Back to top
View user's profile
rwlee

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Mon Nov 20, 2023 10:15 pm    Post subject: ATMEGA 328p Dosen't repond to Nextion NX3224K024 Reply with quote

So I tested the output of the Display, and it works directly with the PC Terminal Emulator, to Print "Hello World" on the comport. But when I connected to the MCU I cant capture the input!

I even tried spliting the Serial output of the so the output of the Nextion display goes directly into the 328p But I get Nothing!

Code:

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 19200
$hwstack = 64
$swstack = 64
$framesize = 64
Config Submode = New
Debug On


Config Com1 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Echo Off
Config Serialin0 = Buffered , Size = 30                     'RX from Terminal
Open "COM1:" For Binary As #1
Const Nex_ = 1

Dim Buf_  as Byte
Dim Loop_Cnt as Byte

Print #Nex_ , "Starting"
Do
  Wait 1
   Buf_ = Ischarwaiting(#Nex_)

      If Buf_ = 1 then
         Loop_Cnt = Inkey(#Nex_)
         Print #Nex_ , "Loop_Cnt " ; Loop_Cnt
      Else
         Print #Nex_ , "Nothing "
      End If
   Loop
End




Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Nov 20, 2023 10:40 pm    Post subject: Reply with quote

It is a "classic mistake" Wink
For buffered Serialin you can`t forget to "Enable Interrupts"!
I know because, years ago, I take that lesson too Very Happy ahahahahaha

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
rwlee

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Mon Nov 20, 2023 11:08 pm    Post subject: ATMEGA 328p Dosen't repond to Nextion NX3224K024 Reply with quote

Thanks, EDC

That did it, but I can't find any examples of how toput together as string extracted from each byte, Is there anyway to grab the entire string at once?
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Mon Nov 20, 2023 11:18 pm    Post subject: Reply with quote

You can try like that.. there is plenty of solutions.
Code:
Dim Resultstring As String * 30

If 0 < Ischarwaiting(#Nex_) Then

Dim Char As Byte

Do
 Char = Inkey(#Nex_)
 Select Case Char
  Case 13  :                'CarriageReturn ->swallow
  Case 10  :                'NewLine ->got string ->processing
     Print Resultstring
     Resultstring = ""     'clear the string for new message
  Case Else
   If Char > 31 Then
      Resultstring = Resultstring + Chr(char)
   End If
 End Select
Loop Until Ischarwaiting(#Nex_) = 0

End If    

Sometimes you must take care about length of the string (to not exeed *30 here).
Sometimes is good to introduce some timeout for entire string.

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
rwlee

Bascom Member



Joined: 04 Aug 2008
Posts: 36
Location: La Porte, Texas

usa.gif
PostPosted: Tue Nov 21, 2023 12:57 am    Post subject: Reply with quote

So I'm Getting the entire Sring but its not formatting Correctly, I had to modify your code because I wasn't getting any thing.

Code:
Dim Resultstring As String * 30
'Print #Nex_ , "Starting"

If Var_ = 1 Then
   'Print #Nex_ , Var_
  Do
      Char = Inkey(#Nex_)
      Select Case Char
       Case 13  :                'CarriageReturn ->swallow
       Case 255  :                'Nextion Outputs before anything
          Print #Nex_ , Resultstring
          Resultstring = ""     'clear the string for new message
       Case Else
        If Char > 31 Then
           Resultstring = Resultstring + Chr(char)
           Print #Nex_ , Resultstring
        End If

      End Select
  Loop Until Ischarwaiting(#Nex_) = 0
End If

Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Nov 21, 2023 7:39 am    Post subject: Reply with quote

Previously I post a general receive routine for "typical" communication.
If you want to communicate with Nextion in both directions you must invest more time to learn Very Happy

Please look at my old post -> https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&p=77756#77756

PS. Receiving weird characters it is often symptom of wrong baudrate. Nextion communicate at 9600 by default I think. Not yours 19200.

_________________
Check B-Flash -my MCS bootloader app for Android
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 -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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