ITEADLIB_Nextion published on Particle Build

I uploaded the comptimer example and the corresponding tft for it. The buttons dont do anything. i can press them but i dont see any change in values

RX to TX and TX to RX. That solved it. Thank you for the help. I have connected the relay shield to a pump, lights and a solenoid. I will be working on building schedules and making them work through the touchscreen.

2 Likes

@Ali Post some pictures of your screen setup when your done if you can.

Iā€™m looking to working with my Nextion screen in the near future but have not had time to dig into the software yet.

By screen setup you are referring to the physical connections to the Screen.

No Iā€™m just wanting to see what your custom screen layout looks like.

Thatā€™s COMPTEXT

Thanks!

I just like to see what other people are up to.

im trying to use a DHT 22 to show values on the Nextion. Any ideas?

Hmm, yes. Just look at the CompText or even the CompWaveform demo.
And if you need to know how to use the sensor, there will be demos and discussions too.

So I donā€™t quite get what more ideas you need :confused:

@Bspranger, @peekay123 and whoever else feels like it :wink:

If you like and have some time, could you have a look at my current work-in-progress (develop branch) on extending the library
https://github.com/ScruffR/ITEADLIB_Nextion/tree/develop

Iā€™ve added getters/setters for all component attributes I could find.
I also added a NexDisplay master class (#include "ITEADLIB_Nextion.h" rather than Nextion.h) instead of calling the standalone functions from NexHardware.h
Already in the Web IDE lib included are Graphing.h/.cpp to expose standalone darwing primitives and I plan on incorporating them into NexDisplay.h/.cpp.

As first test demo Iā€™ve adapted CompTimer.INO to show how I thought it could look like.

/**
 * @example CompTimer.ino
 * 
 * @par How to Use
 * This example shows that ,when the OFF button component on the Nextion screen is released,
 * the timer will opened,the text will show number changed and push the ADDTIME button timer 
 * cycle value will increase,when push the DECTIME button timer cycle  value will reduce.
 *
 * @author huang xianming (email:<xianming.huang@itead.cc>)
 * @date    2015/8/25
 * @copyright 
 * Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
*
* Adapted for Particle devices by ScruffR 12/2015
 */

#if defined(PARTICLE_BUILD)
#include "ITEADLIB_Nextion/ITEADLIB_Nextion.h"
#else
#include "ITEADLIB_Nextion.h"
#endif

NexDisplay display;
//NexDisplay display(Serial1, 9600);

NexButton b0 = NexButton(0, 2, "b0");
NexButton b1 = NexButton(0, 5, "b1");
NexButton b2 = NexButton(0, 6, "b2");
NexText t0 = NexText(0, 3, "t0");
NexText t1 = NexText(0, 4, "t1");
NexTimer tm0 = NexTimer(0, 1, "tm0");


char buffer[100] = {0};
uint32_t number_timer = 0;
uint32_t number_enable = 0;
uint32_t number_cycle = 100;


/*
 * Button component pop callback function. 
 * In this example,the button can open the timer when it is released.
 */
void b0PopCallback(void *ptr)
{
    if(number_enable == 1)
    {
        tm0.enable();
        number_enable = 0;
        b0.setText("ON");
    }
    else if (number_enable ==0)
    {
        tm0.disable();
        number_enable =1;
        b0.setText("OFF");
    }
}
/*
 * Button component pop callback function. 
 * In this example,the timer's cycle value will increase when it is released. 
 */
void b1PopCallback(void *ptr)
{
    tm0.getCycle(&number_cycle);
    number_cycle = number_cycle + 100;
    tm0.setCycle(number_cycle);
    memset(buffer, 0, sizeof(buffer));
    itoa(number_cycle, buffer, 10);
    t1.setText(buffer);
}

/*
 * Button component pop callback function. 
 * In this example,the timer's cycle value will reduce when it is released. 
 */

void b2PopCallback(void *ptr)
{
    tm0.getCycle(&number_cycle);
    if (number_cycle >100)
    {
        number_cycle = number_cycle - 100;
    }
    tm0.setCycle(number_cycle);
    memset(buffer, 0, sizeof(buffer));
    itoa(number_cycle, buffer, 10);
    t1.setText(buffer);
}

/*
 * The timer respond function 
 * In this example,the timer will respond when set cycle time done and puls one for a variable. 
 */

void tm0TimerCallback(void *ptr)
{
    number_timer++;
    memset(buffer, 0, sizeof(buffer));
    itoa(number_timer, buffer, 10);
    t0.setText(buffer);
}


void setup(void)
{    
    display.init();
    display.add(b0);
    display.add(b1);
    display.add(b2);
    display.add(t0);
    display.add(t1);
    display.add(tm0);

    b0.attachPop(b0PopCallback);
    tm0.attachTimer(tm0TimerCallback);
    b1.attachPop(b1PopCallback);
    b2.attachPop(b2PopCallback);

    dbSerialPrintln("setup done"); 
}

void loop(void)
{   
  display.nexLoop();
}

Iā€™d appreciate all sorts of feedback :worried: :sunglasses:

I just ordered one of these. Iā€™m working on a Mac using OS X El Capitan. Do I have to use the Sexton screen configuration software from ITead with this or can you create all of the screen elements on the fly in code?

Nope, you canā€™t create components on the fly (for the time being).
Youā€™d need to use the Nextion Editor (or a third party clone, if you can find one for OSX).

Ok, thanks for the quick response - Iā€™ll have to see what I can find - it will be a while until it gets here from China anyway.

@ScruffR, thanks for porting library to Particle.

However I have some some problems and/or missing something crucial :confused:

I have bought Nextion 3.5" touch display module and I have connected it with Photon:

VIN -> +5V
GND -> GND
TX -> RX
RX -> TX

I have tried couple of examples (CompButton and CompText) from the library BUT when I press button from the screen, Photon will restart when button will be released on the screen???

This is output when I monitored serial during CompButton example:

C:\Windows\System32>particle serial monitor
Opening serial monitor for com port: "COM5"
NEX_RET_EVENT_TOUCH_HEAD[53688403
C:\Windows\System32>particle serial monitor
Opening serial monitor for com port: "COM5"
NEX_RET_EVENT_TOUCH_HEAD[536884036:0,1,b0,(
C:\Windows\System32>particle serial monitor
Opening serial monitor for com port: "COM5"
NEX_RET_EVENT_TOUCH_HEAD[536884036:0,1,b0,(null)
C:\Windows\System32>particle serial monitor
Opening serial monitor for com port: "COM5"

I had to recompile Nextion examples, because TFTā€™s from example have been made to lower screen resolution than my screen is using.

I would appreciate any ideas how to solve this, because now Iā€™m banging my head to the wall

Iā€™ll have to have a look.
Iā€™m still in the middle of getting the lib to the next level (ahead of ITEAD), for which Iā€™ll also rework the samples.
At the moment the samples are still the original code of ITEAD and I have only tested them on my 2.4" displays.

@tao, are you by any chance using a non-automatic SYSTEM_MODE() or SYSTEM_THREAD(ENABLED)?

Iā€™ve just tested the samples and they seem to work on my 2.4" and 4.5" displays, but only in default SYSETM_MODE(AUTOMATIC) withouth SYSTEM_THREAD(ENABLED).
With any other constellation I do see Serial1 to block in the middle of a call for some obscure reason.

Iā€™ll have to spin up a hardware debugger for that issue, but Iā€™ve not yet been this deep down into the bare metal of the Particles, so it might take some time - sorry :flushed:

1 Like

@ScruffR, thanks for quick answers :grinning:

Iā€™m using default settings for SYSTEM_MODE (which I believe is AUTOMATIC) and without SYSTEM_THREAD(ENABLED).

I also set SYSTEM_MODE(AUTOMATIC) before setup function, but it didnā€™t change the behavior ā€¦ still crashing/booting when button will be released from the screen. I did try SYSTEM_MODE(SEMI_AUTOMATIC), but nothing changed.

I have tried with two Photons, but results are same with both ones

If you have very low cloud latency you might see my issues with non-AUTOMATIC in AUTOMATIC too.
Iā€™ve pinpointed a timing issue in nexLoop() where I relied on the cloud to slow things down enough, but didnā€™t :blush:

BTW: What version of my lib are you using and in what dev env?

1 Like

Now examples are working with me also, tried CompButton and CompDualStateButton :relieved:

Earlier I used Particle Dev and downloaded library from Github, spark.json shows that version is 0.0.11. But when I compiled example in Particle Build with library version 0.0.10, examples are working.

Thanks for pointing to library versions and dev env. I have used to use Particle Dev environment and rarely used web based Build :grinning:

I see - 0.0.11 used to be my develop version, which is still work in progress since itā€™ll break compatibility with ITEADā€™s own lib but should incorporate OOP paradigm a bit better.

At the moment Iā€™m trying to push 0.0.11 with a fix for the timing issue as ITEAD-compatible to Web IDE and develop will become version 0.1.x.