Board Resetting While Changing Screens in Nextion

I have a very weird problem that has suddenly started that doesn't seem to be related to a programming issue. The board is resetting after changing several screens. Sometimes it also wipes out the values stored in the EEPROM. Sometimes it's only a couple of screens, others it's several.

However, the board will not reset if no screen pages are getting changed. It will remain on indefinitely in this case.

The project consists of;

  1. Arduino knockoff, not genuine,
  2. Six LEDs of different colors of which only one is ever on at one time. The pin is set to a low output (50) with analogWrite. They all have a common ground with a 100 Ohm pull down resistor. Draws 6.4ma
  3. Nextion NX4024T032-011 with 470Uf capacitor across the power pins and powered by the buck converter
  4. 12V 2A power supply Connected to board Vin and buck converter. They both share a common ground
  5. Buck converter set to 5.2V output
  6. 2 relays powered by buck converter and activated by board. Draws 1.4ma apiece from data pin.
  7. RTC powered by board 3.3V supply. Draws 1.5ma
  8. RF-24 powered by board 3.3V supply. Draws 23.2ma

The object of the project is a pool control system to turn the pump filter on and off at 4 different times.
The two relays will turn on a larger relay to activate the 20A 240V pool pump. They are powered by the buck converter.

The code is attached.

Any thoughts would be greatly appreciated. This project sure is consuming me.

NextionProblem.pdf (285 KB)

Hello Gadgetman9,
After over 50 posts I would hope you know how to post code, NOT in a pdf document!

I've read your question several times and I cannot tell when you refer to 'the board' whether you mean the Nextion display, the unspecified Arduino clone or something else.

  1. Six LEDs of different colors of which only one is ever on at one time. The pin is set to a low output (50) with analogWrite. They all have a common ground with a 100 Ohm pull down resistor. Draws 6.4ma

I don't understand this. You seem to be saying you have 6 LEDs connected to 1 pin and somehow manage to light 1 at a time. If the LED(s) have a common ground then setting the pin low would turn them off, not on. Please post a schematic, hand drawn and photographed is fine.

  1. 12V 2A power supply Connected to board Vin and buck converter. They both share a common ground

I suggest you power the Arduino from the 5V output of the converter, not from 12V. Connect to the 5V pin on the Arduino.

  1. 2 relays powered by buck converter and activated by board. Draws 1.4ma apiece from data pin.

No relay draws only 1.4mA!

My thought is to write a small sketch that illustrates the problem. You may well find that in doing so you find the cause. I have 5 Nextion displays, I've never had a problem with any of them, but I occasionally read that others have. It helps to have at least 2, then if you get a problem you can swap them.

Please post:
A schematic
A short program that illustrates the problem
Photos of your set up
Please follow the forum rules for posting: code in code tags, images displayed, proper schematic.

Thanks.

Hi Perry. I will draw up a schematic at a later date. It will take some time. However, I would like to address a couple comments first. There is a question at the bottom.

After over 50 posts I would hope you know how to post code, NOT in a pdf document!

This site would not let me post the code in a window as there were to many characters. We're allowed a max of 9000 characters. There are over 700 lines of code. I've run into this problem before and had to make them an attachment.

I've read your question several times and I cannot tell when you refer to 'the board' whether you mean the Nextion display, the unspecified Arduino clone or something else.

When I refer to the board, I mean the Arduino knockoff.

I don't understand this. You seem to be saying you have 6 LEDs connected to 1 pin and somehow manage to light 1 at a time. If the LED(s) have a common ground then setting the pin low would turn them off, not on.

I apologize, I wasn't as clear as I could be. Each LED has it's own pin. They share a common ground with a 100 ohm pulldown resistor in series.

No relay draws only 1.4mA!

This is off the pin that activates the control circuit. I measured it with an ampmeter with a resolution of .0001A. There is a separate 5V input powered by the buck converter

I suggest you power the Arduino from the 5V output of the converter, not from 12V. Connect to the 5V pin on the Arduino.

Are you talking about the 5V output pin on the Arduino?

