# APDE USB / OTG communication

**URL:** <https://discourse.processing.org/t/apde-usb-otg-communication/30114>\
**Category:** Processing for Android\
**Created:** [May 16, 2021, 12:13am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114 "2021-05-16T00:13:07Z")\
**Posts on this page:** 20\
**Page:** 8

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 11:17am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/141 "2021-05-26T11:17:19Z")

</div>

Please clarify what working means as im sure that i have sucessfully added libs in apde and so has Jafal.

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 11:24am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/142 "2021-05-26T11:24:00Z")

</div>

@paulgoux

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/72):
>
> I’ve read it 100 times! I’ll send you a picture now.

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/74):
>

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/73):
>

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/67):
>
> Ok. I realized. difficulties arose with both libraries. this hour I will write in detail, I have little experience in installing libraries. Only automatically-zip and manually dfx. but in both cases, the archive must have a “libraries” directory, which must contain the core library files with the .jar extension. The libraries you referenced do not contain this “libraries” directory and there are no .jar files. Don’t know how to install them on APDE. please give instructions.

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/112):
>
> I am trying to repeat your successful feat. I just need to take the last step to victory. how did you install the library you specified in APDE? after all, this library lacks the elements necessary for connection, namely: jar files are missing in the “libraries” folder! How did you manage to connect such a library to APDE? You wrote in your post that you did it. Did you convert the library with something, if so, how and with what?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 11:31am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/143 "2021-05-26T11:31:22Z")

</div>

Then please recheck my post as i tried to make it as clear as possible and even took screenshots

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 11:43am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/144 "2021-05-26T11:43:37Z")

</div>

OK. I will definitely try today. I’m still slowly moving forward with the old library on APDE5.2

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 12:08pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/145 "2021-05-26T12:08:18Z")

</div>

> [@paulgoux](#):
>
> Then please recheck my post as i tried to make it as clear as possible and even took screenshots

This?

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/114):
>
> Im not particularly great with libraries, i jave an android repo that you can make use of ive posted it on the repo however i think ive figured out how to get any library onto android. Take a look at the process. Navigate to the library settings in apde until you get to this screen Press dx dexer Select the library you want to dex.(Note the ext requirements) Then take a look at the files …

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 12:17pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/146 "2021-05-26T12:17:29Z")

</div>

@paulgoux

> **[felHR85/UsbSerial](https://github.com/felHR85/UsbSerial)**
>
> Usb serial controller for Android. Contribute to felHR85/UsbSerial development by creating an account on GitHub.

> **[mik3y/usb-serial-for-android](https://github.com/mik3y/usb-serial-for-android)**
>
> Android USB host serial driver library for CDC, FTDI, Arduino and other devices.

> **[Release v3.4.0 · mik3y/usb-serial-for-android](https://github.com/mik3y/usb-serial-for-android/releases/tag/v3.4.0)**
>
> //github.com/mik3y/usb-serial-for-android/releases/tag/v3.4.0

This is the freshest.  
how to glue them? not .jar files!

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 12:32pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/147 "2021-05-26T12:32:46Z")

</div>

My git already has the file i posted the link…

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 12:50pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/148 "2021-05-26T12:50:19Z")

</div>

![Screenshot_20210526_154621](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a3cba311cd1dd18c4b3dffaf81387718bc6b6bfc.jpeg)  
 ![Screenshot_20210526_155749](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/305b8befe633816f8c1d6463ebde7762647f80ac.jpeg)  
I don’t understand how to work with your library!

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 2:22pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/149 "2021-05-26T14:22:33Z")

</div>

Ignore my last response. I seem to recall @jafal saying you need yo add all three.

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 2:44pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/150 "2021-05-26T14:44:39Z")

</div>

> **[inventit/processing-android-serial](https://github.com/inventit/processing-android-serial)**
>
> Android Serial Library for Processing. Contribute to inventit/processing-android-serial development by creating an account on GitHub.

installs very well on APDE5.2  
and I was almost able to run it.

 ![Screenshot_20210526_174204](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4139b15368444c75a633270feefea073bd37c3a0.jpeg)  
 ![Screenshot_20210526_174316](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0c1a02d298652bc588d871a565f6a62371eca3dc.jpeg)

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 2:51pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/151 "2021-05-26T14:51:33Z")

</div>

I will very, very, very slowly climb to victory!  
 ![20210526_174856](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/aa70c799c5822d968ecde1c607f41557b5153178.gif)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [May 26, 2021, 6:37pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/152 "2021-05-26T18:37:52Z")

</div>

as i said hardware problems i cannot help with as i dont have an arduino to test.

ultimately there are a lot of reasons this could fail and im simply not capable of answering why atm.

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 26, 2021, 9:04pm UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/153 "2021-05-26T21:04:03Z")

</div>

@paulgoux  
I am not asking for help, I am just informing others who have participated about the current state of affairs.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 27, 2021, 5:09am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/154 "2021-05-27T05:09:08Z")

</div>

@paulgoux  
@ZENAR57

