我想用SD卡从Ethernet Shield控制伺服电机? [英] I want to control a Servo motor from Ethernet Shield using SD Card?
本文介绍了我想用SD卡从Ethernet Shield控制伺服电机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello Guys!
我正在练习使用我的Arduino Ethernet Shield进行我想做的项目,它包括从互联网上控制伺服电机,我的SD卡上有一个html代码
Hello Guys!
I Was Practicing with my Arduino Ethernet Shield for a Project i wanted to do and it consists of controlling a servo motor from the Internet, I had a html code on my SD Card
#include <spi.h>
#include <ethernet.h>
#include <servo.h>
#include<sd.h>
Servo myservo;
byte mac[] ={0xDE, 0xAD, 0xBB, 0xEF, 0xFE, 0xED};
IPAddress ip(10,150,40,84);
IPAddress gateway(10,150,40,1);
IPAddress subnet(255,255,255,0);
EthernetServer server(80);
File webFile;
int pos =10;
String redString;
void setup(){
myservo.attach(9);
myservo.write(pos);
Serial.begin(9600);
pinMode(4,OUTPUT);
Ethernet.begin(mac,ip,gateway,subnet);
Serial.print("My Ip is : ");
Serial.println(ip);
server.begin();
//Init SD Card
if(!SD.begin(4)){
Serial.println("ERROR - Initialization Failed!");
return;
}
Serial.println("SUCCESS -SD card Initialized.");
if(!SD.exists("securino.htm")){
Serial.println("ERROR - Can't find securino.html");
}else{
Serial.println("SUCCESS - Found securino.html.");
}
}
void loop(){
EthernetClient client = server.available(); // try to get a client
if(client){ // got a client
boolean currentLineIsBlank = true;
while(client.connected()){
if(client.available()){// client data avail to read
char c = client.read();// read 1 byte char from client
// last line of client req. is blank and ends with \n
// respond to client only after last line recieved
if(redString.length()<100){
redString+=c;
}
if(c="\n" && currentLineIsBlank){
Serial.println(redString);
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type:text/html");
client.println("Connenction:close");
client.println();
// send Web page
webFile = SD.open("securino.htm");//open webpage
if(webFile){
while(webFile.available()){
client.write(webFile.read());// send webpage to client
}
webFile.close();
}
break;
if(redString.indexOf("?turnlft")>0){ // PROBLEM HERE ****
pos = pos -10;
myservo.write(pos);
}
if(redString.indexOf("?turnrght")>0){ // AND HERE ****
pos = pos +10;
myservo.write(pos);
}
redString ="";
}
//every line of text recieved from client ends with \r\n
if(c=='\n'){
//last char on line of recieved text
//starting new line with next character read
currentLineIsBlank = true;
}
else if(c!='\r'){
//a text character was reciever from client
currentLineIsBlank = false;
}
}
}
delay(1); // give the browser time to recieve the data
client.stop();
}
}
<pre lang="c++">
and Here is the HTML Code, I Think the Problem lies Here Could you Help me
This are the Two Link i used to Control the Motor
..........
<a href="\"/?turnlft\"\"">Turn Left</a>
<a href="\"/?turnrght\"\"">Turn Right</a>
推荐答案
1。你有混合client.write和client.println调用,你在发送html代码(正文)之前关闭连接
2.找到一个http客户端和url解析库为arduino确保redString 包含请求网址。我怀疑你的client.read方法是否有效!
3.调试你的http流量。
1. you have mixed client.write and client.println calls and you are closing the connection before sending the html code (body)
2. find a http client and url parsing library for the arduino to ensure "redString" contains the request url. I doubt your client.read method works!
3. debug your http traffic.
这篇关于我想用SD卡从Ethernet Shield控制伺服电机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文