News:

Let's find out together what makes a PIC Tick!

Main Menu

Nextion HMI boards

Started by JohnB, Jun 14, 2022, 01:55 AM

Previous topic - Next topic

JohnB

Has anyone had any success in sending numbers to the display? 
I have no problem sending text e.g. Label.txt="myLabel" but numbers don't seem to be recognised.
In the Nextion simulator, I can write lines like Hrs.val=12 and it updates the object but I haven't found a way to do this down the serial interface. Anything I send is ignored.
JohnB

Yasin

Dear @JohnB, the page is in Turkish. If you use a translation it will be useful.

https://www.picproje.org/index.php/topic,72079.msg564755.html#msg564755

There are 27 educational videos on this channel. But Turkish language LOL


atomix

Here is the code that works for me:

$define NxtStnEnd 255 + 255 + 255
Dim s As String * 48

Proc HMI_SendString(CompName As String * 8, id As Byte)
s = CompName + ".val=" + Str$(Dec id) + NxtStnEnd
HSerOut [s]
EndProc

JohnB

I must have tried every combination bar that one.  Here's my code nearly identical except for Str$(Dec Value).   

$define NxtStnEnd "ÿÿÿ"    ',255,255,255

GoTo _Nextion_Procs_

dim s as string*48

proc HMI_SendNumber(Object As String * 10, Value As byte)
  s = Object+".val="+Str$(Dec Value)+nxtstnend
  HSerout2[s]
EndProc

proc HMI_SendString(Object As String * 8, Message As String * 32)
  s = Object+".txt="+$22+Message+$22+NxtStnEnd
  HserOut2[s]
EndProc

 Thanks its updating now
JohnB

JohnB

I noticed that Send Number is returning an error code of ␚ÿÿÿ. I dont know what that means until I have translate it.  Atomix, do you get a response from the HMI device when you send a number
JohnB

atomix

No. I send a value to the progressbar and everything works fine.

JohnB

Its still updating the number correctly so not sure what it means. 
JohnB

Maxi

Johnb, may be you need to close lcds mistake code return
sorry I can not explain good

try send this code first "one time"
HRSOut "bkcmd=0","ÿÿÿ"

JohnB

l'll give it a try later but I am off line for a few hours.  Thanks for all the inputs  I'll publish the project when its done.
JohnB

joesaliba

Yes John,

I will send the library later.

Regards

Joe

joesaliba

John, what is the error it returns?


joesaliba

John,

Below is the library I use many moons ago. Not the most elegant way how to do it, but it works.

Look for tWrite to change text.

Not at my PC at the moment, but I know I have a working example sending text.

Dim sData   As String * 40
Symbol EoF = $FF
'========================================================================================
' Navigate to pages in Nextion; nPage("page name")

$define nPage(pName)                '
sData = "page " + pName + 0         '
HRSOut1 Str sData , EoF , EoF , EoF
'Print At 3,1, Str sData

'========================================================================================
' Change text box font colour
' tbColour("page name" , "text box id" , "font colour No.")

$define tfcolour(pName, tbName, fColour)            '
sData = pName + "." + tbName + ".pco=" + fColour + 0'
HRSOut1 Str sData , EoF , EoF , EoF + 0              '
sData = "ref " + tbName + EoF + EoF + EoF + 0       '
HRSOut1 Str sData

'========================================================================================
' Change text box background colour
' tbColour("page name" , "text box id" , "back colour No.")

$define tbColour(pName, tbName, bColour)            '
sData = pName + "." + tbName + ".bco=" + bColour + 0'
HRSOut1 Str sData , EoF , EoF , EoF + 0              '
sData = "ref " + tbName + EoF + EoF + EoF + 0       '
HRSOut1 Str sData

'========================================================================================
' Change text content of text box, button ,etc...
' tWrite("page name" , "text box / button id" , "text"

$define tWrite(pName, tbName, Text)                 '
sData = pName + "." + tbName + ".txt=" + $22 + Text + $22 + EoF + EoF + EoF + 0 '
HRSOut1 Str sData

'========================================================================================
' Change picture of text box, button ,etc...
' pWrite("page name" , "text box / button id" , pic or pic2

