GithubHelp home page GithubHelp logo

gokmonk / arduinofirmata-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shokai/arduinofirmata-android

0.0 0.0 0.0 3.08 MB

Arduino Firmata protocol implementation on Android Java.

Home Page: http://shokai.github.com/ArduinoFirmata-Android

License: MIT License

Makefile 5.94% Java 94.06%

arduinofirmata-android's Introduction

ArduinoFirmata on Android

Arduino Firmata protocol (http://firmata.org) 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.

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:

Setup

Connect

import org.shokai.firmata.ArduinoFirmata;

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

Close

arduino.close();

I/O

Digital Write

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)

Analog Read

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

Servo Motor

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

Events

Event Handler

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

Data Handler

arduino.setDataHandler(
  new ArduinoFirmataDataHandler(){
    public void onSysex(byte command, byte[] data){
    }
  }
);

Sysex

Send

byte[] data = {13, 5, 2};
arduino.sysex((byte)0x01, data);  // command, data

Regist Receive Event

arduino.setDataHandler(
  new ArduinoFirmataDataHandler(){
    public void onSysex(byte command, byte[] data){
      Log.v("sysex command", new Integer(command).toString());
      String s = "";
      for(int i = 0; i < data.length; i++){
        s += new Integer(data[i]).toString() + ",";
      }
      Log.v("sysex data", s);
    }
  }
);

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Build arduino-firmata.jar

set Android SDK Path

% export CLASSPATH=$CLASSPATH:/usr/local/var/lib/android-sdk/platforms/android-13/android.jar
% export LC_ALL=en

build jar

% make init
% make

=> arduino-firmata.jar

arduinofirmata-android's People

Contributors

shokai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.