This site would not let me post the code in a window as there were to many characters. We're allowed a max of 9000 characters. There are over 700 lines of code. I've run into this problem before and had to make them an attachment.

I realise that, there are 2 problems with what you did though, the first is if you must attach the code then attach the code, as in attach the ino file, not some other kind of file with the code pasted into it. Please go back and remove the pdf document and post the ino file. Second is if your code is that long you make it very hard for those of us trying to figure out the problem. You are asking us to wade through an awful lot of code to spot the one mistake that's causing the problem. This is hard enough for me to do with my own code with which I am obviously familiar, with someone else's it's very difficult.

If you post a small program that exhibits the problem then 2 things happen: It's easier for us to read and maybe spot the problem and, much more importantly, you'll very likely find the problem while creating the small program.

When I refer to the board, I mean the Arduino knockoff.

That in itself might be the problem! Being a knockoff I mean! A common cause of random resets is writing to memory you don't own, for example:

int test[5];
test[5] = 10;

I've not read your code for the reason stated, but that's the first kind of thing I'd be looking for.

I apologize, I wasn't as clear as I could be. Each LED has it's own pin. They share a common ground with a 100 ohm pulldown resistor in series.

I did wonder if you meant that, but I decided not to guess or assume.

This is off the pin that activates the control circuit. I measured it with an ampmeter with a resolution of .0001A. There is a separate 5V input powered by the buck converter

OK

Are you talking about the 5V output pin on the Arduino?

Yes, you can apply 5V there from a power supply to power it. Please can you set your converter to 5V not 5V2.

[EDIT]
Sorry, I forgot this:

I have a very weird problem that has suddenly started that doesn't seem to be related to a programming issue.

Generally when something like that happens you need to go back to whatever state your project was in before the problem appeared and see if the problem goes away. If the problem goes then the cause is whatever you changed after that.

Over to you to experiment, I hope I have given you some things to consider.

Thank you Perry, you have given me food for thought. I also suspected it might be the Arduino knockoff. What I'm struggling with is whatever could make a board reset on its own(outside of an amperage overload, which I no longer have) and also wipe out the EEPROM.

I will power the Arduino with the buck converter as you suggested.

It's difficult to figure out exactly where in the code it's happening. I think it's occurring on a particular screen that set's the pump schedule, but sometimes it happens just sitting there with no human activity.

This is the code I suspected. I commented out a serial print function and it seemed to lessen the problem but, it didn't go away completely.

