Pages: [1]   Go Down
Author Topic: Simple arduino/apache web control.  (Read 4287 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Tesla Member
***
Karma: 145
Posts: 9696
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've made a simple way to have web control of the arduino based on a servo pan/tilt web cam I've had operating for ~6 years. This method uses the apache web server running on a pc and a batch file to send serial commands to the arduino via the USB serial connection. The main requirement is to have a 100 ohm resistor connected between the arduino 5v pin and the arduino reset pin to defeat the arduino reset when a serial connection is opened. In this instance a position is sent to a servo connected to the arduino from a web page. The same basic setup could be used for controling other devices connected to the arduino.

Below is the batch file used as the CGI interface between the apache web server and the arduino. Copy the code, paste in notepad, and save in the apache cgi-bin folder as arduino.bat. Note that batch files automatically append a cr/lf to the end of strings echoed, but is not important when using the servo library. The batch file sends the contents of the query_string out the selected com port. The comport setting are commented out and are only if your pc comport is normally set to different values.

Code:
@echo off
echo status: 204
echo.
echo.
::mode com5:9600,N,8,1 >nul
echo %QUERY_STRING% >com5
cls

Below is the basic control web page that has the URLs with the servo positions attached as a query_string (?1500). The page can be copied, pasted in notepad, and saved in the apache htdocs folder as arduino.htm. I used 127.0.0.1 for testing on my laptop, bit a lan address like 192.168.1.5 or you.no-ip.com can be used.

Code:
<HTML>
<HEAD>
<TITLE>Zoomkat's Arduino Servo CGI Test</TITLE>
</HEAD>
Zoomkat's Arduino servo cgi test 12/22/10
<BR>
Position Servo:
<BR>
Servo 0:
<BR>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?0500">0500</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?0600">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?0700">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?0800">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?0900">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1000">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1100">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1200">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1300">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1400">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1500">1500</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1700">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1800">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?1900">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2000">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2100">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2200">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2300">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2400">*</a>
<a href="http://127.0.0.1/cgi-bin/arduino.bat?2500">2500</a>
<BR>
</HTML>

Below is my old webcam that is operated in the same way, except that it uses a serial servo control chip instead of an arduino. This should show the simple type of control available. Bottom is the servo code.

http://web.comporium.net/~shb/wc2000-PT-script.htm

Code:
// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.attach(7);  //the pin for the servo control
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray);
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  }
}
« Last Edit: December 23, 2010, 02:26:12 am by zoomkat » Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Atlanta
Offline Offline
Sr. Member
****
Karma: 1
Posts: 255
Arduino still rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Short 'n sweet, look forward to trying it out.  Could be adapted to other actuators too, am ordering another Arduino as soon as my project for day job is done.
Logged

Pages: [1]   Go Up
Jump to: