ICSC library, made by majenko, is perfect for what I want.
I use a RS485 BUS and it worked very well... but only when my program was small and simple.
In short, this lib enable to communicate between nodes. All nodes can be identified with a number, and with commands which can callback other functions.
The communication can be started at anytime.
Now, I had to make libs for all routines on my program, to mantain all code tidy, but I'm having problems... very strange problems.
=> The problem:
I'm using a Datalogger (Seeeduino Stalker board) near Master node (Arduino Mega). The serial ports used are Serial1 on Master (Node 1) and Serial0 on Datalogger (Node 2). The other nodes aren't relevant for now.
== Datalogger libs and functions (only relevant):
logger
exportConfigFile (read from SD and send via serial)
checkFiles (verify if all needed files exists to start logging)
rs485com (deals with all communication data)
configSens (callback function to start exportConfigFile from logger lib)
startAq (callback function to start checkFiles from logger lib)
1- Master send a command to request config file from Datalogger: 'C' This command will callback configSens function;
2- Datalogger read the text file from SDcard. The memory is very limited, so I don't have space to store it on a variable (the file will be much bigger)... I read a byte from SDcard and send it to Master until a char '@' appear. (exportConfigFile function, called inside configSens function - class logger);
3- Datalogger send a confirmation command to Master: 'S'. This command will callback check function on Master; (just for test, and works well but only from Datalogger to Master);
4- then Master send a confirmation command to Datalogger: 'F'. This command will callback finished function;
And the problem is here! Datalogger stops to accept commands once configSens was executed.
You can download my attached code.
I commented non relevant code on Datalogger (I'm testing only this problem). The code of Master is only a simple version.
I already tested different baud values, commented serial communication (apart of ICSC) and many many other things, but nothing fixes this.
Can you point me in the direction of the DS3231 library you're using? None of the versions I have found will work with your code (not a class, no .begin(), etc).
Yes, Seeeduino Stalker board have a 328p. On Arduino IDE, the board is "Arduino Pro or Pro Mini (3.3V, 8MHz) w/ ATmega 328".
I have around 500 bytes available, running last function of that playground page.
On Arduino IDE, the compile return this info: Binary sketch size: 25,290 bytes (of a 30,720 byte maximum) Estimated used SRAM memory: 1,484 bytes (of a 2048 byte maximum)
As you can see the volume cache buffer of the SD card is huge compared to everything else.
ICSC is the next biggest. You can reduce the footprint of ICSC by tweaking some #define entries in the header file:
// This defines the maximum size of any message that can be sent
// between chips. Reduce this to conserve memory at the cost
// of smaller packet sizes. Note that this only affects the
// size of packets that can be received - you can always send
// up to 255 bytes. If the remote end can't receive them all
// the packet will be silently discarded.
#define MAX_MESSAGE 25
// The maximum number of registered commands. If you're not
// going to have many commands reducing this can save memory.
// If you want lots of commands you may need to increase this
// value. Note that this ony affects the commands registerable
// at the receiving end
#define MAX_COMMANDS 10
In the data logger the MAX_COMMANDS could be reduced to 7. If you're not actively using the data portion sent in the packets you can reduce them down to just an empty string "" and drop the max packet size to 9 (8 bytes of packet, and 1 byte of empty string), or use the longer form of the send routine that takes a data pointer and a length, and set the length to 0 and the data pointer to null. Then you can set the max size to 8.
Or you can enable dynamic mode:
// Uncomment the definition of ICSC_DYNAMIC if you want to use
// dynamic memory allocation
//#define ICSC_DYNAMIC
which is even more memory efficient, but allocates memory on the fly. It might be better, or it might not.
I know SD lib takes a huge volume of memory. Initially a tried to use a tiny lib to read/write from SD (don't remember what lib), but something went wrong...
I can test without SoftwareSerial too, it's only for debug.
I will try your hints now and I will post feedback soon.
I really don't know why, but I already have uncommented the line #define ICSC_DYNAMIC (maybe because a previously problem I had with SD card, I tried to change this and forgot to reverse... ). A noob mistake but very unfair
Now, I commented it (disabled dynamic memory allocation) and everything working as expected.