void btnPumpSchApplyPopCallback(void* ptr) {
	// Apply button on Pump Schedule page
	//All pump periods are stored in EEPROM in case of power failure
	//Check boxes to activate or deactivate each pump period.  
	//chk 1, 2, 3, and 4 correspond to each pump period
	chk1.getValue(&byte1);
	if (byte1 == 1) {
		EEPROM.update(29, 1);
		chk1.setValue(1);
	}
	else if (byte1 == 0) {
		EEPROM.update(29, 0);
		chk1.setValue(0);
	}
	chk2.getValue(&byte1);
	if (byte1 == 1) {
		EEPROM.update(30, 1);
		chk2.setValue(1);
	}
	else if (byte1 == 0) {
		EEPROM.update(30, 0);
		chk2.setValue(0);
	}
	chk3.getValue(&byte1);
	if (byte1 == 1) {
		EEPROM.update(31, 1);
		chk3.setValue(1);
	}
	else if (byte1 == 0) {
		EEPROM.update(31, 0);
		chk3.setValue(0);
	}
	chk4.getValue(&byte1);
	if (byte1 == 1) {
		EEPROM.update(32, 1);
		chk4.setValue(1);
	}
	else if (byte1 == 0) {
		EEPROM.update(32, 0);
		chk4.setValue(0);
	}
	//Pump period 1
	hrs1on.getValue(&byte1);
	EEPROM.update(0, byte1);
	mins1on.getValue(&byte1);
	EEPROM.update(1, byte1);
	hrs1off.getValue(&byte1);
	EEPROM.update(2, byte1);
	mins1off.getValue(&byte1);
	EEPROM.update(3, byte1);

	//Pump period 2
	hrs2on.getValue(&byte1);
	EEPROM.update(4, byte1);
	mins2on.getValue(&byte1);
	EEPROM.update(5, byte1);
	hrs2off.getValue(&byte1);
	EEPROM.update(6, byte1);
	mins2off.getValue(&byte1);
	EEPROM.update(7, byte1);

	//Pump period 3
	hrs3on.getValue(&byte1);
	EEPROM.update(8, byte1);
	mins3on.getValue(&byte1);
	EEPROM.update(9, byte1);
	hrs3off.getValue(&byte1);
	EEPROM.update(10, byte1);
	mins3off.getValue(&byte1);
	EEPROM.update(11, byte1);

	//Pump period 4
	hrs4on.getValue(&byte1);
	EEPROM.update(12, byte1);
	mins4on.getValue(&byte1);
	EEPROM.update(13, byte1);
	hrs4off.getValue(&byte1);
	EEPROM.update(14, byte1);
	mins4off.getValue(&byte1);
	EEPROM.update(15, byte1);
	//Eprint(); //Serial data print to verify data went in correctly.  When I commented this out, it seemed to cure problem but it came back.

void Eprint() {
	uint32_t byte2;
	Serial.println();
	Serial.println(F("**************************** Eprint begin ******************************"));
	Serial.print(F("Pump Period1 On Hr "));
	Serial.println(EEPROM.read(0));
	Serial.print(F("Pump Period1 On Min "));
	Serial.println(EEPROM.read(1));
	Serial.print(F("Pump Period1 Off Hr "));
	Serial.println(EEPROM.read(2));
	Serial.print(F("Pump Period1 Off Min "));
	Serial.print(EEPROM.read(3));
	Serial.print(F("  Enabled: "));
		if (EEPROM.read(29) == 1) {
			Serial.print(F("Yes"));
		}
		else
		{
			Serial.print(F("No"));
		}
	/*Serial.println();
	Serial.println();*/
	Serial.println();
	Serial.println();
	Serial.print(F("Pump Period2 On Hr "));
	Serial.println(EEPROM.read(4));
	Serial.print(F("Pump Period2 On Min "));
	Serial.println(EEPROM.read(5));
	Serial.print(F("Pump Period2 Off Hr "));
	Serial.println(EEPROM.read(6));
	Serial.print(F("Pump Period2 Off Min "));
	Serial.print(EEPROM.read(7));
	Serial.print(F("  Enabled: "));
	if (EEPROM.read(30) == 1) {
		Serial.print(F("Yes"));
	}
	else
	{
		Serial.print(F("No"));
	}

	Serial.println();
	Serial.println();
	Serial.print(F("Pump Period3 On Hr "));
	Serial.println(EEPROM.read(8));
	Serial.print(F("Pump Period3 On Min "));
	Serial.println(EEPROM.read(9));
	Serial.print(F("Pump Period3 Off Hr "));
	Serial.println(EEPROM.read(10));
	Serial.print(F("Pump Period3 Off Min "));
	Serial.print(EEPROM.read(11));
	Serial.print(F("  Enabled: "));
	if (EEPROM.read(31) == 1) {
		Serial.print(F("Yes"));
	}
	else
	{
		Serial.print(F("No"));
	}

	Serial.println();
	Serial.println();
	Serial.print(F("Pump Period4 On Hr "));
	Serial.println(EEPROM.read(12));
	Serial.print(F("Pump Period4 On Min "));
	Serial.println(EEPROM.read(13));
	Serial.print(F("Pump Period4 Off Hr "));
	Serial.println(EEPROM.read(14));
	Serial.print(F("Pump Period4 Off Min "));
	Serial.print(EEPROM.read(15));
	Serial.print(F("  Enabled: "));
	if (EEPROM.read(32) == 1) {
		Serial.print(F("Yes"));
	}
	else
	{
		Serial.println(F("No"));
	}
	Serial.println();
	Serial.print(F("Eprom Sleep time value ="));
	Serial.println(EEPROM.read(41));
	Serial.print(F("Start page Sleep time value ="));
	SleepTime.getValue(&byte2);
	Serial.println(byte2);

	Serial.print(F("EEPROM TempOn value ="));
	Serial.println(EEPROM.read(42));
	TempOn.getValue(&byte2);
	Serial.print(F("Start page TempOn value ="));
	Serial.println(byte2);
	
	
}
}

