Start a new topic

Global variable are not available

Hello there,
the global variables are only on one side available.
It makes no difference if the variable is declared local or global.
The variable is on a new page not available.

In loving memory of those privileged 80286's who had a chance to see the internet in their ripe age. I wait patiently for your font editor. If the generated font is even 80% of the picture quality ill take it and get rid of all the extra art work. 

Well, the employers do have a great deal of power. :)   I have seen a situation where Generals wanted to have their 80286's on the Internet, and that was that.  I pity the two guys that had to make it happen, but they pulled it off.  Let me put a rush on finishing up the Font Editor. 

The key to it is that it gives you more control throughout the font generation process.  Rather than just staring at an X, it allows you to preview the font attributes you are selecting (the missing Italics, Strikeout and Underline are included)  I have also been able to swap out a font character for a Unicode character when generating the characters.  (You have to request the original character to get the Unicode to display).  The biggest issue in the generation process is "removing the antialiasing" which on all newer than Windows 98 starts as anti-aliased rendering.  There is two ways of doing this - rendering in Monochrome, or adjust the color filter manually.  The Editor will at least give the user this choice and on some fonts gives a better font, though there is no magic sequence of R/G/B filter values that guarantee, it is a trial and error.  Top that off with being able to edit out the pixels that offend and the user ends up with the best font that was possible.  So the theory goes.  I'm back to a rush on it.

I would say my file size would be down to about half or even less. I am actually following the other threads that mention you're going to release the font editor in 2 weeks. If i can make fonts look better i would be more than happy to get rid of all the extra images. 

Honestly an offending pixel does not bother me but my employers are used to iphones and androids and it is hard to have an argument with them on technological limitations especially since i am developing an app that duplicates the UI on a smartphone. 

I am going to explain the fonts.  (You have to either like the old DOS font above, or hate it, but I showcased it in the above two).  I think the key to the fonts is to realize the pixel is either on or off - set to the color your text is going to be.  What makes your font look bad?  Many times it is an offending pixel out of place, so if you can change that offending pixel - then huh - not so bad.

Years ago before Windows XP, there was no such thing as font smoothing or antialiasing (they add pixels of different colors next to the rendered font to give the visual illusion that the font stroke is a clean smooth stroke)  Take a screen shot and zoom in, way in, and you will see the pixilation that is occurring on our desktops, tablets and phones -- they require huge libraries and massive cpu power to do so (hence most video cards have more ram, speed and cores than the desktops).  Everyone could throw in all the electronic components into their project and basically rebuild an iPhone, and their projects would be super pricey.  But this is the embedded world, with small tiny inexpensive components.  I am not certain many projects would be attempted if we were into $1500 US for hardware before we started writing any code.

And there are some pricey components out there that give huge power.  The Intel Edison I mention was about $90 when I got it, comes with a dual-core atom processor running 500 MHz, an separate embedded MCU, 54 IO lines, 1GB of RAM and 4GB of storage.  Bluetooth and WiFi built in, and an extremely powerful Linux OS - all in about the size of a postage stamp.  Ten years ago, this was the specs of my Webserver I had connected to the Internet backbone running 63 websites.

So, where the only way to get a smooth line to our fonts is blowing up pictures and chewing out all of our storage resources, or do we start looking at removing and adjusting an offending pixel.  How big would your project be if you could contain it in a font?

BTW, I will be releasing a better font editor to do that, I keep saying in about two weeks - I have to get back to it :)

Two more notes.

With an Arduino and SPI lines you can setup more flash on the Arduino side (to be pushed over serial), there is more electronics and soldering to it than just simply stating it.  But it is worth noting that a 16MB flash chip is inexpensive.  W25Q128FVSSIG in Quantity of 10s for under $15 USD on ebay.  Paired with SOP-8 breakout boards give you pin access (the manuals are large).  And by the time you went that far, some 1/2GB chip was probably easier :)  Just nice to know that it can be done.   Also an SD card is also an SPI device so Arduino has huge expansion possibilities on that side of the connection (and there are Arduino libraries already made for the SD card FAT32 file system all over the net).

