Development

Mote Runner:

General / ADC

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-General 03: Analog asyncrhonous reading

This example shows the use of the asyncrhonous reading of the ADC, reading a value and printing it into the screen.

Required Materials

1 x Waspmote PRO
1 x MiniUSB wire
1 x Battery

Notes

* Please, note that the output is in Hexadecimal
* Remember to connect the battery to Waspmote for proper operation.
* To compile this example: mrc --assembly=asyncAdc-1.0 --system=waspmote --ref=logger-#.# AnalogAsyncExample.java

Code

/**
 *  Copyright (C) 2013 Libelium Comunicaciones Distribuidas S.L.
 * http://www.libelium.com
 *
 * This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 3.0 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.html
 *
 *  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/>.
 * 
 * Design: David Gascón
 * 
 * @version 0.1
 * @author Anartz Nuin Jiménez, Diego López Pérez and Ignacio Ruiz Martín
 */
package com.libelium.examples.general;

import com.ibm.saguaro.logger.Logger;
import com.ibm.saguaro.system.ADC;
import com.ibm.saguaro.system.DevCallback;
import com.ibm.saguaro.system.Device;
import com.ibm.saguaro.system.GPIO;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.Util;
import com.ibm.saguaro.system.csr;

public class AnalogAsyncExample {
	static ADC adc = new ADC();
	private static byte ADC_2 = 2;
	
	static int chmap;

	static{
		
		chmap = chmap | (int) (1 << ADC_2);
		adc.setReadHandler(new DevCallback(null) {
			
			@Override
			public int invoke(int flags, byte[] data, int len, int info, long time) {
				return AnalogAsyncExample.onReadDone(flags, data, len, info, time);
			}
		});
		adc.open(chmap, GPIO.NO_PIN, 0, 0);
		adc.read(Device.ASAP, (byte)2, (byte)0);
		
	
	}
	
	private static int onReadDone(int flags, byte[] data, int len, int info, long time){
		int read = Util.get16(data,(byte)0);
		Logger.appendString(csr.s2b("Analog read: "));
		Logger.appendHexInt(read);
		Logger.flush(Mote.INFO);
		
		return 0;
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Analog read: 03FF

Quick Publish: