Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» SC 10: Reading DS18B20 Temperature

In this example the Smart Cities sensor board is turned on and configured to read the temperature sensor on it once every second.

Required Materials

1 x Waspmote
1 x Battery
1 x Smart Cities board
1 x DS18B20

Notes

* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Smart Cities technical guide.
* This example can only be executed in Waspmote v12

Code

/*  
 *  --[SC_10] - Reading DS18B20 Temperature at Smart Cities board-- 
 *  
 *  Explanation: Turn on the Smart Cities board and read the 
 *  temperature sensor on it once every second.
 *  
 *  Copyright (C) 2015 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.1 
 *  Design:            David Gascón 
 *  Implementation:    Luis Miguel Marti
 */

#include <WaspSensorCities.h>
#include <WaspFrame.h>

float digitalTemperature; 
char node_ID[] = "Node_01";


void setup() 
{
  USB.ON();
  USB.println(F("Temperature example"));
  SensorCities.ON();
  // Set the Waspmote ID
  frame.setID(node_ID); 
}
 
void loop()
{
  ///////////////////////////////////////////
  // 1. Turn on the sensors
  /////////////////////////////////////////// 

  // Power on the temperature sensor
  SensorCities.setSensorMode(SENS_ON, SENS_CITIES_TEMP_DS18B20);
  delay(100);
  
  
  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////  

  // Read the temperature sensor
  digitalTemperature = SensorCities.readValue(SENS_CITIES_TEMP_DS18B20);
  
  
  ///////////////////////////////////////////
  // 3. Turn off the sensors
  /////////////////////////////////////////// 

  // Power off the temperature sensor
  SensorCities.setSensorMode(SENS_OFF, SENS_CITIES_TEMP_DS18B20);
  
  
  ///////////////////////////////////////////
  // 4. Create ASCII frame
  /////////////////////////////////////////// 

  // Create new frame (ASCII)
  frame.createFrame(ASCII);

  // Add temperature
  frame.addSensor(SENSOR_TCB, digitalTemperature);

  // Show the frame
  frame.showFrame();

  //wait 1 seconds
  delay(1000);
}

Output

E#
Temperature example
===============================
Current ASCII Frame:
Length: 36
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F30312339235443423A32342E383123
frame (STR): <=>€#400568635#Node_01#9#TCB:24.81#
===============================
===============================
Current ASCII Frame:
Length: 37
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F3031233130235443423A32352E333823
frame (STR): <=>€#400568635#Node_01#10#TCB:25.38#
===============================
===============================
Current ASCII Frame:
Length: 37
Frame Type: 128
frame (HEX): 3C3D3E800123343030353638363335234E6F64655F3031233131235443423A32352E383823
frame (STR): <=>€#400568635#Node_01#11#TCB:25.88#
===============================

Quick Publish: