Start a new topic

Examples not working

Hi guys,


I have bought an Iteaduino Uno and Nextion Display 2.8". I have uploaded the fish tank project, just to try out some functions. It seems i always get the same error(attached file) when i check the serial monitor in arduino IDE. I have also tried some examples from the arduino library, but still no success. I always receive the same message in serial monitor, and none of the button is working or change of text in text field.

PNG
(6.43 KB)

Hi, Boris,

if you use nextion_arduino_library,please try an arduino mega2560.

Hey,
so i figured out how to get my uno working and i tried an dualstate button example. Now started to happen folowing. I wired a dualstate button to pinLed13, so when i press the button LED goes from LOW to HIGH. Then I wanted to simulate a temperature because i dont have any temp sensor, I simply used a for loop to count. So i made a function and in that function i setText to a text field on a display. When i run the sketch, the counter is working but the dualstate button stops working. This is my code, please help.

 

#include "Nextion.h"

const int ledPin =  13;
/*
 *******************************************************************
 * Nextion komponente na strani: Osnovna, pageid:0 
 * 
 *******************************************************************
 */
NexDSButton zagon = NexDSButton(0, 4, "bt0");
NexText tempBojler = NexText(0, 2, "t0");
NexText tempKotel = NexText(0, 3, "t1");
NexText textStatus = NexText(0, 6, "t3");

/*
 *******************************************************************
 * Nextion komponente na strani: nastavitve page id:2 
 * 
 *******************************************************************
 */
 NexDSButton prednostno = NexDSButton(2, 3, "bt0");
 NexDSButton dimnikar = NexDSButton(2, 2, "bt1");
 NexText spBojler = NexText(2, 4, "t0");
 NexText spKotel = NexText(2, 5, "t1");

char buffer[100] = {0};
char buffer_dual_state[100] = {0};
char buffer_temperature[10] = {0};
char buffer_temp[10] = {0};

 NexTouch *nex_listen_list[]=
 {
  &zagon, &tempBojler, &tempKotel, &textStatus,
  
  &prednostno, &dimnikar, &spBojler, &spKotel,
  
  NULL
 };



void zagonPopCallback(void *ptr)
{
  uint32_t dual_state;
  NexDSButton *btn = (NexDSButton *)ptr;
  zagon.getValue(&dual_state);
  
  if(dual_state == 1) 
    {
        itoa(dual_state, buffer_dual_state, 10);
        textStatus.setText(buffer_dual_state);
        digitalWrite(ledPin, HIGH);
    }
    else
    {
        itoa(dual_state, buffer_dual_state, 10);
        textStatus.setText(buffer_dual_state);
        digitalWrite(ledPin, LOW);
    }
}

void simulate(){
  for(int i = 0; i < 10; i++){
    memset(buffer,0,sizeof(buffer));
    memset(buffer_temp,0,sizeof(buffer_temp));
    
    itoa(i,buffer,10);
    if(strcmp(buffer, buffer_temperature)){
      tempBojler.setText(buffer);
      strcpy(buffer_temperature,buffer);
      }
    
    }
  
  }


void setup(void) {
  // put your setup code here, to run once:
  
  pinMode(ledPin, OUTPUT);
  nexInit();
  zagon.attachPop(zagonPopCallback, &zagon);
  
}

void loop(void) {
  // put your main code here, to run repeatedly:
unsigned long nowtime = millis(); 
    unsigned long update = 0;
    if (nowtime > update)
    {
        simulate();
        update += 10000;
    }
 nexLoop(nex_listen_list);

 
}


 

 

#include "Nextion.h"

const int ledPin =  13;
/*
 *******************************************************************
 * Nextion komponente na strani: Osnovna, pageid:0 
 * 
 *******************************************************************
 */
NexDSButton zagon = NexDSButton(0, 4, "bt0");
NexText tempBojler = NexText(0, 2, "t0");
NexText tempKotel = NexText(0, 3, "t1");
NexText textStatus = NexText(0, 6, "t3");

/*
 *******************************************************************
 * Nextion komponente na strani: nastavitve page id:2 
 * 
 *******************************************************************
 */
 NexDSButton prednostno = NexDSButton(2, 3, "bt0");
 NexDSButton dimnikar = NexDSButton(2, 2, "bt1");
 NexText spBojler = NexText(2, 4, "t0");
 NexText spKotel = NexText(2, 5, "t1");

char buffer[100] = {0};
char buffer_dual_state[100] = {0};
char buffer_temperature[10] = {0};
char buffer_temp[10] = {0};

 NexTouch *nex_listen_list[]=
 {
  &zagon, &tempBojler, &tempKotel, &textStatus,
  
  &prednostno, &dimnikar, &spBojler, &spKotel,
  
  NULL
 };



void zagonPopCallback(void *ptr)
{
  uint32_t dual_state;
  NexDSButton *btn = (NexDSButton *)ptr;
  zagon.getValue(&dual_state);
  
  if(dual_state == 1) 
    {
        itoa(dual_state, buffer_dual_state, 10);
        textStatus.setText(buffer_dual_state);
        digitalWrite(ledPin, HIGH);
    }
    else
    {
        itoa(dual_state, buffer_dual_state, 10);
        textStatus.setText(buffer_dual_state);
        digitalWrite(ledPin, LOW);
    }
}

void simulate(){
  for(int i = 0; i < 10; i++){
    memset(buffer,0,sizeof(buffer));
    memset(buffer_temp,0,sizeof(buffer_temp));
    
    itoa(i,buffer,10);
    if(strcmp(buffer, buffer_temperature)){
      tempBojler.setText(buffer);
      strcpy(buffer_temperature,buffer);
      }
    
    }
  
  }


void setup(void) {
  // put your setup code here, to run once:
  
  pinMode(ledPin, OUTPUT);
  nexInit();
  zagon.attachPop(zagonPopCallback, &zagon);
  
}

void loop(void) {
  // put your main code here, to run repeatedly:
unsigned long nowtime = millis(); 
    unsigned long update = 0;
    if (nowtime > update)
    {
        simulate();
        update += 10000;
    }
 nexLoop(nex_listen_list);

 
}


 Is there maybe any other tutorial on arduino library besides fish tank?

Thanks in advance.

 

 Sorry about the double code.

Hi, Boris,
How far with DualState button?
I encountered the same problem - example not working and my code - well, can not understand what the problem is!
Have you come to a decision?
Thanks in advance.
Regards, Kulaksazov

 

Login or Signup to post a comment