NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Control relay via Internet - Help
April 25, 2009 by Domeniko |
Hy, my idea is to make with Nerdkit, project like iPhone controlled R/C car, but this is going to control one pin (or more of them) on MCU that is connected with relay that tur on/off lamp or something else.
output scheme that is connected to pin of MCU, hope that is fine. After installing Apache Webserver I should put files on-off.php and I call it on-offVector.php in root folder C:Program FilesApache Software FoundationApache2.2htdocs (is this the right one?) On-off.php file that I make (not finished) with Adobe Dreamweaver: i don't know how to make when someone click on button ON to write number 1 to pipe.txt file, also when click on button OFF write number 0 to pipe.txt file that is used to send information from on-off.php to Nerdkit. I think I need also a phyton file that communicate with NerdKit... <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>On-off</title> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> // pipe.txt; //on button clicked send 1; //off button clicked send 0; </head> <body> <p align="center">Relay on-off</p> <p align="center"> </p> <p align="center"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0','width','131','height','85','src','button3','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','button3' ); //end AC code </script><noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="131" height="85"> <param name="BGCOLOR" value="" /> <param name="movie" value="button3.swf" /> <param name="quality" value="high" /> <embed src="button3.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="131" height="85" ></embed> </object> </noscript> </p> <p align="center"> <script type="text/javascript"> AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0','width','131','height','85','src','button4','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','button4' ); //end AC code </script> <noscript> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="131" height="85"> <param name="BGCOLOR" value="" /> <param name="movie" value="button4.swf" /> <param name="quality" value="high" /> <embed src="button4.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="131" height="85" ></embed> </object> </noscript> </p> </body> </html> On-offVector.php <?php $x = $_GET["x"]; // whrite 0 or 1 to pipe.txt file //Open pipe and write some text to it. //Mode must be r+ or fopen will get stuck. $pipe = fopen('C:UsersdomenikoDesktoppc_codepipe.txt','r+'); fwrite($pipe,$x); fclose($pipe); ?> Program for MCU should be something like: include <stdio.h>include <avr/io.h>include <avr/interrupt.h>include <avr/pgmspace.h>include <inttypes.h>include "../libnerdkits/delay.h"include "../libnerdkits/uart.h"int main() { //set PB3 as output DDRB |= (1<<PB3); While(1){ If ( read from pipe.txt 0 or 1)
} Return 0; } Make file is not a problem :) What about python file? Well, this is it. Hope we are going to make it work... PS: Sorry for spelling because english is not my mothertang language :) |
---|---|
April 26, 2009 by mrobbins (NerdKits Staff) |
Hi Domeniko, I think you are on the right track, although on Windows, you may not be able to use "named pipes" for communication between the PHP script and the running Python process. Instead, you might want to look into using TCP/IP sockets, as these are totally cross-platform and aren't too much more complicated. Our LED Marquee project uses sockets, and may help point you in the right direction. Looking forward to seeing your progress! Mike |
May 06, 2009 by kwiegand |
Domeniko, You might want to look at this php class for serial port communication: http://www.phpclasses.org/browse/package/3679.html. -Kerry |
Please log in to post a reply.
Did you know that you can control 120 LEDs with just 17 microcontroller pins? Learn more...
|