EEPROM nanv

Hello All,
So I’ve a project here that has been going pretty well using this board Adafruit Pro Trinket - 3V 12MHz : ID 2010 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits

I’ve received a couple of new boards today http://www.ebay.com/itm/200914924969

The only thing that’s not working properly is the EEPROM read and write. Now I don’t have a datasheet on the new boards yet, but when I should be seeing the setting stored and retrieved from memory I instead see " nanv ". All of my buttons are working, everything else is working.

any ideas??

Thank You, John

int usrWattMemoryAddr = 0; 

float userWatts = EEPROM_readDouble(usrWattMemoryAddr);

void setup(){
...
}


void loop(){
userWatts = EEPROM_readDouble(usrWattMemoryAddr);
if(!isdigit(userWatts)){userWatts = 40;}

}

// ************************************************
// Write floating point values to EEPROM
// ************************************************
void EEPROM_writeDouble(int address, double value)
{
   byte* p = (byte*)(void*)&value;
   for (int i = 0; i < sizeof(value); i++)
   {
      //EEPROM.write(address++, *p++);
      EEPROM.update(address++, *p++);
   }
}
 
// ************************************************
// Read floating point values from EEPROM
// ************************************************
double EEPROM_readDouble(int address)
{
   double value = 0.0;
   byte* p = (byte*)(void*)&value;
   for (int i = 0; i < sizeof(value); i++)
   {
      *p++ = EEPROM.read(address++);
   }
   return value;
}
if(!isdigit(userWatts)){userWatts = 40;}

isdigit is used with ascii values to test that they are in the range '0' to '9'.

I think maybe you wanted isnan to test that the value isn't not-a-number.

if(isnan(userWatts)){userWatts = 40;}

Thanks for that. isdigit/isnan. both seem to work and gets me past the initial nanv so I see the 40 on my oled but it's not being stored in memory. If I remove that statement and restart it's nanv again. It's like I'm not writing and reading from eeprom.

I've just run this code https://www.arduino.cc/en/Tutorial/EEPROMRead and I get serial printing from 0 to 255. So it seems then like there is eeprom on the board and it's functioning. So why does code that works on one mini not work the same on another mini?

so it's not a problem with the eeprom itself as I can eeprom.write and eeprom.read just fine. it has to do with storing a float using this double read double write. trouble is I really don't understand what's going on with these functions to be able to fix it. I'll keep searching, if you'd like to give me the solution I'd sure appreciate it. =0)

Thank you, John

ok. I've decided that since the largest number I'd like to store is less than the max possible in a single memory sector and my number is like 30, 40.3 or 60.7 that I can simply num * 10 then write. Afterwards I can read num and / 10. Solved. There's something else going on now though. Ahhh it's always something...

.. well I'm done for the day. Thanks for listening.

John

Always better to do that anyway. Floats have accuracy problems. ints do not.