Also note that Fonts although they are represented in a single color, are only 1 bit per pixel for storage.  I made a Chess board and Yahtzee game where the pieces and dice are a font character and thus 16 times less storage.  If there are segments of your screen that change in the font size (16x16 or whatever) and you can live with the solid color, that can be another space saver as we run out of space.

@Patrick Yea that is pretty bare metals. I have used a lot of images because the fonts don't look good enough so most of my button texts have become images. Basically each screen is 2 full screens using crop to show active state. 


The sendme command is always sent over serial, all HMI designs are capable of responding to it, there is no special HMI for it (it is in the Instruction Set page here)  As far as the Arduino links to the GitHub files it is listed in the FAQs here

I can't assist much in the Arduino code, I am a pascal programmer using Kylix3 on Linux with the Intel Edison ... I'm kind of a bare metals man.

Your graphic files are your biggest resource hog if you are hitting close to the 16M limit.  You will soon need to address them.  The Nextion only offers three means I can think of.

1) Smaller pictures placed only where you need them and not a full screen picture

2) Crop images, to pull a segment of a full page picture forward to your page layer

3) Pushing some of the smaller images over serial (if your Arduino has plenty of storage)

4) Check out some of the Gui Design commands in the instruction sets (link above) to see if some parts of your page can be generated through commands for regions of your pages.  That becomes more solid colors (though one could work out gradients) and that certainly takes less space to issue commands than 800x480x2 (768000 bytes on the 5" and up) for a full sized screen images.

Be sure your bauds setting is the highest stable value it can be without generating errors.

baud= (sets for this session until reboot)  while bauds= (sets it to the default power on value)


You can also always check to see which page the user is on so you know which Text Component to update by sending over serial "sendme".   Using the sendme command will return 0X66 0X02 0XFF 0XFF 0XFF will be returned where 0x66 is the sendme event, 0x02 is page 2 and 0xFF 0xFF 0xFF is the end of data terminator.

Do you have an example of an HMI that uses the send me command? And an ino file. 

That would kind of work for my case. I will have to re write some code on the Nextion but its no biggie. 

Also just to add i really like the product. i just have a lot of pages in my Touchscreen and i am running out of memory. WIsh i had more that 16mb.

Where is the eeprom?  Is it connected Arduino side or is this eeprom built-in on the new Enhanced Version Nextions? (I haven't played with them yet, so I will first describe the Basic models).

On reboots the Nextion is going to loose all user changes to the variables, and load in all default values.  The Arduino, you can easily attach a piece of SPI flash etc.  I am making the assumption that the Arduino and the Display will loose their power at the same time, and start up at the same time.

So on clean start, power just came on - you are getting the user to enter his choice of F or C and that you will store until the next reboot.  One method in a settings page the user can choose between two hotspots for either F or C.  (In the HMI editor tick the "Send component ID" in each hotspot)

This will send data out over serial back to the nextion each time it is pressed.  The data will be in the format 0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF - where 0x65 is the touch event 0x00 is the page number, 0x02 is the component id 0x01 where the press has occurred and 0xFF 0xFF 0xFF is the end of data terminator.  (Swap the press 0x01 with a 0x00 on release).

On the Arduino, setup a listener to catch the data coming in.  When you see that your F touch area has been pressed, you can set it in your Arduino code, likewise if C was touched, set it.  Based on their choice, send a "page newpage" command back to the nextion to take the user to where they need to go.

Now as your Arduino receives new temperature information comes in, you Arduino already knows the users selected choice.  Your Arduino has floating point math that the Nextion Display does not.  Make your calculation on the Arduino and push the value over serial back to the Nextion temp.txt="58.2F".

You can also always check to see which page the user is on so you know which Text Component to update by sending over serial "sendme".   Using the sendme command will return 0X66 0X02 0XFF 0XFF 0XFF will be returned where 0x66 is the sendme event, 0x02 is page 2 and 0xFF 0xFF 0xFF is the end of data terminator.

In the above scenario, I have not used any global variables in the Nextion HMI design, and it is all on the Arduino.

Now regarding graphic files.  Normally there are 3 or 4 bytes to represent the color of a pixel.  In the case of RGB 24-bit color, the values of 0..255 represents Red (one byte), and 0..255 for blue and green (bytes 2 and 3).  In 32-bit color which includes an alpha channel there is a 4th byte 0..255 for the level of transparency.  Each and every graphic file format has to read the picture from storage and expand this to the display, 3 or 4 bytes for each and every pixel, sometimes with large libraries to do so.  So in memory, the graphic is always (Width x Height x bits) /8.   

In the Nextion they use the 565 format which is a 16-bit representation taking 2 bytes of space per pixel.  the highest 5 bits are Red, the middle 6 are green, and the lowest 5 are blue.  ... for each and every pixel Width x Height x 16/8 (or 2 bytes per pixel).  Where the onboard MCU of the Nextion Display really isn't big, there is no real way to put an extensive graphics library in (there'd be no room for running an HMI) and the time it takes to do the processing graphics each time a change is made would really make for a poor interface.  So all graphics end up stored in their expanded format allowing fast access to an individual pixel if need be. (column in the width x height + row in the height) x2 is the address ... ah, next to bytes are our pixel color    :)