Thank you for being patient and respectful. On other areas of the forum I've been berated and spoken to as if I'm a moron. I don't have a background in electronics and this is only a hobby of which most of what I've learned is self taught. However, if they want to develop and test astronaut's backpacks, I can help them with 25 years of experience. There are some members on here from whom I dread their answers.

You are not like that at all. In fact quite the opposite. All of your answers have been informative and helpful. I greatly appreciate that about you.

It's difficult to figure out exactly where in the code it's happening.

Tell me about it! You might have seen my Nextion tutorial, the code in there used to crash at a very specific point if using a Uno or a Mega, but ran perfectly well on MKR1010. It took me months to find, most of that time I just forgot about it and occasionally had an idea that turned out to be wrong. Eventually I discovered the Uno and the Maga could not cope properly with an array I used over a certain size, so I guess a memory problem.

Your code is too much for me to read, I am not very good with other people's code! There's a lot in there that I am not familiar with and would not know if it was a problem or not.

Start small with something that works.

Spilt code into functions with definite purposes. When you add a new function and the problem appears you know where to look.

Thank you for being patient and respectful.

I appreciate that. Sometimes my comments are not as respectful as I want them to be. I am not a trained teacher, I do not know how to handle some people. I don't mind that people don't understand stuff, we all had to start somewhere. I do mind when people are obviously being an idiot (you are not being an idiot).

However, if they want to develop and test astronaut's backpacks, I can help them with 25 years of experience.

You can't dangle that in front of me and walk away!!!!! You serious? If you work in the space industry you are my hero!! I was glued to NASA TV on Wednesday and very disappointed that SpaceX's Falcon 9 could not launch due to weather. I hope it launches safely tonight (my time). I'd love to go into space. I did do a zero G flight a few years ago with my brother.

You can't dangle that in front of me and walk away!!!!! You serious? If you work in the space industry you are my hero!! I was glued to NASA TV on Wednesday and very disappointed that SpaceX's Falcon 9 could not launch due to weather. I hope it launches safely tonight (my time). I'd love to go into space. I did do a zero G flight a few years ago with my brother.

Yes, its true. I worked a total of 40 years for a company that started out as Hamilton Standard, became Hamilton Sunstrand and was UTC Aerospace systems when I retired in 2014. I worked in the factory for the first 15 years and was fortunate to attain a job in their division that was then called Space & Life in 1989. They were just finishing up making the replacement parts for the shuttle Endeavour which was a replacement for Challenger and beginning to do experiments for the yet to be International Space Station. The huge vacuum chamber that the Apollo moon suits were tested in was still there and some of the people who helped put men on the moon. They sure had some great stories!
Those were great times. We did a lot of what ifs from single piece hardware to full scale systems. I worked on all the environmental control systems and water processors on the space shuttle and ISS, waste management systems (toilet and urine processors), satellelite propulsion systems, ovens that regenerate the metal oxide canisters which remove CO2 from the space suits and a host of other projects I can't even remember. We even had a system that allows submarines to remain underwater for months at a time. Then of course, there was the space suit. A seemingly complicated piece of hardware but is really 4 simplistic systems. I have to say though, it is truly and engineering marvel. One of my last projects was the cooling panels on the Parker Solar Probe currently on it's way to the sun. I am fortunate to have a career working with such amazing hardware.
I too was disappointed in the scrubbing of Wednesdays launch. However, I just watched todays successful launch. They are on their way to the ISS. It will take them 19 hours to dock. Everything is done pretty slowly in space where movement is concerned. While gravity is reduced, mass remains the same.
Glad to meet a fellow space affectionado. Hope you were able to see the launch. I believe you are four hours ahead of me. I'm on EDT.

