Development

» Ag xtr 15: GMX240 sensor reading

Basic example that turns on, reads and turn off the sensor. Measured parameters are stored in the corresponding class variables and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme
- 1 GMX240 sensor

Notes

- This example is only valid for Waspmote v15

Code

/*
    ----------- [Ag_xtr_15] - GMX240 sensor reading --------------------

    Explanation: Basic example that turns on, reads and turn off the
    sensor. Measured parameters are stored in the corresponding class
    variables and printed by the serial monitor.

    Measured parameters:
      - Node letter
      - Wind direction
      - Average wind direction
      - Corrected wind direction
      - Average corrected wind direction
      - Average wind gust direction
      - Wind speed
      - Average wind speed
      - Average wind gust speed
      - Wind sensor status
      - Precipitation total
      - Precipitation intensity
      - Precipitation status
      - Compass
      - X tilt
      - Y tilt
      - Z orient
      - Timestamp
      - Supply voltage
      - General status


    Copyright (C) 2018 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:           3.0
    Design:            David Gascón
    Implementation:    J.Siscart, V.Boria
*/

#include <WaspSensorAgrXtr.h>

/*
  SELECT THE RIGHT SOCKET FOR EACH SENSOR.

  Possible sockets for this sensor are:
  - AGR_XTR_SOCKET_E       _________
                          |---------|
                          | A  B  C |
                          |_D__E__F_|


  Example: a 5TM sensor on socket A will be
  [Sensor Class] [Sensor Name] [Selected socket]
  Decagon_5TM    mySensor      (AGR_XTR_SOCKET_A);

  Refer to the technical guide for information about possible combinations.
  www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
*/

//   [Sensor Class] [Sensor Name]
weatherStation mySensor;

uint8_t response = 0;

void setup()
{
  USB.println(F("GMX240 example"));

  // 1. Turn ON the sensor
  mySensor.ON();
}

void loop()
{

  // 2. Read the sensor
  response = mySensor.read();
  
  if (response == 1)
  {
    // 4. Print information
    USB.println(F("---------------------------"));
    USB.print(F("Node letter: \t\t"));
    USB.println(mySensor.gmx240.node_letter);

    USB.print(F("Wind direction: \t"));
    USB.print(mySensor.gmx240.wind_direction);
    USB.println(F(" degrees"));

    USB.print(F("Avg. wind dir:\t\t"));
    USB.print(mySensor.gmx240.average_wind_direction);
    USB.println(F(" degrees"));

    USB.print(F("Cor. wind dir:\t\t"));
    USB.print(mySensor.gmx240.corrected_wind_direction);
    USB.println(F(" degrees"));

    USB.print(F("Avg. cor. wind dir:\t"));
    USB.print(mySensor.gmx240.average_corrected_wind_direction);
    USB.println(F(" degrees"));

    USB.print(F("Avg. wind gust dir:\t"));
    USB.print(mySensor.gmx240.average_wind_gust_direction);
    USB.println(F(" degrees"));


    USB.print(F("Wind speed:\t\t"));
    USB.print(mySensor.gmx240.wind_speed);
    USB.println(F(" m/s"));

    USB.print(F("Avg. wind speed:\t"));
    USB.print(mySensor.gmx240.average_wind_speed);
    USB.println(F(" m/s"));

    USB.print(F("Avg. wind gust speed:\t"));
    USB.print(mySensor.gmx240.average_wind_gust_speed);
    USB.println(F(" m/s"));

    USB.print(F("Wind sensor status: \t"));
    USB.println(mySensor.gmx240.wind_sensor_status);


    USB.print(F("Precip. total:\t\t"));
    USB.print(mySensor.gmx240.precipitation_total);
    USB.println(F(" mm"));

    USB.print(F("Precip. int:\t\t"));
    USB.print(mySensor.gmx240.precipitation_intensity);
    USB.println(F(" mm"));

    USB.print(F("Precip. status:\t\t"));
    USB.println(mySensor.gmx240.precipitation_status);

    USB.print(F("Compass:\t\t"));
    USB.println(mySensor.gmx240.compass);


    USB.print(F("X tilt:\t\t\t"));
    USB.println(mySensor.gmx240.x_tilt);

    USB.print(F("Y tilt:\t\t\t"));
    USB.println(mySensor.gmx240.y_tilt);

    USB.print(F("Z orient:\t\t"));
    USB.println(mySensor.gmx240.z_orient);

    USB.print(F("Timestamp: \t\t"));
    USB.println(mySensor.gmx240.timestamp);

    USB.print(F("Voltage: \t\t"));
    USB.print(mySensor.gmx240.supply_voltage);
    USB.println(F(" V"));

    USB.print(F("Status: \t\t"));
    USB.println(mySensor.gmx240.status);
    USB.println(F("---------------------------\n"));
  }

  delay(5000);

}

Output

H#
GMX240 example
---------------------------
Node letter: Q
Wind direction: 61 degrees
Avg. wind dir: 0 degrees
Cor. wind dir: 208 degrees
Avg. cor. wind dir: 0 degrees
Avg. wind gust dir: 0 degrees
Wind speed: 000.02 m/s
Avg. wind speed: 000.00 m/s
Avg. wind gust speed: 000.00 m/s
Wind sensor status: 0100
Precip. total: 00000.000 mm
Precip. int: 000.000 mm
Precip. status: N
Compass: 147
X tilt: +00
Y tilt: +02
Z orient: -1
Timestamp: 2015-01-27T05:59:45.5
Voltage: 11.8 V
Status: 0000
---------------------------

Quick Publish: