# Connect USB webcam to Processing Android with Ketai

**URL:** <https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664>\
**Category:** Processing for Android\
**Created:** [November 24, 2020, 5:37pm UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664 "2020-11-24T17:37:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![flotowcameron](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@flotowcameron](https://discourse.processing.org/u/flotowcameron)\
**Post date:** [November 24, 2020, 5:37pm UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664/1 "2020-11-24T17:37:12Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Hi everyone,  
Can someone send me the code needed to connect a webcam to an android device? I am using Processing Android Mode obviously and I’ve tried using Ketai Camera and setting cam.setCameraID(); to 2 and -1 but neither works. How can I access a usb webcam connected (via usb) to my android device. I’ll paste my code below.

import ketai.camera.\*;

KetaiCamera cam;

import processing.sound.\*;  
SqrOsc soundRed;  
Pulse soundGreen;  
SinOsc soundBlue;  
int gameState = 0;  
int count = 0;  
float rAmp = 0;  
float gAmp = 0;  
float bAmp = 0;  
boolean sounds = false;  
float tempRed = 0;  
float tempGreen = 0;  
float tempBlue = 0;  
float mapRed = 0;  
float mapGreen = 0;  
float mapBlue = 0;  
float soundSpace = 0;

int countThruCameras;  
void setup() {

textSize(20);  
fullScreen();  
orientation(PORTRAIT);

soundRed = new SqrOsc(this);  
soundRed.amp(0.05);  
soundGreen = new Pulse(this);  
soundGreen.amp(0.05);  
soundBlue = new SinOsc(this);  
soundBlue.amp(0.2);

cam = new KetaiCamera(this, 1000, 1500, 60);  
cam.setCameraID(2);  
textAlign(CENTER, CENTER);  
}

void draw() {

if(gameState == 0){  
count++;  
if(count \>= 200){  
gameState = 1;  
cam.start();  
}  
background(255);

}

if (gameState==1) {

```
print(cam.getCameraID());
soundRed.amp(rAmp);
soundGreen.amp(gAmp);
soundBlue.amp(bAmp);

background(0);

translate(width/2, height/2);
pushMatrix();
rotate(HALF_PI);
image(cam, 0,0);
popMatrix();
tempRed = red(get(width/2, height/2));
tempGreen = green(get(width/2, height/2)); 
tempBlue = blue(get(width/2, height/2));
mapRed = map(tempRed, 0, 255, 1, 200);
mapGreen = map(tempGreen, 0, 255, 0, 450);
mapBlue = map(tempBlue, 0, 255, 1, 500);
rAmp = map(mapRed, 0, 200, 0, .05);
gAmp = map(mapGreen, 0, 450, 0, .05);
bAmp = map(mapBlue, 0, 200, 0, .07);
soundRed.freq(mapRed);
soundGreen.freq(mapGreen);
soundBlue.freq(mapBlue);
stroke(255);
strokeWeight(2);
noFill();
ellipse(0, 0, 40, 40);
if (sounds) {
  soundRed.play();
  soundGreen.play();
  soundBlue.play();
} else {
  soundRed.stop();
  soundGreen.stop();
  soundBlue.stop();
  fill(0, 0, 0, 180);
  stroke(0);
  //rect((-width/2)-5, 170, width+5, 60);
  fill(0, 200, 255);
  text("Click screen to hear color", 0, (height/3)+(height/13));
  stroke(255);
}

```

}  
}

void onCameraPreviewEvent()  
{  
cam.read();  
}

void mousePressed() {

if(gameState==1){  
sounds = !sounds;

}  
}

---

<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:** [November 25, 2020, 5:50am UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664/2 "2020-11-25T05:50:36Z")

</div>

Hi @flotowcameron  
Are you using a webcam with an OTG cable?

---

<div class="post-metadata">

**Author:** ![flotowcameron](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@flotowcameron](https://discourse.processing.org/u/flotowcameron)\
**Post date:** [November 25, 2020, 4:53pm UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664/3 "2020-11-25T16:53:31Z")

</div>

I’m using a webcam. To be specific, I have this one: [https://www.target.com/p/logitech-c270-3-0mp-webcam-black-960-000694/-/A-13252212#lnk=sametab](https://www.target.com/p/logitech-c270-3-0mp-webcam-black-960-000694/-/A-13252212#lnk=sametab)

---

<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:** [November 25, 2020, 5:48pm UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664/4 "2020-11-25T17:48:25Z")

</div>

Should be possible with an OTG cable in series. [Here is an android driver code](https://github.com/jwoolston/Android-Webcam). I can not test this because I don’t have a usb webcam.

---

<div class="post-metadata">

**Author:** ![flotowcameron](https://avatars.discourse-cdn.com/v4/letter/f/a183cd/32.png) [@flotowcameron](https://discourse.processing.org/u/flotowcameron)\
**Post date:** [November 28, 2020, 12:47am UTC](https://discourse.processing.org/t/connect-usb-webcam-to-processing-android-with-ketai/25664/5 "2020-11-28T00:47:54Z")

</div>

I’m newish to Processing Android. How would I use this android driver code in my program? I’ve never done that before.
