Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Reading from EEPROM error in code

Home Forums Mayfly Data Logger Reading from EEPROM error in code

Viewing 6 reply threads
  • Author
    Posts
    • #15184
      James_NZ
      Participant

        Hi,

        I am trying to write some code to test some new low-cost sensors, including a DFRobot gravity conductivity sensor (https://www.dfrobot.com/product-1123.html).  I have used snippets of DFRobot’s code, and built calculated variable functions in modular sensors to read data.  In this case the DFRobor code uses a ‘k’ value as a crude calibration method, i.e. essentially a scaling factor.  I use a separate calibration script to calculate the k value and store it in the EEPROM, which is retrieved  upon initiation of the modular sensors program.

        This method works if I build a script that only reads and returns the SpC value from the condy sensor.  However, the same line of code returns an error when I combine it with the modular sensor code.

        If I comment out all the references to the EEPROM and use a defined k value instead (e.g. kvalue = 1), the modular sensors code compiles with no problems.

        I usually like to work through coding issues myself but in this case I seem to be overlooking something seemingly simple.  Can anyone see anything obvious that I am missing?

        Thanks in advance for your help.

        Regards,

        James

         

        My full modular sensor code (please forgive my inefficiencies, I am just learning c++) :

         

         

         

         

      • #15185
        Sara Damiano
        Moderator

          I think you just missed commenting out one more reference to the EEPROM in line 144: EEPROM_read(KVALUEADDR, Kvalue); //1.0 means no change to raw readings. Just commenting or deleting that line should fix the compiler error.  I would also suggest you delete lines 38-43 so you’re not even trying to include the unused EEPROM library.

          If you wanted to, you could use the “extVoltage” sensor in ModularSensors with >1 reading to simplify all your code for reading the analog values. You would still need to create a calculated variable for the pH, conductivity, and eTape calculated from the voltage.  There’s nothing wrong, though, with reading the value and doing the calculations just as you are.

        • #15186
          Sara Damiano
          Moderator

            If you’re still using the Arduino IDE, you might consider switching to VSCode (or Atom) with PlatformIO.  I know VSCode seems very scary to start with, but if you’re writing new code or even just copy-pasting chunks the linting tools it provides are invaluable.  When I created a project for your code in VSCode, it immediately highlighted the errant EEPROM line.  I know when I try write code of any type without the linter, I always screw up and miss semicolons or other small errors that are really hard to find with your eyes reading the code but which the linter flags right away.

          • #15187
            James_NZ
            Participant

              Thanks @srgdamiano! I will try again when I get home from work.

              I am using Atom with PlatformIO. How do I turn the linter tools on? thanks also for the tip on ‘extVoltage’. I was going to write a function that did the same thing as the unnecessary repetition was starting to bug me!

              James

            • #15190
              James_NZ
              Participant

                Hi Sara,

                I worked through this and everything compiles correctly now!  Thanks for your help.

                I did wonder about the linter in Atom.  From what I have read there seems to be an issue with linters working with .ino files in Atom.  Have you guys found anything that works?

                James

                 

                 

              • #15191
                neilh20
                Participant

                  In case its of interest, I’m using the EEPROMClass from EEPROM.h

                  \.platformio\packages\framework-arduino-avr\libraries\EEPROM\src

                  EEPROM.put(EP_PERSISTENT_STORE_ADDR, epc.app);  where epc.app is a typedef containing all the values to be stored/read from persistent EEPROM.

                  and similarly

                  EEPROM.get(EP_PERSISTENT_STORE_ADDR, epc.app);

                • #15192
                  Sara Damiano
                  Moderator

                    I’ve been using primarily VSCode for a while because it loads faster on my computer, but I believe I set Atom up to force ino’s as cpp’s:  https://docs.platformio.org/en/latest/integration/ide/atom.html#force-arduino-file-as-c

                Viewing 6 reply threads
                • You must be logged in to reply to this topic.