I agree, although incrementing and decrementing are trivial enough cases that handling them on the Nextion side would not be at all unreasonable.

I find that the part of my code handling interaction with the Nextion is processed a number of times a second--such that delays from the back and forth to the picaxe are not noticeable to the user. For other circumstances, that would be one of the areas where YMMV, and offloading processing to the Nextion could improve response. I have not thus far found that to be needed.

Senior Member

My plan is to get the display to do the menial thing like value selection and handle menus. Hopefully that will make response times a bit faster and save code space on the picaxe.
With that in mind I maybe able to move this project from a 28X2 of the current version to a 20X2. Having this sort of interface also mean that less hardware pins are needed, which will hopefully mean that the final product can be smaller as well. If I can it down to the footprint of the display I will be very chuffed.

Senior Member

I was rudely awoken by some builder making a racket after 3 hours of sleep. the plus side of this is that I have now found a little time to have a look at the data coming from the display.
Its a little scruffy, should work for a nearly full scratch pad - the last 4 address will need to be zero value
The code look for 4 zeros in succession, then assumes the first three addresses is information, then looks for 3 $FF in a row and assumes the next three address have data.
I have test in the simulator for about a dozen sets of data being sent and seem to work fine - the pause at the beginning of the read back routine need to be there to ensure that all data has been sent before reading starts, I'm sure there is a way to detect when serial input has stopped but I haven't looked hard enough yet

Senior Member

Hi Oracale
Would you clarifiy a point for me are you trying to alter the value of a variable on the Picaxe or are you reading sensors via the nextion (if so I assum you have the enhanced modle)
If just changing wanting to change values the following works
If you want to read sensor values via the nextion you can terminate all reads as such print "h0.val" print"XXXX" using the X's as a termination then you know that a termination has occured

Senior Member

The idea is to be able to receive multiple pieces of data from menus in a single transmission.
Having the screen deal with selection values when moving from page to page the data needs to be sent as well as the new page. Some pages also have more than one data point to send. So finding the stop bits shows the beginning of the next set of data. I will try and get more iron up in the next couple of days

Senior Member

In the attached screen to values can be set, both these values are kept in range, increased and decreased by the Nextion. When the accept button is pressed both theses values are sent to the picaxe, the screen move to appropriate menu and send the new page number back to the picaxe meaning that 3 set of data is sent. The picaxe just now just has to put them into the correct variables which is why the page information is needed.
I have been using the get command, chose this it send the event that triggered the transmission 0X71 numeric value, 0X66 page ID, 0X65 touch event, 0X70 is sting in ASCII. This should allow thing to be identified if needs be.
so finding the stop values means that the byte after that is the type identifier followed by the information.
I am going to have to increase te number of zero to 5 as in some cases its possible for a zero value to be sent and miss identify the end of a data set.

seeing as the order of receiving is known, the picaxe just uses get to move the values into their respective variables for later use and the code space that is something like + code for multiplex keypad:
(code from original project)

to something like the in the my previous post. further to this, each menu will need something similar to original project for every display (granted without having to set the menu up). But having the Nextion deal with as much as possible mean that the code in the my previous post could be re-used for every menu as a sub-procedure with a few little tweaks.

The may well need to be checks when moving onto each page to ensure that the correct value is displayed, but all being square it shouldn't be needed.
I am going to do some more work on things and hopefully gain a deeper insight into dealing with issue that may arise.

Attachments

Senior Member

Hi Oracle
Still not fully sure what you want nextion to do ann what you want the picaxe to do
The nextion is grapicalUSERinterface machine
Are you trying to use it as a master for the picaxe
Are you concerned about loss of data when moving between pages if so look at post #108 and change where ive
used nvt=nvt to ref (your variable) making sure you have chosen the globle option for the nextion variable
that will alow it to be used across pages and page refreshes
Every time you open up a page in the nextion you are resorting back to the default page you created in
the editor

Senior Member

I am using the nextion as the full user interface - not just for graphics.
It will deal with increasing and decreasing values and checking for overflows/underflows - something we all have done - that information is then sent to the PICAXE.
this will be done on nearly every page which currently stand at 11 saving the code space of all those if statements

these next two is where the picaxe comes in:
when accept is pressed all the information is sent the picaxe

Code:

get mins_var.val
get sec_var.val
page Timers

the 2 variables will then be used by the picaxe to set minutes and seconds

each page has this in post-initialisation

Code:

sendme

which sends the page number the picaxe

so to increase the seconds value the picaxe has done nothing but wait for information and because it should know what page its on it will know where to put the information its received. Hopefully plenty of PICAXE code space will be saved, among a couple other advantages.

Senior Member

