A versatile Arduino library for ESP32 that provides persistent calibration data storage and management capabilities. This library simplifies the process of storing, retrieving, and managing calibration values for sensors, displays, and communication settings.
- Features
- Hardware Requirements
- Quick Start
- Installation
- Dependencies
- Calibration Concepts
- Basic Usage
- Examples
- API Reference
- Error Handling
- Best Practices
- Compatibility Matrix
- Memory Usage
- Troubleshooting
- Security Considerations
- Contributing
- License
- Support
- Changelog
- Persistent storage using ESP32's NVS (Non-Volatile Storage)
- Multiple data type support (int, float, string)
- Namespace-based organization
- JSON import/export capabilities
- Version control and timestamp management
- Encryption support for sensitive data
- Batch operations for atomic updates
- Comprehensive error handling and debugging
- Memory usage monitoring
- Real-time validation
- Backup/restore functionality
- Cross-platform compatibility
- Structured data format support
- ESP32 development board (any variant)
- Minimum 4MB flash memory
- Compatible sensors (optional, based on examples):
- BME280 (temperature/humidity/pressure)
- MPU6050 (accelerometer/gyroscope)
- Potentiometer
- RGB LED
- OLED Display
#include <CalibrationLib.h>
void setup() {
CalibrationLib calib;
calib.begin("quickstart");
// Store a calibration value
calib.setCalibrationValue("sensor_offset", 1.5f);
// Read it back
float offset;
calib.getCalibrationValue("sensor_offset", offset);
Serial.printf("Calibration offset: %.2f\n", offset);
}- Open Arduino IDE
- Go to
Sketch > Include Library > Manage Libraries - Search for "CalibrationLib"
- Click Install
- Download this repository as a ZIP file
- In Arduino IDE, go to
Sketch > Include Library > Add .ZIP Library - Select the downloaded ZIP file
- ESP32 Arduino Core
- Preferences.h (included with ESP32 core)
- ArduinoJson (for JSON functionality)
- Adafruit BME280 Library (for BME280 example)
- Adafruit MPU6050 (for sensor fusion example)
- Adafruit Unified Sensor (sensor support)
Calibration is the process of adjusting measurement data to match known reference values. Common calibration types include:
-
Linear Calibration
calibrated_value = (raw_value * scale) + offset
-
Multi-point Calibration
- Uses multiple reference points
- Interpolates between known values
- Better accuracy across range
-
Auto-calibration
- Self-adjusting based on known conditions
- Periodic recalibration support
Calibration data is stored in ESP32's Non-Volatile Storage (NVS):
- Survives power cycles
- Organized by namespaces
- Protected against corruption
- Optional encryption
#include <CalibrationLib.h>
CalibrationLib calib;
void setup() {
// Initialize with a namespace
calib.begin("mysensor");
// Store calibration values
calib.setCalibrationValue("offset", 2.5f);
calib.setCalibrationValue("scale", 1.023f);
// Read calibration values
float offset, scale;
calib.getCalibrationValue("offset", offset, 0.0f); // Default 0.0 if not found
calib.getCalibrationValue("scale", scale, 1.0f); // Default 1.0 if not found
// Export to JSON
String jsonData;
calib.exportToJson(jsonData);
// Close when done
calib.end();
}{
"version": "1.0.0",
"timestamp": 1634567890,
"namespace": "mysensor",
"values": {
"offset": 2.5,
"scale": 1.023
}
}- BasicCalibration: Simple demonstration of storing and retrieving values
- CalibrationBackupRestore: Data backup and restore functionality
- MultiSensorCalibration: Managing multiple sensor calibrations
- SensorCalibrationWorkflow: Step-by-step calibration process
- BME280Integration: Environmental sensor calibration
- TemperatureAutoCalibration: Self-calibrating temperature sensor
- PotentiometerCalibration: Analog input calibration
- RGBLedCalibration: LED color balance adjustment
- BLECalibration: Bluetooth configuration interface
- MQTTCalibration: MQTT settings management
- OLEDCalibration: Display parameter adjustment
- WebCalibrationInterface: Browser-based calibration
- SensorFusion: Combined sensor data calibration
- UnitTests: Library validation tests
| ESP32 Board | Tested | Minimum Flash | Notes |
|---|---|---|---|
| ESP32 DevKit | ✅ | 4MB | Full support |
| ESP32-S2 | ✅ | 4MB | Full support |
| ESP32-C3 | ✅ | 4MB | Full support |
| ESP32-S3 | ✅ | 4MB | Full support |
| Component | Flash Usage | RAM Usage |
|---|---|---|
| Core Library | ~32KB | ~2KB |
| JSON Support | ~10KB | ~1KB |
| Encryption Module | ~8KB | ~1KB |
CAL_OK // Operation successful
CAL_NOT_INITIALIZED // Library not initialized
CAL_INVALID_PARAM // Invalid parameter provided
CAL_WRITE_ERROR // Failed to write to storage
CAL_READ_ERROR // Failed to read from storage
CAL_MEMORY_ERROR // Memory allocation failed
CAL_ENCRYPTION_ERROR // Encryption/decryption failedDEBUG_NONE // No debug output
DEBUG_ERROR // Errors only
DEBUG_INFO // General information
DEBUG_VERBOSE // Detailed debugging-
Initialization Fails
- Check if namespace is valid
- Verify flash partition size
- Ensure proper board selection
-
Data Persistence Issues
- Verify write operations return success
- Check available storage space
- Ensure proper closure of namespace
-
Memory Problems
- Monitor heap fragmentation
- Use appropriate JSON buffer sizes
- Implement proper memory management
Please report security vulnerabilities to judassithole@duck.com. We follow responsible disclosure practices and will work with you to address any security concerns.
- All sensitive calibration data can be encrypted
- Implementation uses standard ESP32 encryption features
- Regular security audits are performed
-
Namespace Organization
- Use descriptive namespace names
- Separate concerns (e.g., "sensor1", "display")
- Keep names short but meaningful
-
Error Handling
- Check return values
- Set appropriate debug levels
- Provide fallback values
-
Resource Management
- Close calibration when done
- Monitor memory usage
- Use batch operations for multiple updates
-
Security
- Enable encryption for sensitive data
- Validate input data
- Regular backups
-
Version Control
- Track calibration versions
- Handle version migrations
- Set expiration times
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details
- Check the examples included with the library
- Review the documentation
- Open an issue on GitHub
- Contact: judassithole@duck.com
- Initial release
- Core calibration functionality
- JSON import/export support
- Multiple sensor examples
- Documentation and examples
- ESP32 Arduino Core team
- Arduino community
- All contributors and users of this library
- Sensor fusion calibration
- Dynamic calibration based on sensor data
- Integration with machine learning algorithms
- Real-time monitoring and adjustment
- Cloud synchronization for remote access