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 01: CO Sensor on Socket 4 Reading

In this example the Gases 2.0 board is turned on, reading the CO sensor placed on socket4 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 CO sensor (TGS2442)

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 Socket4Example.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 Socket4Example {
	static Timer timer;
	static Gases gas = new Gases();
	
	static{
		gas.ON();
		
		gas.setSensorMode(Constants.SENS_ON, Constants.SENS_SOCKET4CO);
		
		gas.configureSensor(Constants.SENS_SOCKET4CO, (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 socket4CO = gas.readValue(Constants.SENS_SOCKET4CO);

		
		Logger.appendString(csr.s2b("Socket4CO measurement: "));
		Logger.appendHexLong(Float.toLong(socket4CO, (byte)2));
		Logger.appendString(csr.s2b("V "));
		Logger.flush(Mote.INFO);
		
		long coVal = gas.calculateResistance(Constants.SENS_SOCKET4CO, socket4CO, (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: Socket4CO measurement: 00005204 V

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

Quick Publish: