I've hit a road block with the Arduino Due serial freezing at random times between 1-20 minutes.
My current level of programing skills is pretty limited but I'm trying to learn. Some stuff is just above my head!
After scouring the forums for a few days I reluctantly decided to make this post. Most of the issues I've had with this project I've overcome with perseverance so far. Almost everything related with this project has been a learning experience for me. That being said I've hit a road block and need a fresh prospective.
Project Summary:
I've been tasked with creating an aquarium LED controller system for a friend. There are similar projects but I decided to make my own. Control system will control LED light's and a few relay's on a timed schedule. Also a few temperature sensors.
Hardware:
Arduino Due
Nextion NX8048T050 -serial-
DS3231 RTC clock -i2c-
PCA9685 PWM LED control -i2c-
DS18B20 temperature sense -one wire-
I'm using a level shifter for UART and I2C.
Long story short I started the project on the Nano and a smaller 3.5" Nextion display. The project got a little complex for the Nano's limited RAM so I decided to switch to the Due. My friend wanted a larger display so now I'm on a 5" Nextion. This code is a super slimmed down version of the total project. This is a simple version that simply sends the current time read from the RTC on I2C and sends it to the Nextion over serial. I've also included a page for setting the RTC clock on the Nextion so the Due is listening for Nextion page changes and the button to save the time.
The project is setup on my bench ATM. On power up I can see the time relayed by the RTC to the Nextion. After a random time on average about 5 mins the Due stops transmitting on the serial bus. I had a blinking LED on pin 6 and a counter on the Nextion to see if either stop functioning. It appears that BOTH devices continue to operate! The serial bus just stops working. No time sent and no response from the Nextion button presses. So I tried using a USB UART using the Nextion Editor debug to simulate the screen over serial. Still no luck! Nextion shows no errors from the display. Due stops sending data and BOTH Due and Nextion display continue working. This is super frustrating!!
Tried so far:
Tried but failed to impliment the soft_uart library. Didn't spend much time but I'm not sure how to make it work with Nextion.
Different Due boards. Currently using an original.
Different UART ports of the Arduino. Currently using Serial2 (pins 16,17). Using external pullup resisters.
Different I2C ports. Currently using (SDA1, SCL1) with external pullup resisters.
DIfferent bauds.
Different breadboards.
Only RTC.
Different power supply.
Added filtering and pullup resisters on the RX TX pins to try and midigate noise.
Added filter cap to Nextion power header to midigate noise.
Not totally sure if there is enough noise to cause these random problems. Maybe someone can commit on this.
Here are some scope captures. Anyone see this noise being a problem?
Noise:
Close up of the serial waveform:
This is a super slimmed version of the code. Code has basic layout for some Nextion pages and buttons. Basiclly it knows what page the Nextion is on and I can set the RTC from page 4. I'm using a modified DS3231 library because of a conflict using RTC commands in the Due. I created a function for the Nextion serial end command and added a Serial.fluch() and a delay. This seems to give the Due a little longer before stopping but I'm not totally sure it's needed.
void END()
{
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.flush();
delay(20);
}
Here's the code:
#include <Wire.h>
#include <DS3231.h>
#include <Nextion.h>
//#include <DueFlashStorage.h>
//DueFlashStorage dueFlashStorage;
DS3231 rtc(SDA1, SCL1); //Clock
Time t;
int CurrentPage = 0;
int LEDch = 0;
NexPage p0 = NexPage(0, 0, "page0"); //MAIN
NexPage p1 = NexPage(1, 0, "page1"); //LED CONFIG
NexPage p2 = NexPage(2, 0, "page2"); //RLY CONFIG
NexPage p3 = NexPage(3, 0, "page3");
NexPage p4 = NexPage(4, 0, "page4");
NexPage p5 = NexPage(5, 0, "page4");
NexNumber TH = NexNumber(4, 3, "TH"); //Hours
NexNumber TM = NexNumber(4, 4, "TM"); //Minutes
NexNumber TS = NexNumber(4, 5, "TS"); //Seconds
NexButton TIMESAVE = NexButton(4, 7, "TIMESAVE");
NexTouch *nex_listen_list[] =
{
&p0,
&p1,
&p2,
&p3,
&p4,
&p5,
&TIMESAVE,
NULL
};
void setup()
{
Serial2.begin(9600);
delay(1000);
Serial2.print("baud=115200");
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.end();
Serial2.begin(115200);
Wire1.begin();
Wire1.setClock(100000);
rtc.begin();
TIMESAVE.attachPush(TIMESAVEPushCallback);
p0.attachPush(p0PushCallback);
p1.attachPush(p1PushCallback);
p2.attachPush(p2PushCallback);
p3.attachPush(p3PushCallback);
p4.attachPush(p4PushCallback);
p5.attachPush(p5PushCallback);
pinMode(6, OUTPUT); //LED Debug
}
void loop()
{
t = rtc.getTime();
delay(30);
if(CurrentPage == 0)
{
char buffer [12];
sprintf (buffer, "%02u:%02u:%02u\n", t.hour, t.min, t.sec);
Serial2.print("TIME.txt=");
Serial2.print("\"");
Serial2.print(buffer);
Serial2.print("\"");
END();
}
else if(CurrentPage == 1)
{
}
else if(CurrentPage == 2)
{
}
else if(CurrentPage == 3)
{
}
else if(CurrentPage == 4)
{
char buffer [12];
sprintf (buffer, "%02u:%02u:%02u\n", t.hour, t.min, t.sec);
Serial2.print("TIME.txt=");
Serial2.print("\"");
Serial2.print(buffer);
Serial2.print("\"");
END();
}
else if(CurrentPage == 5)
{
}
nexLoop(nex_listen_list);
}
void TIMESAVEPushCallback(void *ptr) //Set time button in Time config page
{
uint32_t TimeHour = 0;
TH.getValue(&TimeHour);
uint32_t TimeMin = 0;
TM.getValue(&TimeMin);
uint32_t TimeSec = 0;
TS.getValue(&TimeSec);
rtc.setTime(TimeHour, TimeMin, TimeSec);
t = rtc.getTime();
digitalWrite(6, LOW);
delay(300);
digitalWrite(6, HIGH);
}
void p0PushCallback(void *ptr)
{
CurrentPage = 0;
LEDch = 0;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void p1PushCallback(void *ptr)
{
CurrentPage = 1;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void p2PushCallback(void *ptr)
{
CurrentPage = 2;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void p3PushCallback(void *ptr)
{
CurrentPage = 3;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void p4PushCallback(void *ptr)
{
CurrentPage = 4;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void p5PushCallback(void *ptr)
{
CurrentPage = 5;
digitalWrite(6, LOW);//Debug feedback
delay(300);
digitalWrite(6, HIGH);
}
void END()
{
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.flush();
delay(50);
}
What I would really like is some advice on how to diagnose this problem and what test code I may try to get some feed back on why this is happening. Could the Nextion be bad? I've seen many posts about similar issues so I still think this could be a software issue.
Thanks guys!