Development

Mote Runner:

Sensor Boards / Gases

This is the development section of the Waspmote Mote Runner platform. You can navigate through the examples with the left bar.

If you actually want to see examples about the original Waspmote platform, please go its specific development section.

» MR-Ga 02: Socket 2A Reading

In this example the Gases 2.0 board and socket 2A are turned on, waiting for the minimum heating time and then reading the sensor every second while printing the output voltage and sensor resistance through the USB.

Required Materials

1 x Waspmote
1 x Battery
1 x Gases 2.0 board
1 x Socket 2A valid sensor:
- TGS2600
- TGS2602
- TGS2610
- TGS2611
- TGS2620

Notes

* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Gases technical guide.
* The sensor gain and load resistor have been adjusted to operate with a given unit of a TGS2442 sensor, they will depend on the sensor used and the application, for more information about how to select this parameters take a look at the Gases board technical guide.
* Logger, Common and Gases assemblies must be loaded in the mote.
* Please note that the output is in hexadecimal.
* Please note that Float.toLong() method has been used with a precission of 2 decimals. For example, a 3413 output in decimal base means 34.13. For more information of Float class, see http://localhost:5000/gac/saguaro-system-11.3.htm?fqn=r:com.ibm.saguaro.system.Float
* To compile this example: mrc --assembly=pir-1.0 --system=waspmote --ref=logger-#.# --ref=/common-1.0 --ref=/gases-1.0 Socket2AExample.java

Code

package com.libelium.examples.gases;


import com.ibm.saguaro.system.Float;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.Time;
import com.ibm.saguaro.system.Timer;
import com.ibm.saguaro.system.TimerEvent;
import com.ibm.saguaro.system.csr;
import com.libelium.common.Constants;
import com.libelium.gases.Gases;
import com.ibm.saguaro.logger.Logger;

public class Socket2AExample {
	static Timer timer;
	static Gases gas = new Gases();
	
	static{
		gas.ON();
		
		gas.setSensorMode(Constants.SENS_ON, Constants.SENS_SOCKET2A);
		
		gas.configureSensor(Constants.SENS_SOCKET2A, (byte)2, Float.make(100, (byte)0));
		
		
		timer = new Timer();
		timer.setCallback(new TimerEvent(null) {
			public void invoke(byte param, long time) {
				Socket4Example.timeCallback(param, time);
			}
		});
		long INTERVAL = Time.toTickSpan(Time.MILLISECS, 1000);
		timer.setAlarmBySpan(INTERVAL);

	}
	protected static void timeCallback(byte param, long time) {

		long socket2A = gas.readValue(Constants.SENS_SOCKET2A);

		
		Logger.appendString(csr.s2b("Socket2A measurement: "));
		Logger.appendHexLong(Float.toLong(socket2A, (byte)2));
		Logger.appendString(csr.s2b("V "));
		Logger.flush(Mote.INFO);
		
		long coVal = gas.calculateResistance(Constants.SENS_SOCKET2A, socket2A, (byte)2,
				Float.make(100, (byte)1));
		
		Logger.appendHexLong(Float.toLong(coVal, (byte)2));
		Logger.appendString(csr.s2b("kOHM"));
		Logger.flush(Mote.INFO);
		

		long INTERVAL = Time.toTickSpan(Time.MILLISECS, 1000);
		timer.setAlarmBySpan(INTERVAL);
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Socket2A measurement: 00005204 V

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Socket2A measurement: 0000560 kOHM

Quick Publish: