Pages: [1]   Go Down
Author Topic: Is there a way to save data inputed into Arduino?  (Read 6406 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a barometer hooked up and running. The issue I am having is that every time you turn it on or hit reset you need to recalibrate it. Is there any way to save data onto the board so that after reset or turn on it runs up the program and then grabs the saved data as well?

I'm using the Duemilanove board and the data I need to save is in the form of a double.

Any help would be appreciated, it's for a class project.

Thanks.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


EEPROM...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234477290/3#3

« Last Edit: January 23, 2011, 10:31:26 pm by bcook » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks. I'll go through all that code and see if I can figure it out. It looks really complicated. lol
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there any way to get some comments? Or explanation on what's going on? I thought I had it but can not figure it out.

Code:

#include <EEPROM.h>

template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        *p++ = EEPROM.read(ee++);
    return i;
}
 

Code:
// include the above EEPROM functions

struct st_t { long lo; byte by; double db; };

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

    int n = 0;

    byte by = 0x33;
    Serial.println(by, HEX);
    n = EEPROM_writeAnything(0, by);
    Serial.print("Wrote bytes: ");
    Serial.println(n);
    by = 0xFF;
    Serial.println(by, HEX);
    n = EEPROM_readAnything(0, by);
    Serial.print("Read bytes: ");
    Serial.println(n);
    Serial.println(by, HEX);

    Serial.println("-------");

    long lo = 0xDEADBEEF;
    Serial.println(lo);
    n = EEPROM_writeAnything(23, lo);
    Serial.print("Wrote bytes: ");
    Serial.println(n);
    lo = 0xFFFFFFFF;
    Serial.println(lo);
    n = EEPROM_readAnything(23, lo);
    Serial.print("Read bytes: ");
    Serial.println(n);
    Serial.println(lo);

    Serial.println("-------");

    double pi = 3.1415926538;

    struct st_t st;
    st.lo = 0xABADF00D;
    st.by = 0x22;
    st.db = pi;
    Serial.println(st.lo);
    Serial.println(st.by, HEX);
    Serial.println(st.db == pi);
    n = EEPROM_writeAnything(221, st);
    Serial.print("Wrote bytes: ");
    Serial.println(n);
    st.lo = 0xFFFFFFFF;
    st.by = 0x11;
    st.db = 0.0;
    Serial.println(st.lo);
    Serial.println(st.by, HEX);
    Serial.println(st.db == pi);
    n = EEPROM_readAnything(221, st);
    Serial.print("Read bytes: ");
    Serial.println(n);
    Serial.println(st.lo);
    Serial.println(st.by, HEX);
    Serial.println(st.db == pi);
}

void loop()
{
}

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 178
Posts: 12288
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Which parts are confusing?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks so much!! I'm still not sure what's going on there in the code, but I have it working in my code! Thanks so much for that. Now I just need to understand that code. lol
Logged

Pages: [1]   Go Up
Jump to: