This tutorial will help you transmit and receive to a serial device using your Liquidware Android kit and Android Ambrosia SD Card
This could be useful to interface Android applications to serial devices like Arduinos, Accelerometers, and other sensors.
import android.serial.*; .... SerialManager Serial; Serial = (SerialManager) getSystemService(Context.SERIAL_SERVICE); |
/* Handle Serial messages */ SerialStatus.SerialMsgListener sl = new SerialStatus.SerialMsgListener() { public void onSerialMsgReceived(String sMsg) { /* Handle the message.. */ Log.v("SkeletonSerial", sMsg); } }; Serial.addSerialMsgListener(sl); |
Serial.begin("ttyUSB0", 9600); |
Serial.print("U"); |
Serial.end("ttyUSB0"); |
void setup(){ Serial.begin(9600); } int i=0; void loop() { Serial.println(i++); delay(500); if (Serial.available()) { int msg = Serial.read(); if (msg == 'A') { digitalWrite(13, HIGH); Serial.println("Turning LED on.."); } if (msg == 'B') { digitalWrite(13, LOW); Serial.println("Turning LED off.."); } } } |