Using Flash instead of EEPROM

I am trying to use an Atlas Scientific pH sensor, however, during compilation I receive the error "do_grav.cpp:9:10: fatal error: EEPROM.h: No such file or directory" which makes sense as there is no native EEPROM on the GIGA. I only need to be able to store and retrieve the calibration settings which are only done on demand.

Is there an easy way to make this utilize flash over EEPROM?


#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include "do_grav.h"
#include "EEPROM.h"


Gravity_DO::Gravity_DO(uint8_t pin){
	this->pin = pin;
    this->EEPROM_offset = (pin) * EEPROM_SIZE_CONST;
    //to lay the calibration parameters out in EEPROM we map their locations to the analog pin numbers
    //we assume a maximum size of EEPROM_SIZE_CONST for every struct we're saving  
}

bool Gravity_DO::begin(){
    #if defined(ESP8266) || defined(ESP32)
        EEPROM.begin(1024);
    #endif 
	if((EEPROM.read(this->EEPROM_offset) == magic_char)
    && (EEPROM.read(this->EEPROM_offset + sizeof(uint8_t)) == GRAV_DO)){
		EEPROM.get(this->EEPROM_offset,Do);
		return true;
    }
	return false;
}

float Gravity_DO::read_voltage() {
    float voltage_mV = 0;
    for (int i = 0; i < volt_avg_len; ++i) {
      voltage_mV += analogRead(this->pin) / 1024.0 * 5000.0;
    }
    voltage_mV /= volt_avg_len;
    return voltage_mV;
}

float Gravity_DO::read_do_percentage(float voltage_mV) {
    return voltage_mV * 100.0 / this->Do.full_sat_voltage;
}

float Gravity_DO::cal() {
    this->Do.full_sat_voltage = read_voltage();
    EEPROM.put(this->EEPROM_offset,Do);
    #if defined(ESP8266) || defined(ESP32)
        EEPROM.commit(); 
    #endif
}

float Gravity_DO::cal_clear() {
    this->Do.full_sat_voltage = DEFAULT_SAT_VOLTAGE;
    EEPROM.put(this->EEPROM_offset,Do);
    #if defined(ESP8266) || defined(ESP32)
        EEPROM.commit(); 
    #endif
}

float Gravity_DO::read_do_percentage() {
  return(read_do_percentage(read_voltage()));
}

On STM32 mcu's the EEPROM library works by emulating EEPROM on flash. I don't know is similar library available for Giga (that is STM32 too)?

I looked into this as I'm migrating from a mega to a giga and make heavy use of the eeprom on the mega.

I ended up buying an I2C eeprom module and using Rot T's i2c eeprom lib GitHub - RobTillaart/I2C_EEPROM: Library for I2C EEPROM - 24LC256

The reason was down to the page erases that are required for flash writes. And whilst I believe erases are also required with eeprom, it's at the bit/byte level which is how I use it.

Getting the external module and using Rob's lib made the rework minimal.

1 Like

@stevebeswick Looks like I will take the same route for now. Can you share which module you purchased?

Did it work? I have the exact same issue with the Atlas Scientific pH sensor, and I purchased an external EEPROM module, but I still can't make it work. Could you share your code or any advice? Thanks.

If using AT24C, try this code on my github. Fixed compatible for GIGA R1

1 Like

I have not had a chance to touch it unfortunately, parts are collecting dust. Hopefully I will get back at it over the next week or two. I will try @nProtect solution as well to see if that may be a better route. If you happen to try, please post your results.