Storing the graphics Display side allow for much faster access than if you were to try and push each pixel over the serial lines ... and with that concept the age of Human Machine Interfacing was born.

Here's a scenario. I have to set units to either C or F from one of the settings screen. Now i have programmed the screen to do what i need to do and it works well. At page load it checks value of sys0 and depending on that shows the correct option selected. If i could read sys0 from the arduino by doing a getVar.sys0 then i can use that int he callback function and store it to eeprom. When the unit is rebooted i can use that stored value to setVar.sys0= at setup. 

Also how come adding a graphic file of size 20kb takes almost 400kb of memory once its loaded on the display?

@Heretic Specifically,

How do you mean access some variables from the MCU at startup? When you say MCU are you speaking about an MCU (Arduino, etc) connected to the Display, or are you talking about the STM32F030C8T6 mcu that is on the back of the Nextion Display?  These variables are they the variables to the HMI, or on the connecting Arduino (like having read a temp sensor- now set it on the display)? 

Just being curious. There wouldn't be many reasons for a whole lot of booleans on the basic model Display - it is more just a display, like your desktop and its monitor (you really don't program to store data in the monitor ram that needs to be read back - your variables are elsewhere and as they change you push the display changes needed to represent the changed variable).  The value in the display is outdated, no longer relevant, the new superceding value of importance, and so we push new values.

IF you have an MCU connected to the display, the start up variables are stored on your MCU, and you use serial to then set your display on startup (every attribute that was bold green in your hmi design can be set over serial), and your connected MCU will probably have more storage resources than the display

Just being curious

@Patrick that is basically what i am doing using. Assigning 1 and 0 to the sys value and using the if condition. I however need to access some variable from the MCU at startup. In any case thank you for your help and explanations.

The sys0 sys1 and sys2 variables are numeric only, each with a 32 bit range.  So sys0.val=12  They do not require page.sys0 as they don't belong to a page.  They will behave as any other global numeric variable. There is no Boolean type, so you have to check with:









Thankfully there are nested if statements now, but you still cannot have a complex condition.

Also remember there is a sleep command that can be woken on touch or serial.  If you are not going to cut power out completely (and resuming from an exact state), sleep plays a nice role.

@ Patrick  got it!! what about the sys0, sys1 variables? is there a way to set them from the MCU. Basically im using sys var as a boolean to pass around values from page to page but on startup i will need to set this to a default depending on the last state it was in.

They have to be declared inside the HMI design *.hmi, and thus *.tft compiled output.

Variables in the HMI design are accessible.  There is no means to create one dynamically afterwards

Also note that x and y coord values are static in the design and are not relocatable.

I can not change the coord values (via t0.x=23) during execution.

I can however, create a component in the hmi design and set its visability to true or false on demand, allowing a component to appear as if it were dynamically created, but again I can not change its position

Login or Signup to post a comment