$define pWrite(pName, tbName, Pic, Pic_No)                 '
sData = pName + "." + tbName + "." + Pic + "=" + Pic_No + EoF + EoF + EoF + 0'
HRSOut1 Str sData                                          '
'sData = "ref " + tbName + EoF + EoF + EoF + 0              '
HRSOut1 sData

'========================================================================================
' Component disable
' comEnable("comName")

$define comDisable(comName)    '
sData = "tsw " + comName + ",0" + EoF + EoF + EoF + 0'
HRSOut1 Str sData

'========================================================================================
' Component enable
' comEnable("comName")

$define comEnable(comName)    '
sData = "tsw " + comName + ",1" + EoF + EoF + EoF + 0'
HRSOut1 Str sData

'========================================================================================
' Timer enable
' tmeEnable("page name" , "Timer name")

$define tmeEnable(pName, tmeName)                 '
sData = pName + "." + tmeName + ".en=1" + EoF + EoF + EoF + 0 '
HRSOut1 Str sData

'========================================================================================
' Timer Disable
' tmeDisable("page name" , "Timer name")

$define tmeDisable(pName, tmeName)                 '
sData = pName + "." + tmeName + ".en=0" + EoF + EoF + EoF + 0 '
HRSOut1 Str sData

'========================================================================================
' Load variable
' var1("page name" , "variable id" , value)

$define vWrite(pName, varName, value)    '

sData = pName + "." + varName + ".val=" + value + EoF + EoF + EoF + 0'

HRSOut1 str sdata

JohnB

According to the Nextion API documentation I should be able to set the visibility of an object.  This is supposed to apply to all versions.  I am using the Basic Nextion HMI and the vis instruction is simply ignored.  Is this documentation just wrong or am I missing a point?
JohnB

joesaliba

vis t0,0 sent as text should hide, in this case t0.

vis t0,1 sent as string should make t0 visible.

In a project I have I use it in a different way, directly from HMI, not sending through PIC.

However, I think that HRSOut "vis t0,0","ÿÿÿ" should do the trick.

Joe

JohnB

Ah, I understand now how its used, and yes it works.  I had assumed that it would be an attribute.
JohnB

joesaliba

John,

When I did some work with Nextion there was no procedures so I used the $define.

Before I rewrite everything to a procedure I have a question.

As procedures have their local variable, in this case mostly strings, which will take less PIC space, procedure or $define?

Regards

Joe

JohnB

#16
Local variables do take up RAM space, they are not recycled. I suggest you do the following:
Create few global variables that you need, in the case of strings make sure they are as long as the longest variable.
Now in the procedure you alias to global variable to the local variable name.
This means you only need as many variables as are required by the procedure with the most local variables.
You basically did that in your Nextion library as you reuse sData:

Dim sData   As String * 40
Symbol EoF = $FF
'========================================================================================
' Navigate to pages in Nextion; nPage("page name")

$define nPage(pName)                '
sData = "page " + pName + 0         '
HRSOut1 Str sData , EoF , EoF , EoF
'Print At 3,1, Str sData

'========================================================================================

If you were to re-write this as a procedure it would look like this:

proc nPage(pName as String[40])
Dim pName as sData
pName = "Page"+PName + 0
HRSOut1 Str pName, EoF , EoF , EoF
EndProc
So in essence both will have a similar demand on RAM

In this example there is nothing in it but it will make code more readable when you have more complicated procedures using many variables.
JohnB

tumbleweed

If you alias them to global variables, make sure your procedures do not call other procedures using the same globals/aliases

top204

#18
You canot have the code:

Proc nPage(pName as String[40])
Dim pName as sData


Because both the parameter and the local variable have the same name, and the String parameter will give an error because its syntax is for an array.

It should be:

Proc nPage(pName as String * 40)

You do not need to alias the parameter within the procedure, because as far as the procedure is concerned, the pName parameter is a String variable with the name "pName". Parameters are actual variables, so they can be treated as normal variables within the procedure itself.

The only time that is not the case is if the parameter is sent as ByRef or BycRef, in which case, they are a Word variable that holds the address of the variable or flash memory passed to the procedure. Commonly known, incorrectly, as Pointers, but they are actually Address Of.

John Drew

If I'm battling for RAM I reserve a global variable(s) for temporary  use inside procedures only e.g. wInsideProc
John