If I comment the next two lines, the program appear to run correctly
if not
After that, the loop fails. it gets the date correctly but doesn't save the data on the SD, if the wifi is enabled, the Arduino resets.
If not, the next loop will fail and throws strange values (negative or ovf or eDj)
I'm afraid I see a huge re-write coming. Your library is using Serial.readBytes() which is a blocking function that will hold everything up until it is satisfied.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data.
You can easily have separate copies of my functions to read data from different serial ports.
Also note that it is essential to call those functions frequently so that they can remove the data from the serial input buffer before it can overflow. That almost certainly means that the way your main program calls the library will have to change also.
Fega:
Also, the Serial port Only receives data when I Send a signal, after that, the sensor will not perform any kind of communication.
If you can be certain that data is only sent to the Arduino when you request it and if your program can then wait until it all arrives then a blocking system would work.
I had assumed that data would be arriving asynchronously at three different serial ports.
And I have just realized that your .INO program does not seem to use your library at all - I was wasting my time looking at the wrong thing. Please be clearer in future.
This looks very strange
if (Serial1.available() > 0) {
Serial1.readBytes(measure,9);
if (measure[0]==0xff && measure[1]==0x78){
Serial1.readBytes(measure,9);
}
and seems to me to have many ways to fail. What happens if 9 bytes are not sent? And you are trying to get 18 bytes (in 2 groups of 9) but you don't seem to do anything to request the second group.
My feeling is that you have let your program grow far too big before sorting out the problems you are now facing. At the very least I suggest you create separate functions to work with each sensor as that will allow you to test them separately with a lot of confidence that any time you call a function "it just works".
Hello @Robin2
I'm very sorry for what happened
My sincere apologies, I didn't merge branch where I implemented the library.
This is basically the same code but clean and reusable, I'm really really grieved about it, is not my intention waste your time in a meaningless way.
About the program grow, I actually made a test for every single component and all of the functions were tested alone, I also save some of the code that I use in the same repository and all work as expected when is used isolated.
About the snippet of code, I really didn't remember why I did it in that way (yeah, I should comment it ), I guess that the sensor re-sends my initial petition before the answer, but I'm not sure about it. but as I mentioned, it works when I tested it before.
I will rewrite the function from zero again, and then post the results
After my previous experience I am not going to take any chances. Please post your program in this Forum - as an attachment if it is too big to include directly.