Hey guys,
I'm building a flow meter with a display for a water filter system (reverse osmosis). The display is supposed to show the volume of water dispensed right now as well as the total volume dispensed since the last filter change, among some other things that don't matter here. Since the total volume dispensed should be saved even when the board loses power, it should be saved to EEPROM.
The board I have uses its own EEPROM library that I found by following the link in the product description on Aliexpress:
But I just can't get it to work with this library. It doesn't seem to support the EEPROM.get() and EEPROM.put() functions at all, which I need because the volume is counted in milliliters and I have to use an unsigned long to store it. But even if I use the EEPROM.read() and EEPROM.write() functions, I still get this error message:
C:\Users\notapantsday\Documents\Arduino\Wasserhahn\Display2\Display2.ino: In function 'void setup()':
C:\Users\notapantsday\Documents\Arduino\Wasserhahn\Display2\Display2.ino:45:27: error: no matching function for call to 'EEPROMClass::read(int, int&)'
EEPROM.read(0, mlCounter); // read out the counter from EEPROM
^
In file included from C:\Users\notapantsday\Documents\Arduino\Wasserhahn\Display2\Display2.ino:11:0:
C:\Users\notapantsday\Documents\Arduino\hardware\LGT\avr\libraries\E2PROM/EEPROM.h:175:13: note: candidate: uint8_t EEPROMClass::read(int)
uint8_t read( int idx ) { return EERef( idx ); }
^~~~
C:\Users\notapantsday\Documents\Arduino\hardware\LGT\avr\libraries\E2PROM/EEPROM.h:175:13: note: candidate expects 1 argument, 2 provided
exit status 1
Compilation error: no matching function for call to 'EEPROMClass::read(int, int&)'
Can anyone help me out here? Is it a problem with the EEPROM library or am I using it wrong? Where/how can I get a working library? Simply replacing the one in the folder with the "standard" EEPROM.h also leads to error messages.
Here's my code:
// A7 TDS
// A6 temp
// D6 flow
// D5 button
// D2 button
// A4 display SDA
// A5 display SCL
#include <Arduino.h>
#include <U8g2lib.h>
#include <EEPROM.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* clock=*/ A5, /* data=*/ A4, /* reset=*/ U8X8_PIN_NONE);
const int intrPin = 2;
const int button1Pin = 2;
const int button2Pin = 5;
const int tempPin = A6;
const int tdsPin = A7;
int ppm;
unsigned long liters;
unsigned long mlCounter;
volatile long count;
float volume;
int ml;
int ml1;
int ml2;
unsigned long startMillis;
unsigned long currentMillis;
unsigned long resetTime = 5000;
unsigned long standbyTime = 20000;
bool timer = false;
bool standby = false;
void setup() {
EEPROM.read(0, mlCounter); // read out the counter from EEPROM
u8g2.begin();
Serial.begin(9600);
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(intrPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(intrPin), Flow, RISING); //Configures interrupt 0 (pin 2 on the Arduino Uno) to run the function "Flow"
}
void loop() {
interrupts(); //Enables interrupts on the Arduino
volume = count * 0.5; // convert counts to milliliters
ml = (int)(volume + 0.5);
currentMillis = millis();
ml2 = ml;
// check for volume changes
if (ml2 == ml1 && timer == false) // same volume but counter not running yet
{
startMillis = millis(); // set timer to zero
timer = true; // timer is running
}
else if (ml2 != ml1) // volume changes
{
startMillis = millis(); // set timer to zero
timer = false; // timer is not running
standby = false;
}
// time elapsed since last change in volume
if (currentMillis - startMillis >= standbyTime && timer == true && count == 0) // timer is running and standby time has passed, count is already reset
{
timer = true; // timer keeps running
standby = true; // activate standby
}
else if (currentMillis - startMillis >= resetTime && timer == true && standby == false) // timer is running and reset time has passed, not in standby (yet)
{
mlCounter += ml;
EEPROM.write(0, mlCounter); // write the contents of mlCounter to the EEPROM starting at address 0
count = 0;
timer = true;
standby = false;
}
liters = int(mlCounter / 1000);
ml1 = ml;
ppm = 0.2 * (analogRead(tdsPin)) - 23; //calculate ppm from voltage
// ppm = analogRead(0);
if (standby == false)
{ u8g2.firstPage();
do {
u8g2.setCursor(0, 25);
u8g2.setFont(u8g2_font_helvB24_tf);
u8g2.print(ml);
u8g2.print(" ml");
u8g2.setCursor(0, 50);
u8g2.setFont(u8g2_font_helvB14_tf);
u8g2.print(ppm);
u8g2.print(" ppm");
u8g2.setCursor(97, 60);
u8g2.setFont(u8g2_font_5x7_tf);
u8g2.print(liters);
} while ( u8g2.nextPage() );}
else if (standby == true)
{ u8g2.firstPage();
do {
u8g2.clearDisplay();
} while ( u8g2.nextPage() );}
}
void Flow()
{
count++;
}
Thanks a lot in advance for any help!