Android processing app crashes when using usb / processing serial library (Serial.list(this)) probs

edited June 2016 in Android Mode

hi - I'm having trouble debugging why my android app is crashing when trying to use processing android serial to talk via Processing android app to arduino. i can successfully install and launch the app on android, but the app keeps crashing. I'm using really simple code just to see if I can talk via an OTG cable via serial from Android to Arduino via processing app. But when I plug in the OTG USB cable that's plugged into arduino UNO, I can choose the android app to open up that I have installed from Processing to android, but right away it says "Unfortunately, this app has stopped".

I'm wondering how to go about debugging this. Is it the wrong port (Serial.list(this)[0]) that is doing this? or something else? I'm not sure how to debug why the app's crashing. I just recently started using Processing 0251 for Android. Even just the line "println(Serial.list(this));" triggers the app to shut down.

Thanks in advance!

I used this link to help getting set up:

Processing code in Android mode:


Serial SerialPort;
boolean Toggle;

void setup()    
  println(Serial.list(this)); //this line alone makes the app crash even if i dont have any other code
  SerialPort = new Serial(this, Serial.list(this)[0], 9600);

void draw()

void mousePressed() {    
  Toggle = !Toggle;
    // while (SerialPort.available() > 0) {
  SerialPort.write( Toggle?"1":"0");
    // }

Arduino Code:

    #define NUMBER_OF_CHANNELS 8
    #define PINLED1 13
    volatile char lastReceivedCharFromSerialIn = '\0';

    void setup() {
      pinMode(PINLED1, OUTPUT);

    void loop() {
      digitalWrite( PINLED1, lastReceivedCharFromSerialIn == '1');

    void serialEvent() {
      while (Serial.available()) {
        // get the new byte:
        lastReceivedCharFromSerialIn = (char); 


  • Hi. I have exactly the same problem. Have you solved it? Or does anyone know how to deal with it? Other programs which don't use Serial library work fine on my phone.

  • First, can you run your code in Java mode?

    Second, what is the meaning of talking to an arduino via serial from Android processing? Like are you trying to connect your android device directly to your arduino? Maybe you should try P2P like WiFi or Bluetooth. I am not an expert in this, but I have a feeling android does not have a way to connect via serial. Please correct me if I am wrong. Where are you getting your information or documentation that describe this type of operation?


  • edited July 2016

    Thanks for your comment.

    Yes, it runs in Java mode, but it uses different serial library then. I want to connect arduino directly to Android via otg usb cable, but it crashes right after uploading a sketch. I use this library for this purpose:

    AndroidSerial for Processing

    An example of this operation is described in the Example section on the library's github site.

    EDIT : I got this to work. The problem was with the phone. It didn't support otg cable. I used other phone and it work on it.

  • Great, good to hear!


Sign In or Register to comment.