Hi Oracle
can you not use the touch release events
in the touched event print "ZZ" as an identifier to tell the picaxe what to do with them open page/ variable change coming
your if statement
on the release event va0.val=nst.txt ect
print nst,txt
I just found if you define what you want to enact apon is easier than interperating their messages
using ascii as an interpruter between the two systems
regards
john

this code puts the information from 6 different menu into their respective variables. the page number is now transmitted when leaving a page instead of opening a page. A after initialisation the only output from the picaxe is in the calibrate screen where it adjusts the bars. All overflow/underflow is dealt with on the nextion. I sure there is some space to be saved in the code, but that will come later

identifying things has been one of the easier thing to do - while the code currently only looks for either a page or a numerical value at the moment, there is no reason why is can't deal with other stuff as well

Senior Member

I bought a nextion and loaded the demo onto sim ok and it worked. That's as far as I got. I never got anywhere with the win dev and couldn't send print commands from picaxe or other systems so just got a driver and use it as serial glcd in another system. Much faster but serial is serial. Least I'm in command of it not a complicated interface. Glad people have got it working.

Senior Member

Hi Oricale
If you look on you tube royal newberry does a video on
moving values and text between pages
He places in the touch event box of say page0 for a component
n0.val=page1.n0.val
vscope global for each page getting the value from page 1 and displaying it on 0
regerds
john

Senior Member

Things are starting to come along a bit now.
The next question I have is more about cheating than anything else.
There is s section where I need to run @64mhz and setting the hserout to b9600_64 yield no results, ie the screen do not update. Is there anyway to update the display at those speeds.
I was thinking that maybe setting hserout to b1200_64 might do the trick but it doesn't work.
If there is not way of making it work I do have a work around.

Senior Member

I have a problem reading touch x,y.
X is 2 bytes received bigendian as is y.
My screen is 240x320.
x and y yalue are not pixel co-ordinates-- see video
240 axis ok but 320 axis gives 16 bit overflowhttps://youtu.be/spCpcNTdN5Q

Moderator

As "Patrick Martin" says, if you are asking (aka polling) the Nextion by doing a "get tch2" from the MCU (is it a PICAXE?) to get the x co-ordinate of the last touch position, then you will get a 0x71 headed reply with a four byte little endian value representing x

If you want to poll for the y co-ordinate of the last touch then it's a "get tch3" command and you will get a 0x71 headed reply with a four byte little endian value representing y

0x67 messages from the Nextion are the Nextion sending out the last touch event asynchronously i.e they will just arrive at the MCU when the screen is touched/released. They always come in pairs in my experience, with a 1 as the 5th data byte for the "press" and a 0 as the "release". However, just to be different the x and y co-ordinates of a 0x67 message are two byte little endian

Both these can be easily seen in the Nextion simulator:
- blank screen, no nextion code in it at all, click on screen then enter "get tch2" or "get tch3" in the "Instruction Input Area" and see the returned 0x71 message
- bank screen, "sendxy=1" in its Preinitialize event, click on screen and see the returned 0x67 messages

Senior Member

I got it working. I had to wait for recieved 0x71. I haven't used the simulator. I don't want to use nextion logic or code.
I used tch0 for x and tch1 for y. You can drag the pen to change x y.
Not picaxe code-
GLCDSendOpInstruction_Nextion( "get", "tch1" ) ;y
do
HSerReceive (myDummyByteIn)
loop until myDummyByteIn=0x71

Senior Member

The nextion system is a learning curve. Controlling the display with a mcu is more learning. Will use the simulator asap.
Getting the touch data is not clear.
The code I posted is blocking ie if no 0x71 recieved it loops. Should have been-
dim touchdata(8)
GLCDSendOpInstruction_Nextion( "get", "tch0" ) ;x
repeat 4
HSerReceive (touchdata(1))
if touchdata(1) = 0x71 then
for temp = 2 to 8
HSerReceive (touchdata(temp))
next temp
if touchdata(6) = 255 & touchdata(7) =255 & touchdata(8) = 255 then
[byte]myWordX = touchdata(2) : myWordX_H = touchdata(3)
end if
exit repeat
end if
end Repeat
This has 4 tries for receiving 0x71 x data, then if the last 3 bytes are 255 it passes x touch co-ords.
Same for y touch.

Senior Member

I have only been working with my project on and off over time, life and other things have been getting the way a bit.
however you don't have to wait around for things if your using hardware serial. you could use an interrupt on serial receive or a simple state of

Code:

if hserptr <> then gosub do_stuff

you can also receive everything and start reading the information before transmission has stopped. The following code is called from the above.

