Skip to content Skip to sidebar Skip to footer

Arduino Android Usb Connection

I am using an Arduino Duemilanove and Nexus 7. I have successfully detected the Arduino board and displayed the vendor id and product id. I am trying to transfer data from my table

Solution 1:

The project you reference from http://android.serverbox.ch/?p=549 in comments will only work with the more recent Arduino boards such as the Uno (or with something else which uses the CDC-ACM serial-over-USB scheme which they implement).

The older Arduino boards such as your duemilanove use an FTDI USB-serial chip, which would require different USB operations.

You may be able to find something somewhere about interfacing the FT232 family of USB-serial converters with Android's USB host api (the FTDI parts are widely used in embedded systems, so it's not out of the question you'll find something), or you can get an Uno board to try the code you already have.

Solution 2:

I know it's been a while but anyway, I made a short library to do this. This is how you use it :

Arduino arduino = newArduino(Context);

@OverrideprotectedvoidonStart() {
    super.onStart();
    arduino.setArduinoListener(newArduinoListener() {
        @OverridepublicvoidonArduinoAttached(UsbDevice device) {
            // arduino plugged in
            arduino.open(device);
        }

        @OverridepublicvoidonArduinoDetached() {
            // arduino unplugged from phone
        }

        @OverridepublicvoidonArduinoMessage(byte[] bytes) {
            String message = newString(bytes);
            // new message received from arduino
        }

        @OverridepublicvoidonArduinoOpened() {
            // you can start the communicationString str = "Hello Arduino !";
            arduino.sendMessage(str.getBytes());
        }
    });
}

@OverrideprotectedvoidonDestroy() {
    super.onDestroy();
    arduino.unsetArduinoListener();
    arduino.close();
}

And the code on Arduino side could be something like this :

voidsetup() {
    Serial.begin(9600);
}

voidloop() {
    if(Serial.available()){
        char c = Serial.read();
        Serial.print(c);
    }
}

You can check the github page if you are interested.

Post a Comment for "Arduino Android Usb Connection"