Development

» MR-General 01: GPIO Example

This example shows how general purpose input and ouput works on Mote Runner. It makes a write and then it reads the same pin, printing it into 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=gpio-1.0 --system=waspmote --ref=logger-#.# GPIOExample.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.GPIO;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.csr;

public class GPIOExample {
	static GPIO gpio = new GPIO();
	static{
		gpio.open();
		
		//Write
		gpio.configureOutput((byte)1, GPIO.OUT_CLR);
		gpio.doPin(GPIO.CTRL_SET, (byte)1);
		//Reading
		gpio.configureInput((byte)1, GPIO.IRQ_DISABLED, (byte)0);
		int read = gpio.doPin(GPIO.CTRL_READ, (byte)1);
		
		Logger.appendString(csr.s2b("Digital 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: Digital read: 0001

Quick Publish:

This site uses cookies. By clicking the “Accept” button you are agreeing to our use of cookies. Read More