I saw the launch, loved it! I am in the UK, British summer time, one hour ahead of UTC. I guess you are in the East of the USA or Canada.

That sounds like a fascinating career!

I am just old enough to remember the moon landings and I hope to see them again before I expire. I hope Yusaku Maezawa gets his trip around the moon, that will be the first time we've been near it since 1972. I'm really looking forward to that and really, REALLY looking forward to someone going to Mars.

And I've just seen the capsule pass over the UK :slight_smile:

I saw the launch, loved it! I am in the UK, British summer time, one hour ahead of UTC. I guess you are in the East of the USA or Canada.

Connecticut

And I've just seen the capsule pass over the UK

Super cool!

I forgot to ask, will the Arduino still supply 3.3V when 5V is attached to the buck converter? I am getting 1.77V from the 3.3V pin in that configuration.

Gadgetman9:
I forgot to ask, will the Arduino still supply 3.3V when 5V is attached to the buck converter? I am getting 1.77V from the 3.3V pin in that configuration.

I don't think you have told me which model of Arduino you have.
If it has a 3V3 pin then there should be 3V3 on the pin. If it has a 3V3 pin then it must be an Arduino with a 3V3 processor.

That you are not getting 3V3 suggests a few possibilities:
The on board regulator is faulty.
The on board regulator is a cheap clone and never was any good.
You are drawing too much current from somewhere (LEDs???)

What do you get on the 3V3 pin with only 5V connected to the 5V pin, 0V to the ground pin and nothing else connected to anything?

I had a quick look thorough your code (which would be a lot easier if it were not in a pdf document :o !).
Unfortunately I cannot help much because you do things very differently to how I would, and you use the Nextion libraries, which I would not touch with a barge pole (British expression).

I have no idea if your use of the Nextion library is correct or not. Note that the original Nextion library is full of bugs, there is a link from my tutorial to a better version by Ray Livingston, I suggest you try it. There is also Easy Nextion Library. Alternatively study my tutorial and use my methods, which don't use a library but do come with me to help. However, you will have to re-write your code and your Nextion configuration to use my methods.

Why are you using analogueWrite() to turn relays on and off? Relays need a simple on or off, high or low. Either that or your relays are not really relays.

Don't use delay(). Ever. Delay is the devil's work, nothing else happens while delay is, err, delaying (regular readers of these pages probably think I am obsessed with this point: they are correct (waves)). Have a read of
Demonstration for several things at the same time
Using millis for timing

I noticed at least 1 instance of String (capital S). Don't use String either, it causes problems with memory use leading to all sorts of odd behaviour, including processor restarts. Use C strings AKA character arrays, for example

char someArray[32] = ("This is an array of chars");

There are lots and lots of discussions on these fora about Strings, find them and read them to learn more about the problems they cause and how to use character arrays instead.

I cannot comment on your use of EEPROM as I have never used it on and Arduino.

I hope some of that helps.

I don't think you have told me which model of Arduino you have.

Its an Arduino Mega knockoff. Here is a link to it:https://www.amazon.com/gp/product/B01H4ZLZLQ/ref=ppx_yo_dt_b_asin_title_o08_s00?ie=UTF8&psc=1

I believe I've found the problem. It is a faulty board. I switched with another knockoff from a different vendor and the problem seems to have gone away. Yaaaaaaay! :). I sure hope it doesn't come back.

I had a quick look thorough your code (which would be a lot easier if it were not in a pdf document !).
Unfortunately I cannot help much because you do things very differently to how I would, and you use the Nextion libraries, which I would not touch with a barge pole (British expression).

I have attached the ino file if you're still interested. I understood the barge pole expression. Here it's 10 foot pole. I bet a barge pole is longer. :slight_smile:

I have no idea if your use of the Nextion library is correct or not. Note that the original Nextion library is full of bugs, there is a link from my tutorial to a better version by Ray Livingston, I suggest you try it. There is also Easy Nextion Library. Alternatively study my tutorial and use my methods, which don't use a library but do come with me to help. However, you will have to re-write your code and your Nextion configuration to use my methods.

