ArduinoFirmata on Android

Firmata protocol implementation on Android Java

What is Firmata?

Firmata is a protocol to controll Arduino from Application on Android Phone. You can write Arduino-code in Android Java.

TRY

Install sample application.

REQUIREMENTS

SETUP

  1. Copy arduino-firmata.jar and usb-serial-for-android.jar to "libs" directory
  2. Copy device_filter.xml to "res/xml" directory
  3. edit AndroidManifest.xml
<activity android:name="MainActivity" />
  <intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
  </intent-filter>
  <meta-data
      android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
      android:resource="@xml/device_filter" />
</activity>

SYNOPSIS

Connect Arduino with Android

import org.shokai.firmata.ArduinoFirmata;

ArduinoFirmata arduino = new ArduinoFirmata();

try{
  arduino.connect();
}
catch(IOException e){
  e.printStackTrace();
}

Digital Write

on board Yellow LED
arduino.digitalWrite(13, true); // on board LED
arduino.digitalWrite(13, false);

Digital Read

arduino.pinMode(7, ArduinoFirmata.INPUT);
boolean status = arduino.digitalRead(7);  // => true/false

Analog Write (PWM)

arduino.analogWrite(11, 230); // pinNumber, value(0~255)

Digital 11 PIN -> LED -> GND

Analog Read

int value = arduino.analogRead(0);  // => 0 ~ 1023

GND & 5V -> CdS & 10kΩ -> Analog 0 PIN

Servo Motor

arduino.servoWrite(9, 135); // pinNumber, angle(0~180)

Close

arduino.close();

Set Event Handler

import org.shokai.firmata.ArduinoFirmataEventHandler;

arduino.setEventHandler(
  new ArduinoFirmataEventHandler(){
    public void onError(String errorMessage){
      Log.e("ArduinoFirmata App", errorMessage);
    }
    public void onClose(){
      Log.v("ArduinoFirmata App", "arduino closed");
    }
  }
);

Samples

LICENSE

Contributing