• Home
  • Arno - Learn Arduino!
    • Arno Sketches
    • Arno Shield
    • Arno Add-Ons >
      • Arno Motion
      • Arno DigitalRGB
  • LeOlympia
    • LeOlympia Instructions
  • Order
  • SODA Datalogger
    • SODA Tutorials >
      • About the HE 1.0
      • HE 1.0: Getting Started
      • HE 1.0: Power Management
      • HE 1.0: Simple datalogging
      • HE 1.0: communicate() Method
      • HE 1.0: High Resolution ADC
      • HE Tutorial: Thermocouples
      • HE Tutorial: Multiple Temperature Sensors on a Bus
    • SODA Library
    • SODA Datalogger Applications
  • Projects
  • Contact
  • Forum
  • SMD Reflow
  • Blog

Simple Datalogging with the HE 1.0

Some of the features of the SODA library are explained here. Let's start with a simple program for datalogging:

#include <EEPROM.h>
#include "SODA.h"
#include <SdFat.h>
#include <Wire.h>
SODA soda;

void setup(){
  soda.begin();
}

void loop(){
  soda.communicate();
  float t = soda.getClockTemp();
  int a1 = analogRead(A1);
  soda.dataLineBegin();
  soda.dataLineAdd(t);
  soda.dataLineAdd(A1);
  soda.dataLineEnd();
  soda.setWake(10,1);
  soda.turnOff();
}

We let this run for a bit and then download the data:

100237,2014-05-27 18:55:06,22.00,19
100237,2014-05-27 18:55:10,22.75,19
100237,2014-05-27 18:55:20,22.75,19
100237,2014-05-27 18:55:30,23.00,19


Let's look at the parts of the program. All SODA programs need to start with statements to include the SODA, EEPROM, Wire, and SDFat libraries (EEPROM and Wire are standard Arduino libraries; you need to install SODA and sdFat).

#include <EEPROM.h>
#include "SODA.h"
#include <SdFat.h>
#include <Wire.h>


We next declare an instance of the SODA class.  It's called soda in our program.

SODA soda;

In the loop() block, we initialize the instance of SODA.  This prepares the SD card and sets some other internals.

void setup(){
  soda.begin();
}

At to beginning of the loop() block there's a call to soda.communicate().  This line is used to put the SODA into communication mode if a computer, tablet, or phone is connected via USB.  Regular datalogging stops while the SODA is in communication mode. 

void loop(){
  soda.communicate();



Many programs will include the lines above.  The next part gets into the specifics of the datalogging mission. In this case we read the temperature from the real-time clock and the analog value from A1:

float t = soda.getClockTemp();
 int a1 = analogRead(A1);



The next lines create a line of data that is saved to the SD card. A line should begin with:

soda.dataLineBegin();

This starts a line of data and records the LOGGERID and the time.  Let's look back at the downloaded data:

100237,2014-05-27 18:55:06,22.00,19


The next lines add the temperature and ADC reading:

  soda.dataLineAdd(t);
  soda.dataLineAdd(A1);


The next line ends data writing and closes the file on the SD card:

  soda.dataLineEnd();

The last two lines control when the SODA will wake next and the puts it to sleep.  The .setWake method has two arguments: the number of units to sleep and the type of units (1 = seconds, 2 = minutes, 3 = hours).  So the line set the alarm for 10 seconds:

  soda.setWake(10,1);

Finally, the SODA turns its self off:

  soda.turnOff();

The SODA will wake when in the next whole increment of the arguments of setWake.  In this example when the seconds part of the time equal 0, 10, 20, 30, 40, or 50.  When the board wakes up it starts the program again from the beginning.  This generates the output we saw above.  Note that the first reading in the line of data will occur right when the program starts.  After that, measurements will occur at consistent intervals.

100237,2014-05-27 18:55:06,22.00,19
100237,2014-05-27 18:55:10,22.75,19
100237,2014-05-27 18:55:20,22.75,19
100237,2014-05-27 18:55:30,23.00,19