Hi
I run a similar code to auto dim the display which works fine,Ill upload it tonight as I dont have access to it at the moment. One thing to check is that you are not trying to write instructions to quickly to the display, I had a loop running sending value changes to a number and didnt give the display time to process which would give me intermittant errors. I changed the timing of my loop and also increased the baud rate which all helped.
Cheers
Mark
There should be a couple of considerations made
- why you want to dim
- where this will be handled
This forms the guidelines to how to achieve. before I dive in,
start by cleaning out other commands such as dim=80 everywhere.
One of these is going to interfere with the others.
The system variable dim and dims
The dim system variable changes the backlight to a percentage
dim=0 will reduce the screen backlighting to 0%,
dim=100 will increase the screen backlighting to 100%
and dim=43 will set the screen backlighting to 43%
The dims system variable does everything that dim does
and also stores this value to be the default power on setting
dims=80 will set screen backlighting to 80% and store it for
when the system either powers back on or wakes from sleep.
The system variables sleep, ussp, thsp, thup and wup
The sleep system variable also changes the backlight
sleep=1 changes the screen backlighting to 0% before entering
into a lower power state and reduced command set
Serial communications is available, needed to receive sleep=0
but updating other variables during sleep can expect troubles.
thup controls if the power to touch sensor is on during sleep
if thup=1 then touch sensor is on during sleep, touch will wake
if thup=0 then touch sensor is off during sleep, touch will not wake
When touch wakes the Nextion the backlighting is restored
wup stands for wake up page, by default it refreshes the current page.
But wup can be set to any page, and in this "any" page
you could get creative with whatever commands you'd like and then
jump back to your page that was current before sleeping.
In fact a wup page can be transparent - .sta set to no background
wup=5 will cause page 5 to be loaded when Nextion first wakes.
But what causes the Nextion to sleep in the first place
Serial command, or event code with sleep=1
thsp controls an auto sleep timer, and sleeps when timer runs out
when there has been no touch.
thsp=15 means go to sleep after 15 second timer runs out.
ussp controls an auto sleep timer, and sleeps when timer runs out
when there has been no serial data
ussp=15 means go to sleep after 15 second timer runs out.
Both thsp and ussp can not be set back to zero once they are set
they will only be set back to zero when Nextion is restarted or rest
When some updates happen and some do not
especially when using the sleep command thsp or ussp - auto sleep
Sleep has do be disabled before updating variables with sleep=0
Nextion sends to the MCU
0x86 0xFF 0xFF 0xFF just as the Nextion goes into auto sleep, and
0x87 0xFF 0xFF 0xFF just as the Nextion codes out of auto sleep
(say with a touch of the touch sensor if thup=1, but not sleep=0)
Your MCU listening to these know if Nextion is asleep or not
But if doing MCU side, there is no need for commands in Nextion side.
Your MCU is in control of turning on and off as your stated by your code.
Setup
loksik
- what is setup?
As the dim setting is on Nextion side, the dimming can be done without MCU.
I used a timer component tm0 to trigger and set dim=0.
On page touch press event, I set
dim=90
tm0.en=0
tm0.en=1
The question has to be what is in control.
Nextion - a touch panel and status monitor
MCU - the microprocessor with programming logic.
In an HMI - Human Machine Interface
I am less certain that a monitor should be in control.
(in your computer system, is monitor the master?)
Such Timer component with such code
* the fastest the timer can respond is a bit more than 51.3ms
- with dim=90ÿÿÿ sent from MCU at 115200 baud (9/11520) is 0.781ms
* but tm0.en=0 followed by tm0.en=1 also no use but consume more time
- perhaps resetting tm0.tim= to a chosen constant may be better
* setting in page touch as opposed to release? can lead to stack issues, depending
- but this also means touch where canvas component are will not trigger - miss.
Real purpose of dim? other than visual gimmick?
- such touch display does not require to avoid image burn in
Use of timer is in constant loop, perhaps without need to do a task
- such constant timer wastes precious Nextion side MCU cycles
what ever power may have been saved by dim is more than consumed by calculations.
Most effective is control from MCU side coding - 8 to 10 bytes to implement, very speedy.
sialc
I am a newbie here. Trying to dim the brightness of nextion using arduino after no touch operation for a set time, and bring up the brightness to normal level when touched again. Any suggestion will be greatly appreciated.
I used the following counter to turn down the brightness after 15 s, where dimtimer is elapsedMillis timer.
void countfade(){
if(dimtimer > 15000)
{
Serial.print("dim=5");
Serial.write(0xff);
Serial.write(0xff);
Serial.write(0xff);
dimtimer=0;
}
}
and on the Nextion editor, for each component and page, I set dim= 80
on Touch Press event.
I have some progress bars in the GUI. The brightness does dim after 15 seconds but it sometimes change the values of my progress bars without any touch. Similarly on touch event, the progress bar values may change. I introduced some delay in the loop and change the trigger value of the dimtimer. Some times I get perfect response without error but some other times I get errors. Not sure what is causing the interference. Any suggestions will be appreciated.