I'm using an upgraded version of the Nextion library which came out last year. It appears to behave a lot better. I'll take a look at the other libraries you suggested. I'll also take a look at your methods which I'm very interested in.

However, at this point I have so much time and energy invested I'm going to stay the current course. I need to get this up and running and rewriting is not an option at the moment. I have a duplicate setup at my computer that I used for development. All of the options are not in the software yet and will take more time to write, test and initiate. Once complete, I can upload the option/improvements to the actual project which will reside in the garage. It is a system to control my pool and I want to get it out there because I'll be closing the pool again in 3 months.

Why are you using analogueWrite() to turn relays on and off?

This will be changed. Originally I was trying to use minimum current flow in order to reduce the load on the board. You helped me with that by telling me about the buck converter.

Don't use delay(). Ever

Removed

Have a read of
Demonstration for several things at the same time
Using millis for timing

Have looked at these and intend to incorporate them where needed.

I noticed at least 1 instance of String (capital S). Don't use String either, it causes problems with memory use leading to all sorts of odd behaviour, including processor restarts.

There is only one instance of String. I used it to receive a title in printTime(). This function tagged on to the end of different debugging Serial.print statements to tell me which function they were coming from. String will not be used during normal program run time.

I didn't know that String could cause any trouble. Thank you.

I have attached four photos of the project. Yes, I know it looks a bit messy, but its functional. The enclosure is too small. Like trying to stuff 5 Lb into a 1 Lb bag. It will probably be rebuilt at a later date. This is basically a prototype. There were a number of afterthoughts added on, so next time, bigger box.

Thank you again for your time and patience. I'm sure we'll be talking again in the near future, especially when I look into your methods of interacting with the Nextion.

By the way, did I mention I have a private pilots license? Almost as good as going into space :o .

PoolFilterSystem.ino (20.8 KB)

I have attached four photos of the project.

Thank you, always interesting to see what people are working on.
How to post an image




Its an Arduino Mega knockoff. Here is a link to it:https://www.amazon.com/gp/product/B01H4ZLZLQ/ref=ppx_yo_dt_b_asin_title_o08_s00?ie=UTF8&psc=1

I have the same one.

Here it's 10 foot pole. I bet a barge pole is longer.

I don't know. My sister owned a narrow boat until recently, I'll ask her.

Thank you again for your time and patience

You're welcome!

By the way, did I mention I have a private pilots license?

Now you are showing off! I wanted to get a PPL, then I had a go in a light aircraft, actually I've done so several times. I found it enjoyable but it didn't leave me wanting to get a licence.

Almost as good as going into space.

Noooo! The zero G flight was a lot more fun than flying a light aircraft, even if it did leave me feeling ill afterwards. Space, I'd love to go into space (I noticed there were 2 spare seats in the Dragon capsule, do you think if I'd turned up and asked they'd have let me in?). I suppose you are going to tell me you are an astronaut now!

Thanks for the update, much appreciated.

Another suggestion, for the front panel find someone who can print vinyl, any local sign making company or company that puts graphics on vehicles should be able to do it, and get them to make you a vinyl label to cover the panel, with all the printing on you need, rather than using labels. They should be able to make it with cut outs for the display and switches etc.

Gadgetman9:
There is only one instance of String.

That bothered me when I read it but at the time I could not think why. Now I know; there might be only 1 instance of String but it gets called many, many times. If it were only called once it wouldn't be a problem, but each time it is called it is (might be) using up more memory until there is none left.

Now I know; there might be only 1 instance of String but it gets called many, many times.

But it doesn't get called at all during normal operation. It's only used for debugging to send a string to a function called printTime.
My failure is back again. Only this time without the board resetting. Strange anomaly. The EEPROM is getting set to 0 except for the two that store the sleep time for the display and a temperature setting for turning the pump on.
I'm hot on the trail though. I think I'm zeroing in on it.