ITEADLIB_Nextion published on Particle Build

I am trying to use a Nextion 2.8 with my Particle Photon. I was able to get the CompButton example to work just fine with the Web Build. But I try to build in the Particle Build, I get errors that dbSerialPrintln and dbSerialPrint, nexLoop, and nexInit are not defined.

It appears that the Web Build library is version 0.0.11 and the gitHub version is version 0.8.0. Which is current? If 0.0.11, where can I get it?

Thanks,
Doug

This is the GitHub repo for 0.0.11
https://github.com/ScruffR/ITEADLIB_Nextion/tree/master

I guess you used the develop branch which is a work-in-progress which has some open building sites (and will for some time due to lack of time ;-))

That worked. Many thanks. I had looked at that one, but the version.txt said “0.8.0” as well.
– Doug

Version.txt refers to the ITEAD version the ports was based on and since I have changed quite a bit of the interna (and more to come) I chose to have my own versions for Particle Build.

spark.json is the place to find the “Particle” version.

Yeah, the code is kind of funky. Not awful, but not good. Anyway, it looks like it works for what I want, which is pretty simple. I’m going try real hard not to get sucked into fixing the library.
– Doug

Yup, hence my endeavour to get the library completely OOPed but that’s a long way to go and sooo little time.

The current version was mainly a copy of the original plus some additions for unsupported functions and the Particle specifics.

I have hit an issue with having millis() based timers in the loop(). Seems like they block nexloop(nex_listen_list); Is there any workaround for this?

Could you post your code?
I wouldn’t see why non-blocking delays (what I understand when you say “millis() based timers”) should interfere with nexloop().

I commented out the millis() that runs set() and buttons b5 and b6 work. When the loop is working the buttons seem to not respond.

Here is the entire sketch

#include "Particle.h"
#include "PietteTech_DHT.h"
#include "ITEADLIB_Nextion.h"
#include "TimeAlarms.h"
#include "NCD16Relay.h"
#undef now()

void n0PopCallback(void *ptr);
void b5PopCallback(void *ptr);
void b6PopCallback(void *ptr);
void t0PopCallback(void *ptr);
void t1PopCallback(void *ptr);

NexNumber n0 = NexNumber(4, 8, "n0");
NexButton b5 = NexButton(4, 9, "b5");
NexButton b6 = NexButton(4, 10, "b6");
NexText t0 = NexText(2,4,"t0");
NexText t1 = NexText(2,5,"t1");

NexTouch *nex_listen_list[] =
{
        &n0,
        &b5,
        &b6,
        &t0,
        &t1,
        NULL
};

void n0PopCallback(void *ptr)
{
        dbSerialPrintln("n0PopCallback");
        n0.setValue(50);
}

void b5PopCallback(void *ptr)
{
        uint32_t number;

        dbSerialPrintln("b0PopCallback");
        Particle.publish("b5");

        n0.getValue(&number);

        number += 1;
        if (number > 24)
        {
                number = 1;
        }
        n0.setValue(number);
}

void b6PopCallback(void *ptr)
{
        uint32_t number;

        dbSerialPrintln("b1PopCallback");
        Particle.publish("b6");

        n0.getValue(&number);

        number -= 1;
        if (number < 1)
        {
                number = 24;
        }

        n0.setValue(number);
}

void t0PopCallback(void *ptr)
{
        String r = Time.format(Time.now(), "%I:%M%p.");
        t0.setText(r);
}

void t1PopCallback(void *ptr)
{
        String r = Time.format(Time.now(), "%F");
        t1.setText(r);
}

void set()
{
        String r = Time.format(Time.now(), "%I:%M%p.");
        String s = Time.format(Time.now(), "%F");
        t0.setText(r);
        t1.setText(s);
}

void formatTime()
{
        struct tm * timeinfo;
        time_t timeNow = (time_t) Time.now();
        char buffer[80];
        time(&timeNow);
        timeinfo = localtime(&timeNow);
        strftime(buffer,80,"%I:%M%p",timeinfo);
        Particle.publish(buffer);
        //puts(buffer);
}

void setup()
{
        Time.zone(-7);
        /* Set the baudrate which is for debug and communicate with Nextion screen. */
        nexInit();

        /* Register the pop event callback function of the current number component. */
        n0.attachPop(n0PopCallback);

        /* Register the pop event callback function of the current button0 component. */
        b5.attachPop(b5PopCallback);

        /* Register the pop event callback function of the current button1 component. */
        b6.attachPop(b6PopCallback);

        t0.attachPop(t0PopCallback);

        t1.attachPop(t1PopCallback);

        dbSerialPrintln("setup done");

}

void loop()
{
        /*
         * When a pop or push event occured every time,
         * the corresponding component[right page id and component id] in touch event list will be asked.
         */
        nexLoop(nex_listen_list);
        if (millis() > 1000)
        {
                set();
        }


}

Before I test your code some suggestions:
You don’t need Time.now() in code like this

String r = Time.format(Time.now(), "%I:%M%p.");

just write

String r = Time.format("%I:%M%p.");

now will be assumed.

I’d do this on the display side and keep it out of your code

        number -= 1;
        if (number < 1)
        {
                number = 24;
        }

        n0.setValue(number);

Great points. I will implement them right now. I was actually following the example in comptext but what you’re suggesting makes more sense. That way the only listeners i will need are the actual set button on every page.

1 Like

I don’t think logic is right:

if (millis() > 1000)
        {
                set();
        }

That’s basically going to be always be true, so the display updates every time through loop. I think you probably want this to update once per second:

    if (millis() - lastUpdate > 1000) {
        lastUpdate = millis();
        set();
    }

And at the top, a global variable:

unsigned long lastUpdate = 0;
3 Likes

Yes that was it. My loop was always true and blocked anything else from running.

1 Like

Hello,

Anybody has some good advice on how to implement a “Clear” button for clearing the data in waveform object?

I’d have to play around with this, but how about a page switch?
Does this not clear the components on the deactivated page?

Hi, Thanks for the answer! I got similar answer elsewhere. So do you think a bank page should be shown for a moment and than jump back to the main page or there should be two identical pages switching back and forth between them as I press the clear button?

That depends on your desired user experience and other components on the page.
A third option would be a “mock-up page” that only shows an image of the actual page.

Hi,
All right I will try tomorrow one or two of these and give you my feedback on my experience. Cheers!

Question… Shouldn’t these lines:
Serial.write("p0.rest"); Serial.write(0xff); Serial.write(0xff); Serial.write(0xff);
clear my screen?

So far the
page0.show();
works only.

I don't think there is a page reset, only a full reset or a page refresh.
Try

  Serial1.write("page 0\xFF\xFF\xFF");
  // or  
  Serial1.write("rest\xFF\xFF\xFF");

You can always test your commands in the NextionEditor Debugger.

And if you want some components to keep their status (beyond a page refresh), just declare them global in NextionEditor. rest will still reset them.