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. General Discussion
  3. Eeprom usage

Eeprom usage

Scheduled Pinned Locked Moved General Discussion
7 Posts 5 Posters 6.4k Views 6 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.
  • P Offline
    P Offline
    pawel
    wrote on last edited by
    #1

    Hi.
    How mySensors usage eeprom memory?
    How many bytes and with addresses?
    I would like use eeprom memory to own application but I don't know with address will be free.

    Thx.
    Pawel

    1 Reply Last reply
    0
    • hekH Online
      hekH Online
      hek
      Admin
      wrote on last edited by
      #2

      You'll find the addresses used here:
      https://github.com/mysensors/Arduino/blob/master/libraries/MySensors/MySensor.h#L44

      If you only need 256 bytes you can use the library functions saveState()/loadState() which makes sure you won't mess up anything.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        marcusvdt
        wrote on last edited by
        #3

        @hek I have a quick question regarding the gw.saveState and consequently the gw.loadState instructions
        As per the link and code you have mentioned, reproduced below:

        // EEPROM start address for mysensors library data
        #define EEPROM_START 0
        // EEPROM location of node id
        #define EEPROM_NODE_ID_ADDRESS EEPROM_START
        // EEPROM location of parent id
        #define EEPROM_PARENT_NODE_ID_ADDRESS (EEPROM_START+1)
        // EEPROM location of distance to gateway
        #define EEPROM_DISTANCE_ADDRESS (EEPROM_PARENT_NODE_ID_ADDRESS+1)
        #define EEPROM_ROUTES_ADDRESS (EEPROM_DISTANCE_ADDRESS+1) // Where to start storing routing information in EEPROM. Will allocate 256 bytes.
        #define EEPROM_CONTROLLER_CONFIG_ADDRESS (EEPROM_ROUTES_ADDRESS+256) // Location of controller sent configuration (we allow one payload of config data from controller)
        #define EEPROM_FIRMWARE_TYPE_ADDRESS (EEPROM_CONTROLLER_CONFIG_ADDRESS+24)
        #define EEPROM_FIRMWARE_VERSION_ADDRESS (EEPROM_FIRMWARE_TYPE_ADDRESS+2)
        #define EEPROM_FIRMWARE_BLOCKS_ADDRESS (EEPROM_FIRMWARE_VERSION_ADDRESS+2)
        #define EEPROM_FIRMWARE_CRC_ADDRESS (EEPROM_FIRMWARE_BLOCKS_ADDRESS+2)
        #define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_FIRMWARE_CRC_ADDRESS+2) // First free address for sketch static configuration
        

        I understand it translates to:

        ADDRESS	SIZE		ALIAS
        0X000	1 BYTE		EEPROM_START, EEPROM_NODE_ID_ADDRESS
        0X001	1 BYTE		EEPROM_PARENT_NODE_ID_ADDRESS
        0X002	1 BYTE		EEPROM_DISTANCE_ADDRESS
        0X003	256 BYTES		EEPROM_ROUTES_ADDRESS
        0X103	24 BYTES	EEPROM_CONTROLLER_CONFIG_ADDRESS
        0X11B	2 BYTES		EEPROM_FIRMWARE_TYPE_ADDRESS
        0X11D	2 BYTES		EEPROM_FIRMWARE_VERSION_ADDRESS
        0X11F	2 BYTES		EEPROM_FIRMWARE_BLOCKS_ADDRESS
        0X121	2 BYTES		EEPROM_FIRMWARE_CRC_ADDRESS
        0X123	???			EEPROM_LOCAL_CONFIG_ADDRESS
        

        So it means when I perform these instructions:
        lightStatus = state;
        gw.saveState(0,state);

        In what specific address am I saving the data? The instruction itself says position zero, so am I saving to the first address 0x123 in this case???

        Thanks in advance.

        1 Reply Last reply
        0
        • hekH Online
          hekH Online
          hek
          Admin
          wrote on last edited by
          #4

          0x123

          Yes, that sounds about right.

          1 Reply Last reply
          0
          • bisschopsrB Offline
            bisschopsrB Offline
            bisschopsr
            wrote on last edited by
            #5

            Sound good! How can I write/read values over 255 to the EEPROM. This takes more then one byte.
            If I write 255, I get: 255 0 (place 0 place 1)
            256 will give: 0 255
            257 will give: 1 255
            etc.

            Reading only reads the byte indicated with the function loadState()

            Thanks in advance

            Ralph

            Domoticz, P1 meter interface, MySensors and more to come!

            fetsF 1 Reply Last reply
            0
            • bisschopsrB bisschopsr

              Sound good! How can I write/read values over 255 to the EEPROM. This takes more then one byte.
              If I write 255, I get: 255 0 (place 0 place 1)
              256 will give: 0 255
              257 will give: 1 255
              etc.

              Reading only reads the byte indicated with the function loadState()

              Thanks in advance

              Ralph

              fetsF Offline
              fetsF Offline
              fets
              wrote on last edited by
              #6

              @bisschopsr I think you can use hw_writeConfigBlock/hw_readConfigBlock with the "right" address

              1 Reply Last reply
              0
              • bisschopsrB Offline
                bisschopsrB Offline
                bisschopsr
                wrote on last edited by bisschopsr
                #7

                Hi All,

                Resolved this with a simple funtion splitting the value in byte long parts. Bit shifting and OR are a perfect fit for this :-).

                The code:

                void storeEeprom(int pos, int value) {
                	// function for saving the values to the internal EEPROM
                	// value = the value to be stored (as int)
                	// pos = the first byte position to store the value in
                	// only two bytes can be stored with this function (max 32.767)
                	gw.saveState(pos, ((unsigned int)value >> 8 ));
                	pos++;
                	gw.saveState(pos, (value & 0xff));
                }
                
                int readEeprom(int pos) {
                	// function for reading the values from the internal EEPROM
                	// pos = the first byte position to read the value from 
                
                	int hiByte;
                	int loByte;
                
                	hiByte = gw.loadState(pos) << 8;
                	pos++;
                	loByte = gw.loadState(pos);
                	return (hiByte | loByte);
                }
                

                Domoticz, P1 meter interface, MySensors and more to come!

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


                28

                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