glv method works I followed the steps and it is success now the library could be use with APDE

 ![Screenshot_2021-05-27-08-03-47-549](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b21d88a82e13e4e929159d9966ae1beff4b8bada.jpeg)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 27, 2021, 5:12am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/155 "2021-05-27T05:12:58Z")

</div>

@glv

i am always saying that you are one of the best

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 27, 2021, 5:18am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/156 "2021-05-27T05:18:31Z")

</div>

![Screenshot_2021-05-27-08-17-54-999](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/82b325d3cad78bfcfcb1beefaa5cf3da598b8965.jpeg)

> **[APDE.apk.apk](https://drive.google.com/file/d/1_ufR7-yyfm9-D47HxZgyCTVQ1rp8yGG7/view)**
>
> Google Drive file.

@ZENAR57 here is the modified APDE you can download it and it is ready to use the library

here is working code

```auto
import org.slf4j.*;
import org.slf4j.helpers.*;
import com.hoho.android.usbserial.util.*;
import com.yourinventit.processing.android.serial.*;
import org.slf4j.spi.*;
import com.hoho.android.usbserial.driver.*;
import org.slf4j.impl.*;

//import processing.serial.*; // imports library for serial communication

Serial SerialPort; // defines Object for Serial

String ang="";
String distance="";
String data="";

int angle, dist;

void setup() {
  
   size (1200, 700); 
   
  // myPort = new Serial(this,"COM4", 9600); // starts the serial communication
  
 SerialPort = new Serial(this, Serial.list(this)[0], 9600);
  SerialPort .bufferUntil('.'); // reads the data from the serial port up to the character '.' before calling serialEvent
   
 
  background(0);
}

void draw() {
  
                              //for the blur effect
      fill(0,5); //colour,opacity
      noStroke();
      rect(0, 0, width, height*0.93); 
      
      noStroke();
      fill(0,255);
      rect(0,height*0.93,width,height); // so that the text having angle and distance doesnt blur out
      
      
      drawRadar(); 
      drawLine();
      drawObject();
      drawText();
}

void serialEvent (Serial myPort) { // starts reading data from the Serial Port
                                                                                      // reads the data from the Serial Port up to the character '.' and puts it into the String variable "data".
      data = myPort.readStringUntil('.');
      data = data.substring(0,data.length()-1);
      
      int index1 = data.indexOf(",");                                                    
      ang= data.substring(0, index1);                                                 
      distance= data.substring(index1+1, data.length());                            
      
      angle = int(ang);
      dist = int(distance);
      System.out.println(angle);
}

void drawRadar()
{
    pushMatrix();
    noFill();
    stroke(10,255,10); //green
    strokeWeight(3);
    
    translate(width/2,height-height*0.06);
    
    line(-width/2,0,width/2,0);
    
    arc(0,0,(width*0.5),(width*0.5),PI,TWO_PI);
    arc(0,0,(width*0.25),(width*0.25),PI,TWO_PI);
    arc(0,0,(width*0.75),(width*0.75),PI,TWO_PI);
    arc(0,0,(width*0.95),(width*0.95),PI,TWO_PI);
    
    line(0,0,(-width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));
    line(0,0,(-width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));
    line(0,0,(-width/2)*cos(radians(90)),(-width/2)*sin(radians(90)));
    line(0,0,(-width/2)*cos(radians(120)),(-width/2)*sin(radians(120)));
    line(0,0,(-width/2)*cos(radians(150)),(-width/2)*sin(radians(150)));
    
    stroke(175,255,175); 
    strokeWeight(1);
    line(0,0,(-width/2)*cos(radians(15)),(-width/2)*sin(radians(15)));
    line(0,0,(-width/2)*cos(radians(45)),(-width/2)*sin(radians(45)));
    line(0,0,(-width/2)*cos(radians(75)),(-width/2)*sin(radians(75)));
    line(0,0,(-width/2)*cos(radians(105)),(-width/2)*sin(radians(105)));
    line(0,0,(-width/2)*cos(radians(135)),(-width/2)*sin(radians(135)));
    line(0,0,(-width/2)*cos(radians(165)),(-width/2)*sin(radians(165)));

    popMatrix();
}

void drawLine() {
  
    pushMatrix();
    
    strokeWeight(9);
    stroke(0,255,0);
    translate(width/2,height-height*0.06); 
    
   line(0,0,(width/2)*cos(radians(angle)),(-width/2)*sin(radians(angle)));
   

    popMatrix();
    
}

void drawObject() {
  
    pushMatrix();
    
    strokeWeight(9);
    stroke(255,0,0);
    translate(width/2,height-height*0.06);
   
    float pixleDist = (dist/40.0)*(width/2.0); // covers the distance from the sensor from cm to pixels
    float pd=(width/2)-pixleDist;
    
             
    float x=-pixleDist*cos(radians(angle));
    float y=-pixleDist*sin(radians(angle));
    
    if(dist<=40) // limiting the range to 40 cms
    {                               
       //line(0,0,pixleDist,0);  
       line(-x,y,-x+(pd*cos(radians(angle))),y-(pd*sin(radians(angle))));
    }
    popMatrix();
}

void drawText()
{
    pushMatrix();
    
    fill(100,200,255);
    textSize(25);
    
    text("10cm",(width/2)+(width*0.115),height*0.93);
    text("20cm",(width/2)+(width*0.24),height*0.93);
    text("30cm",(width/2)+(width*0.365),height*0.93);
    text("40cm",(width/2)+(width*0.45),height*0.93);
    
    textSize(40);
    text("YAinnoware",width*0.08,height*0.99);
    text("Angle :"+angle,width*0.45,height*0.99);
    
    if(dist<=40) {
      text("Distance :"+dist,width*0.7,height*0.99);
    }
      
   translate(width/2,height-height*0.06);
   textSize(25);
   
   text(" 30°",(width/2)*cos(radians(30)),(-width/2)*sin(radians(30)));
   text(" 60°",(width/2)*cos(radians(60)),(-width/2)*sin(radians(60)));
   text("90°",(width/2)*cos(radians(91)),(-width/2)*sin(radians(90)));
   text("120°",(width/2)*cos(radians(123)),(-width/2)*sin(radians(118)));
   text("150°",(width/2)*cos(radians(160)),(-width/2)*sin(radians(150)));
    
    popMatrix();  
  
}

```

take Arduino code from here

### [Radar (SONAR) Using Processing 3](https://www.hackster.io/Yug_Ajmera/radar-sonar-using-processing-3-7302c6)

and this is the device filter file make folders in your sketch folder res/xml

```auto
<?xml version="1.0" encoding="utf-8"?>
<!--
https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples/src/main/res/xml/device_filter.xml
-->
<resources>
    <!-- 0x0403 / 0x6001: FTDI FT232R UART -->
    <usb-device vendor-id="1027" product-id="24577" />

    <!-- 0x0403 / 0x6015: FTDI FT231X -->
    <usb-device vendor-id="1027" product-id="24597" />

    <!-- 0x2341 / Arduino -->
    <usb-device vendor-id="9025" />

    <!-- 0x16C0 / 0x0483: Teensyduino -->
    <usb-device vendor-id="5824" product-id="1155" />

    <!-- 0x10C4 / 0xEA60: CP210x UART Bridge -->
    <usb-device vendor-id="4292" product-id="60000" />

    <!-- 0x067B / 0x2303: Prolific PL2303 -->
    <usb-device vendor-id="1659" product-id="8963" />

    <!-- 0x1a86 / 0x7523: Qinheng CH340 -->
    <usb-device vendor-id="6790" product-id="29987" />
</resources>

```

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 27, 2021, 9:04am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/157 "2021-05-27T09:04:22Z")

