First Project - Web Controlable Webcam

Status
Not open for further replies.

MrDyne

New member
Greetings, Teensy users!

Just wanted to post my first project with the teensy.
I'm using the Teensy2++.

I didn't start out to build this, it just kinda happened as I was messing with the teensy for the first time. I've never used anything Arduino before.
So ya it pretty much started when I found the Servo example in the Teensyduino software. My Dad had a box with a really old analog Futaba RC kit. Two spare servos. I didn't know if they would work.

First test was just to see if the servo example would work with these old servos, which they did. But a servo going back and forth is kind of boring.
So I looked at options of controlling the servos position from the computer. Some Googleing and checking out the Serial example I was able to set the servo position by sending a single ASCII character to the COM port. But this was very limited because the only way to control the servo was via a command prompt "echo ! > COM7" or the COM port window in the Arduino IDE. I needed a program that could control the servo position better, but I don't know C++ or Java. All I know is xhtml, css, PHP, batch, and Game Maker.

I figured that controlling the Teensy/servo through a webpage was the coolest idea. So another quick Google I found PHP-Serial script. Works really well with WAMP server on my computer.

So ya, Web browser > Web server > PHP > Serial > Teensy > Servo. And then the week I was building this project my friend gives me an old webcam. So I quickly added the 2nd servo, programed the teensy to accept two ASCII character via serial and then hot glue both the servos and the camera together. (so I have Z and Y axises),

Code:
#include <PWMServo.h>
 
PWMServo servo_0;
PWMServo servo_1; 
int pos[1];

void setup() 
{ 
  Serial.begin(9600);
  servo_0.attach(SERVO_PIN_A);
  servo_1.attach(SERVO_PIN_B);
  servo_0.write(77);
  servo_1.write(77);
}
 
void loop() 
{ 
  if (Serial.available() > 1)
    {  
       pos[0] = (Serial.read() - 0);
       pos[1] = (Serial.read() - 0);
       servo_0.write(pos[0]);
       servo_1.write(pos[1]);
       Serial.flush();
    }
}

turretcam1.jpg

I know it's not the best thing to run the servos off the Teensy's power and I originally used the 5 volt line off a spare ATX power supply but it was too cumbersome to have the ATX power supply on my desk to run the servos. I have no way to test how much current the servos take but I made sure to hardcode in range limits. The servos wont go near their stall limits. And they aren't being forced to move anything heavy. So I haven't had any problems, yet.

turretcam2.jpg

It's a really basic webpage. I don't know javascript or ajax so the page reloads on each click. The bold numbers are increments and others are actual positions. Because the serial data is one way the webpage has to remember the current servo position, but that's not a big deal. I'm still surprised how fast it reacts when you press a button on the webpage. I do video calls on Skype with friends and give them a specially written URL to auto login to the webpage. "http://username:password@domain.com:port/" They have quite the fun controlling my camera and looking around my desk area over the internet.

~MrDyne
 
Status
Not open for further replies.
Back
Top