Start a new topic

myNextion.buttonToggle PROBLEM

Hello guys, I'm trying to use buttonToggle but it seens to be not working...


I'm using right like this:


myNextion.buttonToggle(button2State, "b3", 0, 1);


the button name id "b3", I don't know what's this "0" and "1" and when I try to change de "button2State" It gives a error


Sorry, not familiar with that format. It's not Iteadlb formatted.


Next Steps:

 a) Contact authors of library for support

 b) Read their library code to find your error


Don't worry... Do you know another way to change button state from Arduino? Thanks a lot.

I have no clue what you are trying to do.

b3 generally refers to the Nextion Button Component.

it is momentary logic only when pressed screen side


So if you are trying to change state on a non dual-state ... ahh

Sorry, I'll explain what I'm trying to do...


I've a physical button, I want to change the button state in my Nextion screen after physical button press. The button which I'm using in my Nextion LCD is a dual state button.


I can do the reverse operation, I can send a string from Nextion telling my arduino which state is the button in my Nextion Screen, but I can't change the button state from my Nextion LCD from my arduino.




I'll explain the example here:

I have:

1x Dual-state touch button

1x Led

1x Nextion LCD


What I need:


when I press the Dual state button then the Led turns ON and Nextion LCD dual-state button goes to ON(or 1)...


when I press the Nextion LCD dual state button to turn off the LED, then the Led turns off and the dual-state touch button goes off too... (I already did this, it's working, but I can't do the reverse operation)


Just print a string from your Arduino to the Nextion corresponding to the events .


Either...


Serial.print("b3.val=0");

Serial.write(0xFF);

Serial.write(0xFF);

Serial.write(0xFF);


for the 'Off' condition or


Serial.print("b3.val=1");

Serial.write(0xFF);

Serial.write(0xFF);

Serial.write(0xFF);


for 'On'


Proper terms help

- please don't refer to Nextion as an LCD

- Nextion has logic, LCDs do not.


Missing from your example:

- which Nextion Series/Model

- which library / or straight code

- what is in your HMI

- which component Button or Dual-state button

- how button is configured in HMI, solid color/image


Nextion Series makes a difference

 - if Enhanced Series Model - possible to hook Dual-State button to GPIO and bind via cfgpio command and button/DualStateButton in Nextion HMI.


If indeed this was a button, then b3 is accurate as component in HMI

If it is a dual-state button, then bt3 makes more sense.


Your logic would be flawed to think that a physical dual state can act in this manner

- How could a virtual button press a physical dual state and lock into new position?

- Physical Dual State Button is in wrong state to Virtual HMI Dual State


But I am most uncertain if it is electronics, logic or Arduino understandings missing.

I would have suggested that Steve, but ...

A button b3 does not have a .val attribute to set

Indeed Patrick,


It's about the best I could decipher from the information he supplied, sort of talking about 1 or 0 logic...


" Nextion LCD dual-state button goes to ON(or 1)..." 



I am trying to figure out what he needs.


If indeed a physical Dual-State locking

 - code needs to be based on physical and controlled MCU side

If it is controlled screen side, then Screen and Physical will be out of sync


The use of his code example introduces yet another lib I haven't yet seen

- or it could be he missed on trying to code it, and lib we may know.


@indev2 I'm using pins 10 and 11 for Nextion, they're not Serial... I'm using AT Mega 2560 board...



@Patrick Martin

Should I call it Nextion display?

My nextion in 3.5" non enhanced model

I'm using Nextion.h library

The component is a dual staate button which I renamed it from "bt3" to "b3"

The button is configured with 2 images, when I press it, it changes the icon image...


- How could a virtual button press a physical dual state and lock into new position?

As I said, it was an example, I'm using IOT with Nextion display. The "physical" button is the button in IOT app... 

"The use of his code example introduces yet another lib I haven't yet seen":


Yes, I'm using a different library, I thought it was the genuine Nextion library...,



"If it is controlled screen side, then Screen and Physical will be out of sync"

Yes! That's what's happening and I don't want to happen it, I want to sync them... I can send commands from Nextion display to Arduino, but I can't send commands (like changing the state of a dual button state) from my Arduino to my Nextion...



Then if you have renamed a dual-state button component to b3

  (that is an important piece of information)

- The button is configured with 2 images

- The dual-state button is configured with 2 images.


Since you don't have an Enhanced - binding is out of the question


use what indev2 suggested. 

Serially send ("b3.val=0ÿÿÿ") or ("b3.val=1ÿÿÿ") as needed


If you had just a plain button configured with 2 images then you could change images

sending ("b3.pic=3") and ("b3.pic=4") could accomplish the same


Nextion.h doesn't state which library - it is a common file name used

IOT or the Internet of things is a group of many - non specific either.


I hope you see where accurate specifics make a huge difference.

Nextion.h is also the main file in the Iteadlib Arduino Nextion Library



 

#include "Nextion.h"

/*
 * Declare a dual state button object [page id:0,component id:1, component name: "bt0"]. 
 */
NexDSButton b3 = NexDSButton(0, 1, "b3");
uint32_t : button3state;

void toggle_b3(void) {
   if(button3state==1) {
    button3state = 0
  } else {
    button3state = 1
  }
  b3.setValue(button3state);
}

void setup(void)
{    
    nexInit();
}

void loop(void)
{
   toggle_b3();
   delay(1000);
}

 

Thanks for the advices. I'll download the Itead Library later (I'm not in home now) then I'll test that code and will post results here. 

Login or Signup to post a comment