The User Space configuration is usually performed during the setup(). It is done by setting the size (in bytes) of each sub-space:
- HC_eeprom.setUserSpace(Boolean, Byte, Integer, Long, Float, String)
The size of a sub-space represents the number of memory cells occupied by this sub-space. The max number of elements contained in the sub-space will depend on the sub-space size and its data type.
Keeping all sub-spaces
void setup() { // initialize library HC_begin(); // configure User Space (set sub-spaces sizes) HC_eeprom.setUserSpace( 20, // Boolean space : default 50 100, // Byte space : default 100 100, // Integer space : default 200 100, // Long space : default 250 300, // Float space : default 250 4096); // String space : default 4096 }
In this example, we ask the sub-spaces to have the following sizes:
- Boolean : 20 bytes
- Byte : 100 bytes
- Integer : 100 bytes
- Long : 100 bytes
- Float : 300 bytes
- String : 4096 bytes.
Note that the String Space size is set to a high value so that it fills the remaining free space. Its true size will depend on the available memory space:
Removing sub-spaces (1)
If you want to remove a sub-space, set its size to 0.
Space allocation is done in a specific order, starting with Boolean Space, and ending with String Space. If the first allocated sub-spaces are too big, the remaining non-allocated sub-spaces are either shortened or removed (size set to 0).
Refer to this example : Changing the User Space.
void setup() { // initialize library HC_begin(); // configure User Space (set sub-spaces sizes) HC_eeprom.setUserSpace( 0, // Boolean space : default 50 500, // Byte space : default 100 0, // Integer space : default 200 4096, // Long space : default 250 0, // Float space : default 250 0); // String space : default 4096 }
Removing sub-spaces (2)
You are not required to allocate all the memory space. The remaining non-allocated space will just be unused by the library.
Refer to this example : Changing the User Space.
void setup() { // initialize library HC_begin(); // configure User Space (set sub-spaces sizes) HC_eeprom.setUserSpace( 0, // Boolean space : default 50 500, // Byte space : default 100 0, // Integer space : default 200 0, // Long space : default 250 0, // Float space : default 250 0); // String space : default 4096 }
Configuring the String Space
String Space configuration is done by setting the max length of all the Strings stored inside (this length does not include the terminating char ‘\0’), using the following function:
- HC_eeprom.setMaxStringLength(length) => possible length values : 1 to 30, default 30.
You can retrieve this configuration parameter with:
- HC_eeprom.getMaxStringLength() => return length (byte)
Refer to this example : Configuring the String Space.
void setup() { // initialize library HC_begin(); // configure String Space HC_eeprom.setMaxStringLength(15); // 1 to 30, default 30 }
In this example, the default configuration is applied, except that the max String length is 15.
This length impacts on the number of String which can be recorded in the String Space. For the Arduino Uno, the default String Space size is 130. So, the number of String which can be contained in the String Space here is 130/15 = 8 Strings.
Using the default configuration
Refer to this example : Using the EEPROM Panel.
#include <HITIComm.h> void setup() { // initialize library HC_begin(); } void loop() { // configure User Space with default configuration HC_communicate(); }
In the default configuration, we ask the sub-spaces to have the following sizes:
- Boolean : 50 bytes
- Byte : 100 bytes
- Integer : 200 bytes
- Long : 250 bytes
- Float : 250 bytes
- String : 4096 bytes.
Note that the String Space size is set to a high value so that it fills the remaining free space. Its true size will depend on the available memory space:
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article