Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Arduino freezes when I'm writing EEPROM

Arduino freezes when I'm writing EEPROM

Scheduled Pinned Locked Moved Troubleshooting
17 Posts 4 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mfalkviddM Offline
    mfalkviddM Offline
    mfalkvidd
    Mod
    wrote on last edited by
    #2

    The addresses used by MySensors are documented here: https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/core/MySensorCore.h#L40
    The first address you can use is at EEPROM_LOCAL_CONFIG_ADDRESS

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jhonnygolpe
      wrote on last edited by
      #3

      just tested.... when I replace EEPROM_LOCAL_ADDRESS with EEPROM_LOCAL_CONFIG_ADDRESS, I get some compile warnings, all with the same text:
      warning: large integer implicitly truncated to unsigned type [-Woverflow]
      but the code it's uploaded. But again it freezes by the first time that saveState(EEPROM_LOCAL_CONFIG_ADDRESS, 0) is used.

      1 Reply Last reply
      0
      • J jhonnygolpe

        Hi. I'm trying to sa#define EEPROM_LOCAL_ADDRESS Insert Code Here

            (EEPROM_NODE_ID_ADDRESS+8)
        

        and saving like:

        saveState(EEPROM_LOCAL_ADDRESS,  (uint16_t)newPosition);
        

        but always after a saveState instruction, my program freezes.
        I don't know if mysensors uses all the EEPROM area and so my code generates a problem with it.
        Any help would be apreciated.
        thanks

        tekkaT Offline
        tekkaT Offline
        tekka
        Admin
        wrote on last edited by
        #4

        @jhonnygolpe loadState() and saveState() take care of the addressing internally:

        saveState(pos, val);
        

        will write to EEPROM_LOCAL_CONFIG_ADDRESS + pos

        https://github.com/mysensors/Arduino/blob/development/libraries/MySensors/core/MySensorCore.cpp#L301-L306

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #5

          @jhonnygolpe you get compiler warnings because your newPosition is 16 bits and saveState can only save 8 bits. The saveState definition:
          saveState(uint8_t pos, uint8_t value)

          You'll need to use a 8 bit value for newPosition, or something like @bisschopsr's function here to save all 16 bits. Just remember to increment pos by two (to accomodate for 2x8 bits) if you're saving multiple values.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jhonnygolpe
            wrote on last edited by
            #6

            Hi again. I've just tried your advises and, of course, I've solve my compilation errors. Thanks for your help !!
            But I can't write and rewrite the EEPROM correctly yet. It seems like I'm writing on a new address an y time, so in 2 or 3 times of savind data, arduino freezes.
            Now I've defined

            #define EEPROM_LOCAL_ADDRESS 2
            

            and after just 2 or 3 times of using

            saveState(EEPROM_LOCAL_ADDRESS,  (uint8_t)newPosition);
            

            arduino freezes.
            I've a test code, very similar, but without saving or reading from the EEPROM and works fine, so I suppose it's my fault using correctly those functions.
            Thanks again

            YveauxY 1 Reply Last reply
            1
            • mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by mfalkvidd
              #7

              Strange. Have you tried on another Arduino? Could be that the eeprom is broken.

              How are you powering the Arduino? If I remember correctly, writing to the eeprom can be a bit voltage sensitive.

              On the other hand, the MySensors library writes to the eeprom every now and then and that seems to work.

              Could you post your entire sketch?

              You might also want to add a bunch of Serial.println statements to determine exactly where in the code the Arduino freezes. Is it at the saveState function, or at readState, or somewhere else?

              1 Reply Last reply
              0
              • J jhonnygolpe

                Hi again. I've just tried your advises and, of course, I've solve my compilation errors. Thanks for your help !!
                But I can't write and rewrite the EEPROM correctly yet. It seems like I'm writing on a new address an y time, so in 2 or 3 times of savind data, arduino freezes.
                Now I've defined

                #define EEPROM_LOCAL_ADDRESS 2
                

                and after just 2 or 3 times of using

                saveState(EEPROM_LOCAL_ADDRESS,  (uint8_t)newPosition);
                

                arduino freezes.
                I've a test code, very similar, but without saving or reading from the EEPROM and works fine, so I suppose it's my fault using correctly those functions.
                Thanks again

                YveauxY Offline
                YveauxY Offline
                Yveaux
                Mod
                wrote on last edited by
                #8

                @jhonnygolpe What Arduino hardware are you using?
                Did you try writing to another address?

                http://yveaux.blogspot.nl

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jhonnygolpe
                  wrote on last edited by
                  #9

                  Well, i'm working with Arduino Uno, directly connected to the 220V/5v converter, so the power can't be the problem. I will enclose the code, and to help the reading of it, i'll try to explain it. On the Arduino there are connected a DHT22 sensor, and 2 relays and 2 buttons to control the blinds. I'm using my former motorized blinds, with its wall-mounted controllers (now one button to UP, another to DOWN). I want to use the previous controllers, and add remote control to move the blinds. So in the loop() function, I check if any of the buttons has been pressed, or if it's the time to send some info to the gateway. I use to have problems when I move down the blind remotely, with the receive function. With the debug activated, it seems to freeze after finishing the downAction() function...
                  By the time, I'm gonna try the code with another arduino and another EEPROM address.
                  As you will see I'm using another DEBUG class, very similar to the mysensors'oneSerialDebug.h blindsControlEL.ino

                  mfalkviddM 1 Reply Last reply
                  0
                  • J jhonnygolpe

                    Well, i'm working with Arduino Uno, directly connected to the 220V/5v converter, so the power can't be the problem. I will enclose the code, and to help the reading of it, i'll try to explain it. On the Arduino there are connected a DHT22 sensor, and 2 relays and 2 buttons to control the blinds. I'm using my former motorized blinds, with its wall-mounted controllers (now one button to UP, another to DOWN). I want to use the previous controllers, and add remote control to move the blinds. So in the loop() function, I check if any of the buttons has been pressed, or if it's the time to send some info to the gateway. I use to have problems when I move down the blind remotely, with the receive function. With the debug activated, it seems to freeze after finishing the downAction() function...
                    By the time, I'm gonna try the code with another arduino and another EEPROM address.
                    As you will see I'm using another DEBUG class, very similar to the mysensors'oneSerialDebug.h blindsControlEL.ino

                    mfalkviddM Offline
                    mfalkviddM Offline
                    mfalkvidd
                    Mod
                    wrote on last edited by
                    #10

                    @jhonnygolpe said:

                    With the debug activated, it seems to freeze after finishing the downAction() function...

                    Are you sure it exits the downAction? How about adding debug statements before and after each funtion call in loop()? That would help determine which fuction freezes.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jhonnygolpe
                      wrote on last edited by jhonnygolpe
                      #11

                      [EDIT] I've found that I missed a return; call on the receive() function... and now it's working fine...
                      Really I'm not sure where it fails. And yes, the next step it's write a lot of 'DEBUG'. I've tested changing the eeprom address with the same results, so I'm assuming the fault it's in my code :worried:
                      But always falls after a downAction movement...

                      1 Reply Last reply
                      0
                      • mfalkviddM Offline
                        mfalkviddM Offline
                        mfalkvidd
                        Mod
                        wrote on last edited by
                        #12

                        I think it hangs in this loop:

                        while ( valueU == HIGH
                                          && ((nowMillis - startMillis) / OPERATION_TIME) < 100
                                          && (positionValue + ((nowMillis - startMillis) / OPERATION_TIME)) < 100
                                          &&  (nowMillis - startMillis) < OPERATION_TIME );
                        

                        None of the variables in this loop will be updated while the loop is running, so it will run forever. I don't know what you wanted to do, but I don't think you wanted an infinite loop.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jhonnygolpe
                          wrote on last edited by
                          #13

                          Not really... inside the do loop, that it's repeated anytime, updates valueU and nowMillis values, so it's not an infinite loop.
                          I think it was a problem with the receive function... after calling

                          
                              else {
                                moveBlind(dimvalue); 
                                return;
                              }
                            }
                          

                          the moveBlind function I missed the return;
                          Now it seems to work fine.... I'm sure I'll have some more errors, but i'm satisfied by the moment.
                          Thanks a lot to everybody

                          1 Reply Last reply
                          0
                          • mfalkviddM Offline
                            mfalkviddM Offline
                            mfalkvidd
                            Mod
                            wrote on last edited by mfalkvidd
                            #14

                            What's inside the while loop? To me it looks like nothing. There is no { after the while conditions, just a ;. The ; means that the while loop has no contents except re-evaluating the conditions.

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              jhonnygolpe
                              wrote on last edited by
                              #15

                              It's a

                              do { 
                              ...t 
                              } while();
                              

                              loop. It's similar to the while, but with this one you can control that the routine inside the do{...} it's always executed at least once.

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                jhonnygolpe
                                wrote on last edited by
                                #16

                                Nevertheless I must review all my code.... It's been working for a time... But lately it freezes again

                                1 Reply Last reply
                                0
                                • mfalkviddM Offline
                                  mfalkviddM Offline
                                  mfalkvidd
                                  Mod
                                  wrote on last edited by
                                  #17

                                  Oh. Sorry. I wasn't aware of the do-while construct. Thanks for teaching me.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  9

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  Posts


                                  Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • MySensors
                                  • OpenHardware.io
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular