Hej,
Zajmuję się projektem na studia, który na celu ma kontrole servo poprzez web server postawiony na Arduino Uno razem z Wifi Shield. Posiadam Arduino Uno, Wifi Shield i Tkiner Kit'a spięte razem. Korzystam z Arduino IDE w wersji 1.6. Wersja firmware'a na Wifi Shield to 1.1.0.
Problem mam z samą kontrolą mechanizmu servo poprzez naciśnięcie przycisków na stronie która działa na web server'ze. Początkowo udało mi się zrobić tak aby servo obracało się ale tylko w jedną stronę, naciśnięcie drugiego przycisku który miał spowodować obracanie serva w drugą stronę nie działało. W tym momencie jestem na etapie, że servo nie obraca się w żadną stronę.
Poniżej udostępniam kod.
Zajmuję się projektem na studia, który na celu ma kontrole servo poprzez web server postawiony na Arduino Uno razem z Wifi Shield. Posiadam Arduino Uno, Wifi Shield i Tkiner Kit'a spięte razem. Korzystam z Arduino IDE w wersji 1.6. Wersja firmware'a na Wifi Shield to 1.1.0.
Problem mam z samą kontrolą mechanizmu servo poprzez naciśnięcie przycisków na stronie która działa na web server'ze. Początkowo udało mi się zrobić tak aby servo obracało się ale tylko w jedną stronę, naciśnięcie drugiego przycisku który miał spowodować obracanie serva w drugą stronę nie działało. W tym momencie jestem na etapie, że servo nie obraca się w żadną stronę.
Poniżej udostępniam kod.
Kod:
#include <SPI.h>
#include <WiFi.h>
#include <Servo.h>
char ssid[] = "myNetwork"; // your network SSID (name)
char pass[] = "password"; // your network password
int keyIndex = 0;
Servo myservo;
int pos = 0;
String readString;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Serial.begin(9600); // initialize serial communication
myservo.attach(11);
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true); // don't continue
}
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin(); // start the web server on port 80
printWifiStatus(); // you're connected now, so print out the status
}
void loop() {
WiFiClient client = server.available(); // listen for incoming clients
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Projekt Komputeryzacja Pomiarow</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Projekt</H1>");
client.println("<br />");
client.println("<H2>Arduino with WiFi Shield</H2>");
client.println("<br />");
client.println("<a href=\"/?left\"\">Ruch do przodu</a>");
client.println("<a href=\"/?right\"\">Ruch do tyłu</a><br />");
client.println("<br />");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
client.stop();
if (readString.indexOf("?left") >0){
for(pos = 0; pos < 180; pos += 3)
{
myservo.write(pos);
delay(15);
}
}
if (readString.indexOf("?right") >0){
for(pos = 180; pos>=1; pos-=3)
{
myservo.write(pos);
delay(15);
}
}
readString="";
}
}
}
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}