this code currently only reads back 4 pieces of information through sertxd. the data_check procedure can be updated to check for whatever you need, this only reflects what I needed at the time of writing.
The whole programme uses variable above the normal system variables as a receive buffer, once the above has completed a case event will find what page sent the information and put the received information into the correct variables. As a side note I found it easier to always send the page that the Nextion is on as my setup actually quite heavily uses the displays code and abilities to move through menus, do basic maths and selections. So instead of the picaxe waiting for an input and then doing a simple x+1 the nextion does. yes this mean the picaxe can either be doing something else, or is waiting for the nextion. one of the big upside for me is that this save a suprising amount of code space. This is not just due to having to do all the maths, but it does not have to draw the menus either. have in some cases have button appear and disappear depending on what has been displayed. sliders to select values and in one case a press and hold so that you don't have to constantly tap to move large amounts.

Due to what can be done in the display itself I would strongly advise anyone to use its abilities, there is so much that can be achieved very easily.

Senior Member

They are good in that complicated plot and line and even a guage with sin cos is done for you. using picaxe this is handy but any pic (328p is now a pic) can benefit from nice graphics and easy touch events.
There's 4gig of memory for storing your own images.
There's disappointments for me in that there's no moveable images, so games are out.
I use 115200 baud and a basic to asm compier and tried printing and erasing a char in forground background colour and it's slow so ploting a multicoloured sprite would be too slow. Shame since it uses an arm.
It's a while since I used picaxe basic but if I find info anyone wants I'll post.
ps I got it down to a sub,saved 20 bytes and can use get, tch 0,1,2,3. maybe useful
dim touchdata(8) , temp , xy_touchdata_ok as byte
dim xpress , ypress as word

Senior Member

Thanks to all the forum members I have a nextion 2.4 working with a 14M2. My unit came with a micro USB adapter for powering the unit or testing, the instructions are a bit vague. There is a warning about using insufficient power supply leading to module failure.

I ran the module on 3.3 Volts and it worked fine but the caution is concerning. Eventually I would like to run the project with a single LiPo cell.
Has anyone experienced issues running the Nextion module on voltages below 5V. I'm fairly certain there is a 3.3V regulator onboard but haven't looked at the schematic.

Senior Member

Thanks for the info, that makes a lot of sense. I have a number of those battery booster boxes and it does make sense to use it with a portable project. It's all self contained, charger, battery saver and regulator. I'll see if I wanna gamble with damaging the display, I know I will not gamble with large Nextion displays that get rather pricey.

New Member

I would just like to say thank you for the code, it has driven me in the right direction now as i have been struggling for past weeks, there will be no stopping me now, already have the 7" Nextion on the way. and thank you again, this has opened so many doors.

It works a treat, battery's have to be purchased separate though, if you purchase an led head torch rechargeable the battery's remove very easily, and are half the price of purchasing the battery's on there own.

Senior Member

hi
Being having a play with it myself have worked out how to alter multiple values of the page with only a + and - keys
To do this I used the timer variable in conjunction with a variable. Each of the hotspot(day temp hum,alarm,ect) for the values to be set or changed is given a value, the value is as assigned is then used with the plus key, when the minus key is selected the value is incresse by 1 ie 1 becomes 2, on reselection of plus key the value is decressed back by 1. While you keep the key depressed it alters sets the picaxe variable automatically adding 1 or subtracting 1 without the constent tip tapping of the key. The present state of the picaxe variable is then displayed on the screen under the selected action
Nextion Timer variable

"QU" is read by the picaxe and the picaxe determins what action to take ihe number keys hold the following 1( tx0.txt=tx0.txt+"1") 2( tx0.txt=tx0.txt+"2") 0=(tx0.txt=tx0.txt+"0") ,ect C= tx0.txt=tx0.txt-1 and the AC= tx0.txt=tx0.txt-4

New Member

As for as I remember, you don't need a controller like a PicAxe to control the Nextion display. The processor just provides data over a serial bus to be displayed on the display.
Simply put, with the editor from Nextion, you set up a program and look to be loaded on the display. This program actually controls the display and the communication with the PicAxe. The latter reads out sensors like humidity, temperature and pressure and sends this data to the display. The program you made with the Nextion-editor puts this data on the display on the places you want them to appear.
You can download the editor from Nextion and try it out on your PC. A brief look in the documentation gives me the impression that looks somewhat like Visual Basic that I learned about 10 years ago.

Senior Member

Hi depeet
I am using the nextion as a slave to alter the values of the variable of the picaxe, which then uses those values
as presets to determine actions to undertake determined by you the user.
The nextion is simply used a slave to report and display the state of the picaxes variables which can be altered at any time
dependent on the users requirmnets. No need to reprograme the picaxe to alter the presets to achive the desired outcome.
After selection the nextion simpley displays the outcomes of the attached sensors and what the picaxe has determined to do with those outcomes
turning items on or off warnings ect
What I was demonstrating that the simple touch release funtion of the hotspot can be altered with the nextion
timer variable to increment or deincrement with out constently tapping at the screen and by just using the same 2 keys all variables of the picaxe can be altered as an when required
by holding down the + or - keys it bounces in and out of the timer variable adding or subtracting the picaxes variable
without removing your finger from the screen automatically.

