# Using Serial with Processing for Android

**URL:** <https://discourse.processing.org/t/using-serial-with-processing-for-android/22974>\
**Category:** Processing for Android\
**Created:** [August 1, 2020, 9:41pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974 "2020-08-01T21:41:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 1, 2020, 9:41pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/1 "2020-08-01T21:41:42Z")

</div>

I’m trying to use Bluetooth Classic from a Processing app (version 3.5.4) in the Android mode with a Serial library download from the internet “AndroidSerial”. Source code which fails is as follows:

```auto
import com.yourinventit.processing.android.serial.*;

void setup() {
  fullScreen();
}

void draw() {
  background(204);
  
 fill(0);
 rect(200,60,60,60);
 fill(255);
 triangle(205,65,255,65,230,115);
     
  if (mousePressed) {
    if ((mouseX > 200) && (mouseX < 260) && (mouseY > 60) && (mouseY < 120)) {
      println(Serial.list(this));
    } 
}
}

```

The app crashes when the triangle is pressed. Error message follows:

```auto
FATAL EXCEPTION: Animation Thread
Process: processing.test.serialtest, PID: 18741
java.lang.IllegalArgumentException: This library works only on Android.
	at com.yourinventit.processing.android.serial.SerialCommunicatorFacory.create(SerialCommunicatorFacory.java:67)
	at com.yourinventit.processing.android.serial.Serial.<init>(Serial.java:41)
	at com.yourinventit.processing.android.serial.Serial.<init>(Serial.java:50)
	at com.yourinventit.processing.android.serial.Serial.list(Serial.java:263)
	at processing.test.serialtest.serialTest.draw(serialTest.java:37)
	at processing.core.PApplet.handleDraw(PApplet.java:1852)
	at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:476)
	at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:516)

```

I note that the library works only on Android, but the Android mode is selected and an Android sdk is installed on my system (macOS).

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [August 2, 2020, 8:36am UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/2 "2020-08-02T08:36:59Z")

</div>

Hi.  
Have you tried [this version](https://github.com/inventit/processing-android-serial/releases/tag/0.2.0) of the lib?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 2, 2020, 2:05pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/3 "2020-08-02T14:05:25Z")

</div>

@noel very helpful. Latest version of library no longer causes crash. However, now I get the following error message and I’m not sure how to fix it:

```auto
Processing-Android USB Serial ERROR

Port:null
Check the following:
1) Make sure AndroidManifest.xm. contains <use-feature> tag for android.hardware.usb.host
2) USB Serial is connected to the device

```

I’m trying to get this demo to run on a Samsung tablet using an Arduino UNO connected to a Mac mini as the data source. The UNO has a classic Bluetooth shield which is sending test data (tested in another Processing java app and this is working). I have checked all the Bluetooth boxes under Android/Sketch Permissions but do not see “use-feature” in the manifest which is shown below:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="processing.test.serialtest">
    <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="28"/>
    <application android:icon="@mipmap/ic_launcher" android:label="serialTest">
        <activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED"/>
</manifest>

```

How would I add a tag for android.hardware.usb.host to the manifest in Processing?

I greatly appreciate your help.

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [August 2, 2020, 2:14pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/4 "2020-08-02T14:14:39Z")

</div>

@svan ===

```auto
<manifest ...>
    <uses-feature android:name="android.hardware.usb.host" />

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [August 2, 2020, 3:03pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/5 "2020-08-02T15:03:51Z")

</div>

And the port number is properly listed of course?

---

<div class="post-metadata">

**Author:** ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)\
**Post date:** [August 2, 2020, 3:23pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/6 "2020-08-02T15:23:26Z")

</div>

@svan === it seems to be null…

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 2, 2020, 4:34pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/7 "2020-08-02T16:34:59Z")

</div>

@noel and @akenaton

Adding the “uses-feature” to the manifest in the project folder didn’t solve the problem. I still get the same error message, therefore I am unable to get the demo to give me a serial port list. However, I have looked in the tablet’s settings and can see that I have previously paired the Bluetooth shield for use with another app. Just to see what would happen, I unpaired it and tried to re-pair it. Now it does not show the shield as being available for pairing and I am unsure why. For now it appears that recognition of the port is the problem and will need more trouble-shooting. I appreciate your help. Will provide follow-up if I ever get it working.

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [August 2, 2020, 4:54pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/8 "2020-08-02T16:54:38Z")

</div>

Have you closed all other programs that could be using your serial port, for example arduino serial monitor, hyperterminal, etc. ?

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [August 2, 2020, 5:02pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/9 "2020-08-02T17:02:36Z")

</div>

[This](http://www.nirsoft.net/utils/usb_devices_view.html) can help?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 2, 2020, 7:48pm UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/10 "2020-08-02T19:48:48Z")

</div>

@noel - USBDeview appears to be a Windows app and I’m doing this on a Mac. The serial ports on a Mac may be displayed in Terminal using the command “ls /dev/cu.\*”. At any rate, I think I’m going down the wrong road; what I need is a list of paired Bluetooth devices and devices available for pairing on my Android tablet. Therefore, I don’t think “println(Serial.list(this))” will work for this purpose. Hopefully, there is another way to find Bluetooth devices using Processing Android; I need to read some more. Thanks.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [August 6, 2020, 4:59am UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/11 "2020-08-06T04:59:22Z")

</div>

The following code will find the Bluetooth devices paired with my Samsung tablet:

```auto
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import java.util.Set;

String[] devices = {};
 
 void findPairedBluetoothDevices() {
 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
 if (adapter == null) {
    println("Device doesn't support Bluetooth.");
 } else {
   Set<BluetoothDevice> pairedDevices = adapter.getBondedDevices();
   if (pairedDevices.size() > 0) {
    // Get the name and address of each paired device.
     for (BluetoothDevice device : pairedDevices) {
       String deviceName = device.getName();
       String deviceHardwareAddress = device.getAddress(); // MAC address
       String deviceInfo = deviceName + "\n " + deviceHardwareAddress;
       devices = append(devices, deviceInfo);
       println(deviceInfo);
     }       
  }
 }
}

void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  findPairedBluetoothDevices();
}

void draw() {
  color BLUE = color(64,124,188);
  background(BLUE);
  fill(255);
  textSize(48);
  for(int j = 0; j < devices.length; j++) {
  text(devices[j], 130, 100 + (180 * j), 500, 180);
  }
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [August 6, 2020, 5:53am UTC](https://discourse.processing.org/t/using-serial-with-processing-for-android/22974/12 "2020-08-06T05:53:52Z")

</div>

Thanks for sharing…
