Start a new topic

Not reading values from textbox on arduino

 Hi,

Ive got the nextion 3.2" hooked up to a mega 2560 and Ive got a working keypad that i can enter a number into when i click on a textbox, when i finish entering data i press the OK button on the keypad menu and the number entered is displayed on page 0 in the text button.  Im trying to read the values into the nextion with the following code but it doesnt seem to work. It dispalys in the serial monitor that the ok button is clicked and that the received string has a value of 0 no matter what i type in.

ive included the code for anyone interested:

#include "Nextion.h"
#include <stdlib.h>
char buffer[100] = {0};
NexButton kok = NexButton(2, 11, "kok");

NexText mobile = NexText(1, 1, "mobile");
NexTouch *nex_listen_list[] =
{
  &mobile,
  &kok,
  NULL
};
void setup() {
  // put your setup code here, to run once:
  nexInit();
  kok.attachPop(kokPopCallback, &kok);
  dbSerialPrintln("setup done");
  delay (50);
}
void loop() {
  // put your main code here, to run repeatedly:
  nexLoop(nex_listen_list);
}
void kokPopCallback(void *ptr)
{   
  memset(buffer, 0, sizeof(buffer));
  mobile.getText(buffer,sizeof(buffer));
  String dayofmonth = buffer;
  Serial.println(dayofmonth);
 
  }

1 Comment

Whoops, sorry its this code im using. button kok is on page 2 and has an ID of 11 and the text box 'mobile' is on page 1 with an ID of 1. I seem to only ever get a 0. I thought i had it working before but i dont know, Ive been comparing it to the Nextion sample code. Any ideas?  Thanks guys

 

 

#include "Nextion.h"
void kokPopCallback(void *ptr);
NexButton kok = NexButton(2, 11, "kok");

NexText mobile = NexText(1, 1, "mobile");

char buffer[100] = {0};
NexTouch *nex_listen_list[] = 
{
  &mobile,
   &kok,
    NULL
};
void kokPopCallback(void *ptr)
{   uint16_t len;
    uint16_t number;
      memset(buffer, 0, sizeof(buffer)); 
     mobile.getText(buffer,sizeof(buffer));
     number = atoi(buffer);
     dbSerialPrint(number); 
   }
   
void setup(void) {
   nexInit();
   kok.attachPop(kokPopCallback);
   dbSerialPrintln("setup done"); 
   delay (50);
}
void loop(void)
{
 nexLoop(nex_listen_list);
}

 

Login or Signup to post a comment