database

Dear all,

for my project I want to create a simple database, as I do not have a lot of time I hoped I could get some help. What I want is to create certain timeslots, say 10 of 10 seconds each. In each timeslot I want to save 4 variables, they all have either 2 or 3 different possibilities, which I get from sensors and from other arduinos through xbee. I want one cycle of recording and my system reacting on that, then save that to the database, after that I want to keep playing my sketch with the saved variables until a reset button is pressed for example.

I have an sd module available and could also use a pc if necessary, but I would prefer to keep it on the arduino. Could I use the following library and if so, is there some kind of manual, or could someone help me get started?

Im sorry if I am not clear enough, but thanks for helping me!

kind regards,

Tim

Hi Tim

In each timeslot I want to save 4 variables, they all have either 2 or 3 different possibilities

Can you say what type of variables, and give some examples of what the possibilities are?

I want one cycle of recording and my system reacting on that, then save that to the database

Can you clarify? One cycle of 10 sampling periods, 4 data items per period? So one cycle generates 40 data items?

And the code that does the "reacting" i.e. processes this data, is that going to run on the Arduino?

after that I want to keep playing my sketch with the saved variables until a reset button is pressed for example.

So, after resetting the Arduino or powering it off and back on, you forget the old data and start collecting new data, i.e. start another cycle of 10 sampling periods?

Could I use the following library

I couldn't see any attachment. Did you mean to include a link or file with your post?

All the best

Ray

sorry for being so unclear. At this point this will be the idea: 4 cycles, in each cycle I measure 4 variables, two of which have two possibilities, so I could make them booleans if that is easier, the other two have three possibilities. If I could store it like: at time slot one a=1 b=2 c=1 d=4, and that for four other timeslots that would be best. What is also possible is to say at timeslot one save the numbers 1,3,5 and 6, and I will know what it means.

Since it is for a demo I do not need to save anything for a longer ammount of time, so all the data can be deleted when reset. I dont know if I would actually need a database, if I could somehow measure for one loop and then just have those values until reset that is good enough. It will all run on arduino, two of the values are sent and received through xbee.

the link I meant to include is Arduino Playground - DatabaseLibrary

Thank you very much for replying

OK, Tim. That helps a lot.

I don't think you need a database at all, as you say. Hold the items in arrays. Your code would do the data collection in each of the four cycles, putting the data into the arrays. You could put this loop in the "void setup()" part of your Arduino program, after doing all the initialisation that you need. That way, the loop of 4 cycles is done once.

Then, in the "void loop()" part of your program, you do what ever you want with the data. I'm assuming that you want to do something over and over again with the same data until reset. You've not gone into detail on that yet, which is fine, so can't say exactly what needs doing there.

About the arrays. Sounds like you have some integer data and some boolean data.

One way to do this would be to set up arrays like this - I'm inventing the names and data types just for example. There would be lots of other code in here, obviously, hence all the "...".

const byte numberOfCycles = 4;  // Makes it easier to change the number of cycles in future
int temperatureReading[numberOfCycles] = {0}; // Array of integers, one item for each cycle, initialised to 0
int pressureReading[numberOfCycles] = {0}; // Same again for the next data item
boolean isLightOn[numberOfCycles] = {false}; // Same again for a boolean data item
...

void setup()
{
   ...
    for (byte i = 0; i < numberOfCycles; i++)  // The 4 array elements are numbered 0 to 3
    {
        ...
        // example of how you might put the data in the arrays
        temperatureReading[i] = yourFunctionThatReadsTemperature();
        pressureReading[i] = yourFunctionThatReadsPressure();
        isLightOn[i] = yourFunctionToCheckTheLight();
        ...
    }
    ...
}

void loop()
{
...
// Do something with the data in the arrays
...
}

Hope this helps.

Ray

Hi Ray,

thanks a lot for the effort, I think I will be able to make something with this.

Tim