element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum I need help integrating EEPROMEX.h
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 3 replies
  • Subscribers 416 subscribers
  • Views 650 views
  • Users 0 members are here
Related

I need help integrating EEPROMEX.h

e14 Contributor
e14 Contributor over 13 years ago

I am dying here and cant sleep thinking about this project. I am a PLC Programmer with no C++ experience except for my recent attempt to write it to arduino.sketch. I have downloaded the "flow meter" sketch from Jaycar. I have been able to make minor changes to make it do what I want. The only problem is, I do not want to lose my total litres count if the power cycles. The count will only be 2 digits or less. I need to integrate the library EEPROMEX into the sketch to retain the count in memory (without wearing out the eeprom by using the eepromex to increment to the next memory location each time it backs up as per http://thijs.elenbaas.net/). I am only using milliLitresA and have illiminated B. I have tried a million times to insert this logic without any luck. Can anyone help me write this correctly?  I dont know how to post the file for the modified sketch of this project. Thanks for any help

  • Sign in to reply
  • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago

    Perry,

    I dont know how to post the file for the modified sketch of this project.

    There are several ways to post the file. 

    1) you can copy/paste it into your post.

    2) you can attach it as a separate file.

     

    note: to paste, sometimes you have to hold the "Control" key when you right-click the mouse.

    note: to attach a separate file you have to use the "advanced editor" which can be selected

    in the upper-right part of the posting window, then look at the bottom of the window for "Attach file".

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Thanks, I did try the paste, let me try to paste with control:

     

    #include <EEPROMEx.h>
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    // Specify the pins for the two counter reset buttons and indicator LED
    byte resetButtonA = 11;
    byte statusLed    = 13;

    byte sensorInterrupt = 0;  // 0 = pin 2; 1 = pin 3
    byte sensorPin       = 2;

    // The hall-effect flow sensor outputs approximately 4.5 pulses per second per
    // litre/minute of flow.
    float calibrationFactor = 4.5;

    volatile byte pulseCount; 

    float flowRate;
    unsigned int flowMilliLitres;
    unsigned int totalMilliLitresA;

    unsigned long oldTime;

    void setup()
    {
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");

      // Initialize a serial connection for reporting values to the host
      Serial.begin(38400);

      // Set up the status LED line as an output
      pinMode(statusLed, OUTPUT);
      digitalWrite(statusLed, HIGH);  // We have an active-low LED attached

      // Set up the pair of counter reset buttons and activate internal pull-up resistors
      pinMode(resetButtonA, INPUT);
      digitalWrite(resetButtonA, HIGH);
     
      pinMode(sensorPin, INPUT);
      digitalWrite(sensorPin, HIGH);

      pulseCount        = 0;
      flowRate          = 0.0;
      flowMilliLitres   = 0;
      totalMilliLitresA = min(totalMilliLitresA, 0);
      totalMilliLitresA - max(totalMilliLitresA, 58000);
      oldTime           = 0;

       
      // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
      // Configured to trigger on a FALLING state change (transition from HIGH
      // state to LOW state)
      attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
    }

    /**
    * Main program loop
    */
    void loop()
    {
      if(digitalRead(resetButtonA) == LOW);
     
      {
        totalMilliLitresA = 58000;
        lcd.setCursor(0, 1);
        lcd.print(" reset");
       
        }
         if((millis() - oldTime) > 1000)    // Only process counters once per second
      {
        // Disable the interrupt while calculating flow rate and sending the value to
        // the host
        detachInterrupt(sensorInterrupt);
        //lcd.setCursor(15, 0);
        //lcd.print("*");

        // Because this loop may not complete in exactly 1 second intervals we calculate
        // the number of milliseconds that have passed since the last execution and use
        // that to scale the output. We also apply the calibrationFactor to scale the output
        // based on the number of pulses per second per units of measure (litres/minute in
        // this case) coming from the sensor.
        flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

        // Note the time this processing pass was executed. Note that because we've
        // disabled interrupts the millis() function won't actually be incrementing right
        // at this point, but it will still return the value it was set to just before
        // interrupts went away.
        oldTime = millis();

        // Divide the flow rate in litres/minute by 60 to determine how many litres have
        // passed through the sensor in this 1 second interval, then multiply by 1000 to
        // convert to millilitres.
        flowMilliLitres = (flowRate / 60) * 1000;

        // Add the millilitres passed in this second to the cumulative total
        totalMilliLitresA -= flowMilliLitres;
       

        // During testing it can be useful to output the literal pulse count value so you
        // can compare that and the calculated flow rate against the data sheets for the
        // flow sensor. Uncomment the following two lines to display the count value.
        //Serial.print(pulseCount, DEC);
        //Serial.print("  ");

        // Write the calculated value to the serial port. Because we want to output a
        // floating point value and print() can't handle floats we have to do some trickery
        // to output the whole number part, then a decimal point, then the fractional part.
        unsigned int frac;

        // Print the flow rate for this second in litres / minute
        Serial.print(int(flowRate));  // Print the integer part of the variable
        Serial.print(".");             // Print the decimal point
        // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
        frac = (flowRate - int(flowRate)) * 10;
        Serial.print(frac, DEC) ;      // Print the fractional part of the variable

        // Print the number of litres flowed in this second
        Serial.print(" ");             // Output separator
        Serial.print(flowMilliLitres);

        // Print the cumulative total of litres flowed since starting
        Serial.print(" ");
        Serial.print(totalMilliLitresA);
                   
          

        lcd.setCursor(0, 0);
        lcd.print("                ");
        lcd.setCursor(0, 0);
        lcd.print("Flow: ");
        if(int(flowRate) < 10)
        {
          lcd.print(" ");
        }
        lcd.print((int)flowRate);   // Print the integer part of the variable
        lcd.print('.');             // Print the decimal point
        lcd.print(frac, DEC) ;      // Print the fractional part of the variable
        lcd.print(" L");
        lcd.print("/min");

       
          
        lcd.setCursor(0, 1);
        lcd.print(int(totalMilliLitresA / 100));
        lcd.print("  Ltrs left");
       

        // Reset the pulse counter so we can start incrementing again
        pulseCount = 0;

        // Enable the interrupt again now that we've finished sending output
        attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
      }
    }

    /**
    * Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
    * handlers should be kept as small as possible so they return quickly.
    */
    void pulseCounter()
    {
      // Increment the pulse counter
      pulseCount++;
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 13 years ago in reply to e14 Contributor

    Thanks, I did try the paste, let me try to paste with control:

     

    #include <EEPROMEx.h>
    #include <LiquidCrystal.h>

    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    // Specify the pins for the two counter reset buttons and indicator LED
    byte resetButtonA = 11;
    byte statusLed    = 13;

    byte sensorInterrupt = 0;  // 0 = pin 2; 1 = pin 3
    byte sensorPin       = 2;

    // The hall-effect flow sensor outputs approximately 4.5 pulses per second per
    // litre/minute of flow.
    float calibrationFactor = 4.5;

    volatile byte pulseCount; 

    float flowRate;
    unsigned int flowMilliLitres;
    unsigned int totalMilliLitresA;

    unsigned long oldTime;

    void setup()
    {
      lcd.begin(16, 2);
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");

      // Initialize a serial connection for reporting values to the host
      Serial.begin(38400);

      // Set up the status LED line as an output
      pinMode(statusLed, OUTPUT);
      digitalWrite(statusLed, HIGH);  // We have an active-low LED attached

      // Set up the pair of counter reset buttons and activate internal pull-up resistors
      pinMode(resetButtonA, INPUT);
      digitalWrite(resetButtonA, HIGH);
     
      pinMode(sensorPin, INPUT);
      digitalWrite(sensorPin, HIGH);

      pulseCount        = 0;
      flowRate          = 0.0;
      flowMilliLitres   = 0;
      totalMilliLitresA = min(totalMilliLitresA, 0);
      totalMilliLitresA - max(totalMilliLitresA, 58000);
      oldTime           = 0;

       
      // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
      // Configured to trigger on a FALLING state change (transition from HIGH
      // state to LOW state)
      attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
    }

    /**
    * Main program loop
    */
    void loop()
    {
      if(digitalRead(resetButtonA) == LOW);
     
      {
        totalMilliLitresA = 58000;
        lcd.setCursor(0, 1);
        lcd.print(" reset");
       
        }
         if((millis() - oldTime) > 1000)    // Only process counters once per second
      {
        // Disable the interrupt while calculating flow rate and sending the value to
        // the host
        detachInterrupt(sensorInterrupt);
        //lcd.setCursor(15, 0);
        //lcd.print("*");

        // Because this loop may not complete in exactly 1 second intervals we calculate
        // the number of milliseconds that have passed since the last execution and use
        // that to scale the output. We also apply the calibrationFactor to scale the output
        // based on the number of pulses per second per units of measure (litres/minute in
        // this case) coming from the sensor.
        flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

        // Note the time this processing pass was executed. Note that because we've
        // disabled interrupts the millis() function won't actually be incrementing right
        // at this point, but it will still return the value it was set to just before
        // interrupts went away.
        oldTime = millis();

        // Divide the flow rate in litres/minute by 60 to determine how many litres have
        // passed through the sensor in this 1 second interval, then multiply by 1000 to
        // convert to millilitres.
        flowMilliLitres = (flowRate / 60) * 1000;

        // Add the millilitres passed in this second to the cumulative total
        totalMilliLitresA -= flowMilliLitres;
       

        // During testing it can be useful to output the literal pulse count value so you
        // can compare that and the calculated flow rate against the data sheets for the
        // flow sensor. Uncomment the following two lines to display the count value.
        //Serial.print(pulseCount, DEC);
        //Serial.print("  ");

        // Write the calculated value to the serial port. Because we want to output a
        // floating point value and print() can't handle floats we have to do some trickery
        // to output the whole number part, then a decimal point, then the fractional part.
        unsigned int frac;

        // Print the flow rate for this second in litres / minute
        Serial.print(int(flowRate));  // Print the integer part of the variable
        Serial.print(".");             // Print the decimal point
        // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
        frac = (flowRate - int(flowRate)) * 10;
        Serial.print(frac, DEC) ;      // Print the fractional part of the variable

        // Print the number of litres flowed in this second
        Serial.print(" ");             // Output separator
        Serial.print(flowMilliLitres);

        // Print the cumulative total of litres flowed since starting
        Serial.print(" ");
        Serial.print(totalMilliLitresA);
                   
          

        lcd.setCursor(0, 0);
        lcd.print("                ");
        lcd.setCursor(0, 0);
        lcd.print("Flow: ");
        if(int(flowRate) < 10)
        {
          lcd.print(" ");
        }
        lcd.print((int)flowRate);   // Print the integer part of the variable
        lcd.print('.');             // Print the decimal point
        lcd.print(frac, DEC) ;      // Print the fractional part of the variable
        lcd.print(" L");
        lcd.print("/min");

       
          
        lcd.setCursor(0, 1);
        lcd.print(int(totalMilliLitresA / 100));
        lcd.print("  Ltrs left");
       

        // Reset the pulse counter so we can start incrementing again
        pulseCount = 0;

        // Enable the interrupt again now that we've finished sending output
        attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
      }
    }

    /**
    * Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
    * handlers should be kept as small as possible so they return quickly.
    */
    void pulseCounter()
    {
      // Increment the pulse counter
      pulseCount++;
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube