Example Code for Arduino-EF Database

Last revision 2026/01/13

This article provides example code for utilizing the Arduino-EF Database with the Firebeetle M0, demonstrating how to configure, print, and delete flash key-values using the DFRobot_EasyFlash Library.

Hardware Preparation

Software Preparation

Other Preparation Work

Firebeetle M0 has built-in DFRobot_EasyFlash Library, and the related demo can be found in the following.

Sample Code

Config flash key-value, print then delete the key by serial.

/*!
 * @file delValue.ino
 * @brief Set a key-value pair and delete it by key 
 * @n Experiment phenomenon: serial print the length of value the key corresponds 
 *
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [LiYue]([email protected])
 * @version  V1.0
 * @date  2019-12-23
 * @get from https://www.dfrobot.com
 * @url https://github.com/cdjq/DFRobot_EasyFlash
 */

#include <DFRobot_EasyFlash.h>
DFRobot_EasyFlash easyflash;

char key[] = "key";               
char value[] = "value";
char valueRec[20];
size_t valueLen;
size_t getLen;
String data;
void setup()
{
  Serial.begin(115200);
  while(!Serial);
  easyflash.begin();
  easyflash.setValue(key,value);
  data = easyflash.getValue(key);
  getLen = easyflash.getValue(key,valueRec,20,valueLen);   //getValue() return the length of the obtained key. valueLen records the real length of the value. (Since the obtained length is smaller than/equal to the buffer length, it may smaller than the real length)
  Serial.print("The length of the value is :");Serial.println(getLen);
  Serial.println(data);
  easyflash.delValue(key);                        //Delete key-value pair according to key
  getLen = easyflash.getValue(key,valueRec,20,valueLen);  //getValue() return the real length obtained. Note that if the value has been deleted, valueLen cannot get the actual length of the value, so the value of valueLen will not change. It should be the exactly the same as the value passed in.
  Serial.print("After delete the key&value.The length of the value is :");Serial.println(getLen);
}

void loop() {

}

Result

The serial port prints the length of the value corresponding to the key before and after deletion.

Was this article helpful?

TOP