Changing bco from a program

I have a multi-page display file.
Page 7 has some text boxes, one of which is called tdateDay1
In the Editor,in 'debug’mode, with page 7 displayed, I can type
tdateDay1.bco=63488
and the background colour of the text box changes to red.
I can also type
tdateDay1.bco=65535
and the background colour of the text box changes to white.
In my program code, I cannot find a format for the command which will do the same thing.
If I try tdateDay1.bco=65535
or tdateDay1.bco(65535)
or tdateDay1.setText(bco=65535)
or any of a dozen different methods
I get errors in the IDE.

Any ideas?

Which platform (Arduino?) and which library version do you use? Everything depends. If the library which you use does not explicitly support modifying the bco property, the “official” Itead library has the generic sendCommand() function, which allows to transmit the command string as if you would issue it in the editor.

Where and how are you putting/executing this code?

Traxxtar,

I have the code inside a PopCallback

I can get the change I need if I use:

Serial1.print(“tdateDay1.bco=33792”);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.print(“tdateDay2.bco=63488”);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

That changes the background colour of two text boxes: tdateDay1 and tdateDay2.
But I can’t find the correct syntax for use with the ITEAD library.

Ricky

Fjodor,

I am using a Teensy 3.5, in the extended Arduino IDE. I have included the ITEAD Nextion library.
I can change pco for a text box, but not bco.
Simple hardware serial commands will work, like:

Serial1.print(“tdateDay1.bco=33792”);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.print(“tdateDay2.bco=63488”);
Serial1.write(0xff);
Serial1.write(0xff);
Serial1.write(0xff);

The sendCommand() looks like the way, so thanks for that; but I can’t find the correct syntax.

At the start of the program I have
#include< Nextion.h>
#define NXTSERIAL Serial1

later, I have
NXTSERIAL.sendCommand(“tdateDay1.bco=63488”);

and the compiler error message says:
‘class HardwareSerial’ has no member named ‘sendCommand’

Do I have the wrong syntax??

Obviously, you have the wrong syntax. Because when you define NXTSERIAL, how shall the itead library know that you are meaning its communication port? Take off that define from your code and edit line 37 in NexConfig.h
From:
37… #define nexSerial Serial2
To:
37… #define nexSerial Serial1
following the documentation in the library’s readme.md file.

Then, it would work on the Teensy’s Serial1, using the appropriate syntax nexSerial.sendCommand(“whatever”);

OK.
I have been using a version of NexConfig.h modified as you suggest, for nearly a year. That file was modified when I started using the Teensy. I have checked, and it is modified. I have also checked the IDE is including the correct file from the C: drive.
I have now removed the define NXTSERIAL.
I have checked the syntax I am using for nexSerial.sendCommand(“tdateDay1.bco=63488”) and it seems OK.
I still get the same errors, and I am puzzled by the reference to ‘class HardwareSerial’.

There is nothing to be puzzled about. Your define re-defined your NXTSERIAL directly towards the hardware UART named Serial1. Thus, each method which you use for your NXTSERIAL object is handled by the compiler as if you had directly written Serial1.sendCommand(). But the Teensy core Serial1 object has no sendCommand method. Only the nexSerial object (which overloads the generic hardware class) adds and handles the additional methods which are declared in the library. That’s how C++ objects work in general.

The nexSerial.sendCommand(“tdateDay1.bco=63488”) looks correct. But when sending it from the Teensy, same rules as sending commands from the editor window apply: The page which contains the object must be loaded. If you get still errors, let us know which errors. It’s almost impossible to send an erroneous command string to a Nextion and not getting a qualified error code, indicating the problem. At least when the baud rates match.

OK. That makes sense. So does that mean the Teensy cannot use sendCommand(), whereas the Arduino can? If that is true, then I will (a) revert to the Serial.print and Serial.write commands which I know work; and (b) find out if Paul Stoffregen can add the sendCommand to his version of the Teensy core Serial1 object.
Thanks for your help with this. It is much appreciated.
And I must go back to my C++ textbooks…

You still did not understand it. No hardware Serial in the world provides a sendCommand() function, neither Arduino, nor Teensy, nor STM32, nor…
It’s the library which (independent of the MCU which you use) overloads whatever generic hardware UART drivers and adds the functionality which is required only by and specifically for the Nextion. That’s what libraries are for. Why should Massimo (Arduino) or Paul (Teensy) add functions to their Serial drivers which are not useful for the vast majority of their users?
Getting back over your C++ books might be a good idea.

Yes. The more I program, the more ambitious I become, and the more problems appear, but, on the other hand, the more I [have to] learn.

1 Like

Good discussion, but an alternative approach might be…assuming your serial communications are working properly.
If you can’t get a library to work properly, this approach might work.
Create another object on your HMI display. It could be a variable, etc. Send it a value from the Arduino, then in the HMI code, change the .bco value based on a condition check of the variable you changed.

1 Like

Yes; that’s a good idea.
I have seen some complex displays with multiple pages, and they do seem to do a lot of the work in the display itself. I think that’s the way Nextion anticipate their more Advanced or Intelligent displays might be used, dispensing with the external processor. That way, they can be stand-alone controllers.
In this case, I do have multiple screens, and I do use the limited system variables for some things. The screen that was giving me trouble is for a time/day/date entry which will then pass the resulting time to the Teensy’s inbuilt RTC. The checks required to ensure the entered date is a valid combination of day,month and year are a bit lengthy and are best done in the Teensy, I think.
I have used invisible buttons on some screens to trigger events.
But I will experiment with variables in a simpler program and screen set, as I think this is a potentially valuable technique.