| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Want to get organized in 2022? Let Dokkio put your cloud files (Drive, Dropbox, and Slack and Gmail attachments) and documents (Google Docs, Sheets, and Notion) in order. Try Dokkio (from the makers of PBworks) for free. Available on the web, Mac, and Windows.

View
 

How-to use a serial port with Android, Liquidware Ambrosia edition

Page history last edited by mike 9 years, 8 months ago

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.

 

 

 

  • In your Skeleton app add this code to begin serial:
import android.serial.*;
....
SerialManager Serial; 

Serial = (SerialManager) getSystemService(Context.SERIAL_SERVICE); 

 

  • In your Skeleton app add the following code to receive serial messages
/* Handle Serial messages */
SerialStatus.SerialMsgListener sl = new SerialStatus.SerialMsgListener() {
 public void onSerialMsgReceived(String sMsg) {
  /* Handle the message.. */
  Log.v("SkeletonSerial", sMsg);
 }
};
Serial.addSerialMsgListener(sl);

 

  • Add the following code to begin serial
Serial.begin("ttyUSB0", 9600);

 

  • Add the following code to transmit serial
Serial.print("U");

 

  • Add the following code to end serial
Serial.end("ttyUSB0");

 

  • Attach your Serial device through a USB hub for power and connect to the BeagleBoard's USB host port.  I am using an Arduino as my serial device. http://arduino.cc

   

 

               

 

 

  • On the Arduino I used the following sketch to read "A" or "B" characters, which turn the LED ON or OFF:
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..");
    }
  }
}

 

 

 

Comments (0)

You don't have permission to comment on this page.