This library allows to share variables between devices on the same CAN bus. A data pool is defined by its unique name (hash code) and its number of 32bit variables.

Each device can read and write the variable values while the library makes sure that the values are up-to-date in the background.
To use this library
#include "Datapool.h"
Define and Create a data pool
#define POOL_NAME "A_SimplePool_V1_2"
#define NB_OF_VARIABLES 10
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING,
POOL_NAME, NB_OF_VARIABLES );
Start the data pool
myPool.begin();
Example
The following example creates a data pool and let the user modify the int-value of variabel 1. If any variable of the pool is modified remotely then it will be printed.
#include "Datapool.h"
#define NB_OF_VARIABLES 3
#define POOL_NAME "A_SimplePool_V1_0"
void myCallBack(uint8_t ou8_NbOfUpdatedVariable);
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING, POOL_NAME, NB_OF_VARIABLES, myCallBack );
void setup() {
while(!Serial);
myPool.begin();
Serial.println("Enter new value of Var1");
}
int8_t s8_modVar = -1;
void loop()
{
if(Serial.peek() != -1)
{
int i_new = Serial.readStringUntil('\n').toInt();
myPool.setValue( 1, (int32_t)i_new );
}
if(s8_modVar > -1)
{
Serial.println("Var"+String(s8_modVar)+": "+
String( myPool.getValue_int32(s8_modVar) ));
s8_modVar = -1;
}
}
void myCallBack(uint8_t ou8_NbOfUpdatedVariable)
{
s8_modVar = ou8_NbOfUpdatedVariable;
}
Hint: Use the Datapool-Monitor that is embedded in the CAN2SER monitor:

Datapool library notes & features
The library provides further feature such as:
- call-back function whenever a variable is modified
- cyclic distribution of variables or only if the value is changed
- ‘listen only’ variables that we only read but never share from your side
Further information
Please see the libraries methods (on right hand side) to learn more.
Note: as an example, the DICE_GPS library uses the Datapool library to share the positioning information and time hence you could see it in the datapool-monitor, too.