</div>

@jafal  
@paulgoux  
@glv  
I managed to establish a connection.  
I used normal APDE5.2 (unmodified) and normal 0.2.0beta library. The manifest and file filter are used normal. the problem was that all together it absolutely didn’t work at 57600. At any other speed it started to work well.

> [@APDE USB / OTG communication](https://discourse.processing.org/t/apde-usb-otg-communication/30114/101):
>
> my arduino configured for constant cyclic transmission at a rate of 57600. he cannot accept anything now, he has to change it.

however, the 57600 terminal worked well in a third-party program.

 ![Screenshot_20210527_050941_processing.test.sketch_20210523a](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/32d43d10264e0088cb4599c71bd2d5ebc2279319.jpeg)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [May 27, 2021, 9:04am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/158 "2021-05-27T09:04:47Z")

</div>

here is the library  
[https://drive.google.com/drive/folders/1rOhqlkHkkarVYh5q3qaM5wokhwuFWXzM?usp=sharing](https://drive.google.com/drive/folders/1rOhqlkHkkarVYh5q3qaM5wokhwuFWXzM?usp=sharing)

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 27, 2021, 9:48am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/159 "2021-05-27T09:48:10Z")

</div>

@jafal  
@paulgoux  
@glv  
Thank you all very much. I appreciate every letter and number you write here. your help is immense.

---

<div class="post-metadata">

**Author:** ![ZENAR57](https://avatars.discourse-cdn.com/v4/letter/z/a698b9/32.png) [@ZENAR57](https://discourse.processing.org/u/ZENAR57)\
**Post date:** [May 27, 2021, 11:54am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/160 "2021-05-27T11:54:57Z")

</div>

APDE5.2  
I blinded the library from your files and installed fine. But I don’t know much about it, something went wrong.

 ![Screenshot_20210527_144409](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/db16a78c27c496e3907352f83d7a7954a16c485d.jpeg)  
 ![Screenshot_20210527_144334](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6f80846c994609209704b8f7169997cb2be6dd47.jpeg)

could you please format it correctly into a zip file?  
It will be able to work on api16, is it android 4.1? Today there are still many large, old tablets on android4.1, I wanted to use them in the first place, because for the modern world and normal use they are very outdated.

[Previous page](https://discourse.processing.org/t/apde-usb-otg-communication/30114.md?page=7)

[Next page](https://discourse.processing.org/t/apde-usb-otg-communication/30114.md?page=9)