Senior Member

A week ago I received my Nextion 2.4" display in the mail, in a few hours time I was able to design a simple altimeter screen that shows the altitude, it's metric or english units, the current barometer setting, and the barometer units. My picaxe 18m2 reads an i2c sensor, makes the barometer corrections and updates the display.

So far, so good. I really like this little display. Mine is the advanced one, but I probably won't be using the extra stuff in this project.

I thought about a Nextion slider to set the barometer, but with the small display, it seems like the resolution isn't enough. A typical aviation barometer report is read to two decimals. This implies that an input device needs to be able to select one part in a thousand in extreme cases, and in most cases a few dozen. I can't see anything in the instruction manual that mentions a touch version of a rotary knob. Is this true? Or am I missing it?

Some alternatives I've been thinking about:

A push button above and below each of the barometer digits for incrementing, decrementing each digit.

Digit push buttons for a keyboard to enter each digit.

An invisible slider over each digit.

A set of invisible buttons, maybe ten, arranged in a circle that would implement a rotary, one finger operated knob.

Or, my fall-back route is to use hidden touch to get to a settings page where I don't care about cluttered or messy. Then a numeric keyboard would be no problem. And, I would be able to select metric or english units.

Senior Member

Hi have a look at my post #148
on your display create a hot spot over your barometer create a nextion variable and associate a value to the barometer touch event
create 2 small hot spots one for plus one for minus then create a nextion timer variable set the en of the variable to 0 I have found
a time dellay set in the variable of 400 works well. This will allow you to hold your finger on the area and it will keep incing or decing whilst your finger is on the screen. Then alter post 148 to suit your needs
On the picaxe side I tend to use ongosub to assist with the timings as you know what value you have associated to it then simply inc or dec
the picaxe variable for your needs

Senior Member

Hi have a look at my post #148
on your display create a hot spot over your barometer create a nextion variable and associate a value to the barometer touch event
create 2 small hot spots one for plus one for minus then create a nextion timer variable set the en of the variable to 0 I have found
a time dellay set in the variable of 400 works well. This will allow you to hold your finger on the area and it will keep incing or decing whilst your finger is on the screen. Then alter post 148 to suit your needs
On the picaxe side I tend to use ongosub to assist with the timings as you know what value you have associated to it then simply inc or dec
the picaxe variable for your needs

Your comment got me to thinking the nextion could replace nixie tubes. Here's a photo of the smallest nextion emulating a nixie display. Ambient light, reflections, my shaky hands, and some interaction with my camera and the display make for a not nearly as good as real life view, but you can get the idea. I simply used photos of all ten digits, added them to the display library, and can call them from the picaxe to place them where I want.

A typical picaxe statement to place digit 5 at x=85 and y=135:

serout b.6, T9600_32, ("pic 85,135,5",255,255,255)

The individual nixie digit pictures were sized to 70x100 pixels to fit the 320x240 nextion screen. The nextion small display, at $15 for the simple one beats $100 each nixie tubes, not to mention only 5 volts power supply.

Senior Member

Yep gotta see all the other screens not lit - and have those very interesting neon plasma spectrum bands... There were numeric indicators with engraved plexiglass numbers stacked and lit with incandescent lamps and so many other heroic attempts at numeric displays - we've come a long way... [not to mention the vertical 10 Ne2 neon tubes of yore... ;-0 ].

Senior Member

If the photo were better, you can see some of the support structure and unlit digits. I just got the photos off internet, but with a quality camera setup, and the real McCoy, I think they would look pretty good. l spent the morning fooling with this, and don't have more than a passing interest. Maybe my post will inspire someone to do it properly and use a larger display to build a clock. The nextion has a battery backed realtime clock on board. Another photo of frame around the nixies would look good, too.

Meanwhile my altimeter is working well. I settled on four buttons to adjust the local barometer setting. One each of +1, +10, -1, and -10. This makes large or small changes easy, and with a separate page for settings, the main page isn't cluttered.

Moderator

On a random sampling of a very few Nextion displays (although I've used about 50 so far on my projects), the accuracy of the Nextion RTC is, IIRC, of the order of +/- 3 minutes per day...
...so I use an onboard (and genuine) DS3232 for RTC purposes which gives me an accuracy of around 2 seconds per week.

The new "Intelligent Series" range of Nextion displays have several major functional enhancements - I have a 7" version for evaluation (paid for by me!) ... it's very good, but the gotcha of the Nextion 7" and 10.1" displays is that the pixels are not square, which gives all sorts of weird effects when you generate pictures on a "square pixel" display (e.g a PC) and then display them on the Nextion...circles are not circles any more