Project 13 - Temperature, Humidity and Light Data Logger

<< Click to Display Table of Contents >>

Navigation:  Projects >

Project 13 - Temperature, Humidity and Light Data Logger

This project shows how to implement the three-channel data logger using the CleO primitives. Three devices are utilized for this project. It is using the HDC1080 library to interact with the HDC1080 component.

 

 

Component(s)

 

This project uses the following component(s) -

 

HDC1080

CleO Light Sensor

 

 

Wiring Diagram

 

 

Project 13-Temperature,humidty, Light Data Logger

 

 

 

Code

 

The samples[3][32] array is used to store the samples. The Setup() routine begins with initializing CleO. Here is the sample code snippet -

 

int nsamples;

static float samples[3][32] = {0.0};

static uint32_t colors[3] = {DEEP_SKY_BLUE, GOLD, WHITE};

char text[][20] = {"Light Sensitivity", "Humidity", "Temperature"};

static float temperature = 0.0;

static float humidity = 0.0;

bool hdc1080_detected = true;

ClosedCube_HDC1080 hdc1080;

void setup()

{

 /* Initialize CleO */

 CleO.begin();

 

 /* Initialize HDC1080 */

 hdc1080.begin(HDC1080_ADDR);

}

 

Inside the loop() routine, the samples are collected from each device and then prepares screen frame between the CleO.Start() and CleO.Show() routines.

 

For each channel, it draws a rectangle, calculates minimum/maximum values and selects a different color. It also gets the latest collected samples (nsamples) and draws the line for it. Using the last reading, it displays this value using the StringExt() command. Here is the sample code snippet -

 

void loop() {

/* Stores all recording samples collected from 3 channels in an array Latest samples will be stored at highest index in an array  */

 CollectTemperatureHumidity();

 addsamples(CollectFromPR1(), humidity, temperature);

 

/* Start drawing the screen shot */

 CleO.Start();

 

 float mn, mx, scale;

 CleO.LineWidth(2);

  float channel_display_width = 740;

  float channel_display_height = 120;

 

/* For each channel */

 for (int chan = 0; chan < 3; chan++) {

   int ybase = 150 + 150 * chan;

 

  /* Draw a rectangle section in which reading will be drawn */

   CleO.RectangleExt(0, ybase, channel_display_width, channel_display_height, 0x303030, BL, 0, 0);

   CleO.StringExt(FONT_SANS_2, channel_display_width, ybase - channel_display_height, colors[chan], TR, 0, 0, text[chan]);

 

   if (hdc1080_detected == false)

     CleO.StringExt(FONT_SANS_2, 0, 480, RED, BL, 0, 0, "No HDC1080 Detected");

 

   mn = mx = samples[chan][31];

   float *s = samples[chan];

 

  /* From all samples in a channel, get min and max */

   for (int i = (32 - nsamples); i < 32; i++) {

     mn = min(mn, s[i]);

     mx = max(mx, s[i]);

   }

 

  /* Get the scaling value */

   if (mx != mn)

     scale = 90 / (mx - mn);

   else

     scale = 0;

 

  /* Select different color for each channel */

   CleO.LineColor(colors[chan]);

 

  /* Connect all samples for a channel with a line */

   for (int i = (32 - nsamples); i < 31; i++) {

     float x0 = i * (channel_display_width / 31);

     float x1 = (i + 1) * (channel_display_width / 31);

     float y0 = ybase - scale * (s[i] - mn);

     float y1 = ybase - scale * (s[i + 1] - mn);

     CleO.Line(x0, y0, x1, y1);

   }

 

  /* Get the y coordinate for the last sample and use it for drawing reading as text */

   char val[9];

   sprintf(val, "%d", int(s[31]));

   float y = ybase - scale * (s[31] - mn);

   CleO.StringExt(FONT_SANS_3, channel_display_width + 8, y, colors[chan], BL, 0, 0, val);

 }

 

 /* Show the screenshot */

 CleO.Show();

 delay(400);

}

 

The following sample code snippet shows the routine used for HDC1080 reading temperature and humidity -

 

void CollectTemperatureHumidity() {

/* Collect temperature and humidity */

 int ManufacturerId = hdc1080.readManufacturerId();

 int DeviceId = hdc1080.readDeviceId();

 temperature = hdc1080.readTemperature();

 humidity= hdc1080.readHumidity();

 

 hdc1080_detected = true;

 

 if (!(ManufacturerId == MANUFACTURER_ID && DeviceId == DEVICE_ID)) {

   hdc1080_detected = false;

   temperature = 0.0;

   humidity = 0.0;

 }

}

 

 

Note: If no hardware is detected, then an appropriate error message is displayed.

 

 

Output

 

 

Project13-TemperatureHumidityAndLightDatalogger