while compiling program i am getting error in Arduino PlAYGROUND

I am compiling a program in Arduino Playground Arduino 1.0.5, program is given below

#include <EEPROM.h>

#include <avr/eeprom.h>

const int buflen = 32;

struct __eeprom_data {
int first;
int second;
boolean third;
char fourth[buflen];

};

void setup()
{
Serial.begin(57600);

int q = 132;
eeprom_write(q, first);
eeprom_write(5958, second);
eeprom_write(false, third);
eeprom_write("Hello from EEPROM!", fourth);


int a, b;
boolean c;
char d[buflen];


eeprom_read(a, first);
eeprom_read(b, second);
eeprom_read(c, third);
eeprom_read(d, fourth);


Serial.println(a);
Serial.println(b);
Serial.println(c ? "TRUE" : "FALSE");
Serial.println(d);


eeprom_write("This is a buffer overflow", third);

eeprom_write('X', fourth[3]);
eeprom_read(d, fourth);
char x;
eeprom_read(x, fourth[3]);
Serial.println(d);
Serial.println(x);
}
void loop() { }

Its a program to read and write some data to EEPROM of Arduino .Earlier when some macros were define, it was giving error that # aren’t followed by macros.While compiling i get the following error.

EEPROMADVANCE.ino: In function ‘void setup()’:
EEPROMADVANCE:20: error: ‘first’ was not declared in this scope
EEPROMADVANCE:20: error: ‘eeprom_write’ was not declared in this scope
EEPROMADVANCE:21: error: ‘second’ was not declared in this scope
EEPROMADVANCE:22: error: ‘third’ was not declared in this scope
EEPROMADVANCE:23: error: ‘fourth’ was not declared in this scope
EEPROMADVANCE:31: error: ‘eeprom_read’ was not declared in this scope

I am unable to understand what i am lacking.I had already used the required EEPROM library.

Ok i got the first error, first of all avr/eeprom.h did not contain any eeprom_write function and thats why i was getting error of eeprom_write is not defined in this scope and secondly , no struct type variable was described in the code with the help of which i can use struct member variables.

srj0408: Ok i got the first error, first of all avr/eeprom.h did not contain any eeprom_write function and thats why i was getting error of eeprom_write is not defined in this scope and secondly , no struct type variable was described in the code with the help of which i can use struct member variables.

So, do you still have a problem?

I had changed that code and now i will try with avr/eeprom library function eeprom_write_block, and eeprom_read_block

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <avr/eeprom.h>

struct settings_t
{
  char new[]="9c304900-212a-11e3-8224-0800200c9a66";
} settings;

void setup()
{
  //eeprom_read_block((void*)&settings.new, (void*)0, sizeof(settings));
     lcd.begin(16, 2);
 // ...
}
void loop()
{
    // let the user adjust their alarm settings
    // let the user adjust their mode settings
    // ...

    // if they push the "Save" button, save their configuration
    if (digitalRead(13) == HIGH)
      eeprom_write_block((const void*)&settings.new, (void*)0, sizeof(settings));
}

similarly i had written a read sketch,

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#include <avr/eeprom.h>

char *new ;
void setup()
{      
       Serial.begin(9600);
       lcd.begin(16, 2);
}
void loop()
{
      eeprom_read_block(new, (void*)0, sizeof(settings));
      lcd.write(new);
      Serial.println(new);
      //eeprom_write_block((const void*)&settings.new, (void*)0, sizeof(settings));
}

I will test it once and display it on LCD and serial.Will update soon on this.

Using names of keywords, like new, as names of variables is a bad idea.

struct settings_t
{
  char new[]="9c304900-212a-11e3-8224-0800200c9a66";
} settings;

There is no reason to wrap a single variable in a struct.

This time i changed the name of the variable and used structure with two char variables.Though i am not that much good in C++, but i tried .I initialized the structure and then a structure type settings.But when i compile the following code in Arduino i get the following error

#include <avr/eeprom.h>

struct settings_t
{
  char UUID ;
  char serialid;
} settings;

void setup()
{
 
}
void loop()
{    settings.UUID = "9c304900-212a-11e3-8224-0800200c9a66";
     settings.serialid = "ID_1.07;
     eeprom_write_block((const void*)&settings, (void*)0, sizeof(settings));
}

i think using &settings in the functin eeprom_write_block pass the values assigned by me.But i am getting following error

anonmous:15: error: missing terminating " character
anonmous.ino: In function ‘void loop()’:
anonmous:14: error: invalid conversion from ‘const char*’ to ‘char’
anonmous:22: error: void value not ignored as it ought to be

I had one more question, arduino compiler didn’t bother about language.Means if we do have one sketch in C++ and one in C, the C sketch can always use C++ sketch.I tried earlier to use a sketch in another sketch by simply saving a sketch with .h extension and then including that sketch in the other sketch in between “”.What i want to do , is to write UUID and serial ID in EEPROM and the with other sketch , i want to read that and use in another sketch.

 "ID_1.07;

anonmous:15: error: missing terminating " character

Doesn't get much clearer than that.

settings.UUID = "9c304900-212a-11e3-8224-0800200c9a66";anonmous:14: error: invalid conversion from 'const char*' to 'char'

Or that.

"9c304900-212a-11e3-8224-0800200c9a66" is not a character. You can't store that in a char variable.

     settings.serialid = "ID_1.07;

Missing a close quote.

ok that both have been taken care of , now i had edited the code and now its being compiled.I have to just test it with real hardware.here is the code.
Can some one send me link for simulator of Arduino.Though i have some, but one which atleast reduce the usage of real hardware.

#include <avr/eeprom.h>

struct settings_t
{
  char UUID[37] ;
  char serialid[8];
};

void setup()
{
 
}
void loop()

{   
     char UUID[37] = "9c304900-212a-11e3-8224-0800200c9a66";
     char serialid[8] = "ID_1.07";
     char readUUID[37];
     char readserialid[8]; 
    
      eeprom_write_block((const void*)&UUID, (void*)0, sizeof(UUID));
            eeprom_write_block((const void*)&serialid, (void*)100, sizeof(serialid));
              eeprom_read_block(( void*)&readUUID, (void*)0, sizeof(UUID));
                        eeprom_read_block(( void*)&readserialid, (void*)100, sizeof(readserialid));


}

So, the struct isn't being used. Why is it still there?

What's up with the weird indenting? Is that supposed to mean something?

How will you know if you read what you wrote? How long will you let that code run, uselessly wearing out your EEPROM?

srj0408: ok that both have been taken care of , now i had edited the code and now its being compiled.I have to just test it with real hardware.here is the code. Can some one send me link for simulator of Arduino.Though i have some, but one which atleast reduce the usage of real hardware.

I always test on real hardware personally. Why do you want to reduce the usage of it? Simulators rarely behave the same as real hardware anyway.

PaulS is right. That code will wear out your EEPROM in a few minutes. I suggest only writing to it if something changes. Or in the case of your code, once, in setup.