I have 3 devices that sends CSV data on Serial1 , Serial2 and Serial3 of my Arduino Mega.
also have 4 current sensors on my AnalogRead A0,A1,A2,A3
and Lastly, I have 2, AC Rectified to DC inputs on A4 and A6 (My A5 Pin is burnt). A4 and A6 is energized with a Selector Switch(When A4 is High , A6 is low and V/V )
When energized, I open the Serial monitor to check the data and everything seems to be fine.
Then I set A4 to high which makes A6 low.
Serial Data updates.
Now I set A4 and A6 both to low
Serial Data updates
Now I set A6 high which makes A4 low
Serial Data updates
Now I set both to low again
Arduino Times out, Data stops.
This always happens when I set both to low. Somehow, something is disconnecting or disrupting the arduino but I have no idea on what is. I am hoping someone in the community has encountered this kind of problem.
My first thought is that the A4 and A6 inputs are causing the error. A4 and A6 are both from the same AC source but they are from a different rectifying circuit. (220VAC step down to 4.5VAC then rectified to 4.7VDC)
For each serial port, the String content only gets reset to an empty String in loop() after ETX has been received on all serial ports. Is it possible that the external devices are sending at different rates, so one of the content strings is growing too large and running out of memory?
A possible fix would be to change each event handler so that the last part was like this (with the appropriate flag variable in each case)
// print anything else
if (!flag1)
{
content.concat(c1);
}
Can you show how the other devices are connected to the serial ports?
And do the serial devices continuously send data to the Mega, or only when you operate the selector switch?
The other devices are called "Power Analyzers" they are the ones mentioned in CSV they send a string of data every 1 second.
they operate continously independent of the selector switch
For each serial port, the String `content` only gets reset to an empty String in `loop()` after ETX has been received on [u]all[/u] serial ports. Is it possible that the external devices are sending at different rates, so one of the `content` strings is growing too large and running out of memory?
A possible fix would be to change each event handler so that the last part was like this (with the appropriate flag variable in each case)
// print anything else
if (!flag1)
{
content.concat(c1);
}
Every serial port gets a new data every 1 second from each power analyzer there is a possibility that they might be out of sync but so far i have no problems with it.
BUT
The additional condition statement you said will help to stop overflow incase it happens and I will add it thank you for that.
The additional condition statement you said will help to stop overflow incase it happens and I will add it thank you for that.
As Mark @holmes4 said, it won't help if one of the power analysers stops sending. The program will get stuck waiting for the last power analyser to send an ETX.
But make the code change and see if it changes how the program behaves.