Start a new topic

.setText Error

I am trying out a simple program below which on the button Pop event changes the text of a text object. When I run it I get a debug error - recvRetCommandFinished err

and the text does not change. Here is the code:


 

#include "Nextion.h"

SoftwareSerial HMISerial(14,12);//See NexConfig.h for details

const int LED = 2;
bool POWER = false;

NexButton btnPower = NexButton(0, 8, "btnPower");
NexText txtTemp = NexText(0,1,"txtTemp");

NexTouch *nex_listen_list[] = 
{
    &btnPower,
    &txtTemp,
    NULL
};

void txtTempPopCallback(void *ptr)
{
  dbSerialPrintln("txtTemp");
}

void btnPowerPopCallback(void *ptr)
{
  dbSerialPrintln("Power");
  if(!POWER)
  {
    digitalWrite(LED, LOW);
    POWER = true;   
    txtTemp.setText("ON");
  }
  else
  {
    digitalWrite(LED, HIGH);
    txtTemp.setText("OFF");
    POWER = false;
  }
}
void setup() {
  nexInit();
  btnPower.attachPop(btnPowerPopCallback, &btnPower);
  txtTemp.attachPop(txtTempPopCallback, &txtTemp);
 
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  dbSerialPrintln("\nReady");
}

void loop() 
{
  nexLoop(nex_listen_list);
}

 



What MCU are you using?

What design decision led you to SoftwareSerial?


//see Nextion.h  ??  Where is such Nextion.h


In this case I am using a WEMOS D1 Mini (ESP8266) as the MCU.

Needed the SoftwareSerial because there is just one hardware serial available.


See Nextion.h - is where I made the mod for using SoftwareSerial.


One thing - is the 3.3v from WEMOS OK for the serial input on the Nextion?


Perhaps upload mods - no one can mind read to know what changes are made.


And now this is where you need to dig in


1) If such 3.3v from WEMOS isn't okay, what could your losses be?

    a) are you prepared to gambling such losses?

    b) would you rather look it up, make calculations, measurements to ensure?


But such MCU side specifications are well beyond the scope of Nextion

You'll need to compare your Nextion model's datasheet with your MCU datasheets




The 3.3v should be OK as other 3.3 will work.

Here is the Nextion spec

Input Voltage(RXD) Output 1, Iout=1mA 2.0 3.3 5.0 V


The Software Serial mod is here:

 

#include <SoftwareSerial.h>
extern SoftwareSerial HMISerial;


/**
 * @file NexConfig.h
 *
 * Options for user can be found here. 
 *
 * @author  Wu Pengfei (email:<pengfei.wu@itead.cc>)
 * @date    2015/8/13
 * @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.
 */
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__

/**
 * @addtogroup Configuration 
 * @{ 
 */

/** 
 * Define DEBUG_SERIAL_ENABLE to enable debug serial. 
 * Comment it to disable debug serial. 
 */
#define DEBUG_SERIAL_ENABLE

/**
 * Define dbSerial for the output of debug messages. 
 */
#define dbSerial Serial

/**
 * Define nexSerial for communicate with Nextion touch panel. 
 */
#define nexSerial HMISerial


#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a)    dbSerial.print(a)
#define dbSerialPrintln(a)  dbSerial.println(a)
#define dbSerialBegin(a)    dbSerial.begin(a)
#else
#define dbSerialPrint(a)    do{}while(0)
#define dbSerialPrintln(a)  do{}while(0)
#define dbSerialBegin(a)    do{}while(0)
#endif

/**
 * @}
 */

#endif /* #ifndef __NEXCONFIG_H__ */

 

Any other reasons I am getting the error?



UPDATE******************************************


Found a bad jumper wire...Thank GOD, was driving me crazy....


Working now... Can sleep better tonight!


nexInit() as defined in NexHardware.cpp shows?


 

bool nexInit(void)
{
    bool ret1 = false;
    bool ret2 = false;
    
    dbSerialBegin(9600);
    nexSerial.begin(115200);
    sendCommand("");
    sendCommand("bkcmd=1");
    ret1 = recvRetCommandFinished();
    sendCommand("page 0");
    ret2 = recvRetCommandFinished();
    return ret1 && ret2;
}

 


recvRetCommandFinished() in NexHardware.cpp shows:

 

bool recvRetCommandFinished(uint32_t timeout)
{    
    bool ret = false;
    uint8_t temp[4] = {0};
    
    nexSerial.setTimeout(timeout);
    if (sizeof(temp) != nexSerial.readBytes((char *)temp, sizeof(temp)))
    {
        ret = false;
    }

    if (temp[0] == NEX_RET_CMD_FINISHED
        && temp[1] == 0xFF
        && temp[2] == 0xFF
        && temp[3] == 0xFF
        )
    {
        ret = true;
    }

    if (ret) 
    {
        dbSerialPrintln("recvRetCommandFinished ok");
    }
    else
    {
        dbSerialPrintln("recvRetCommandFinished err");
    }
    
    return ret;
}

 

So it is expecting for four bytes to return in the order of 0x00 0xFF 0xFF 0xFF
So if it doesn't get this back from the Nextion
    1st) after bkcmd=1 is sent out
   2nd) after page 0 is sent out
   and each time a recvRetCommandFinished is issued.

Can be an indicator that your connection is not working
Can be that your serial was not yet properly established when these commands went out.
I have seen this type of code used to wait until serial is setup before continuing.
    Serial.begin(9600);
    while (!Serial) { };
  
  So ... a bad wire .. huh

The wire going FROM WEMOS TX -> NEXTION RX was not connected correctly, bad or open wire.


The Nextion was transmitting to the WEMOS ok, but the WEMOS was NOT transmitting to the Nextion.


Login or Signup to post a comment