Development

» MR-General 02: Analog syncrhonous reading

This example shows the use of the syncrhonous 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=syncAdc-1.0 --system=waspmote --ref=logger-#.# AnalogSyncExample.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.GPIO;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.csr;
import com.ibm.waspmote.WASPMOTE;

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

	static{
		
		chmap = chmap | (int) (1 << ADC_2);
		adc.open(chmap, GPIO.NO_PIN, 0, 0);

		//Reading
		int read = adc.readChannel(ADC_2);
		
		Logger.appendString(csr.s2b("Analog read: "));
		Logger.appendHexInt(read);
		Logger.flush(Mote.INFO);
	}
}

Output

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

Quick Publish: