I don't know if this is the write category to post this but I didn't find anyone that is closer to my question...
As written in the title I have an arduino Uno with a WiFi shield on. I also connected an LCD on pins nr 9,8,6,5,3,2 and a servo to A0
What I am experiencing is that wifi losses connection if I use servo.write() int the loop().
Here is the code:
#include <Servo.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <WiFi.h>
LiquidCrystal lcd(9,8,6,5,3,2);
// create an instance of the servo library
Servo myServo;
char ssid[] = "HOL ALU WLAN"; // your network SSID (name)
char pass[] = "1a8b17137c"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
char readString[100];
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(1,OUTPUT);
myServo.attach(14);
myServo.write(0);
lcd.begin(16,2);
lcd.clear();
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
lcd.print("CONNECTING...");
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(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();
// you're connected now, so print out the status:
printWifiStatus();
lcd.clear();
lcd.print("CONNECTED");
// move the servo to the unlocked position
lcd.setCursor(0,1);
IPAddress ip = WiFi.localIP();
lcd.print(ip);
}
void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
int i=0;
int starting=-1;
int ending=-1;
while (client.connected()) {
if (client.available()) {
char c = client.read();
//Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if(i<99) {
//store characters to string
readString[i]=c;
if(c=='=' && starting <0) starting=i;
if(c=='&' && ending <0) ending=i;
i++;
}
if (c == '\n' && currentLineIsBlank) {
String speeda="";
for(int j=starting+1;j<ending;j++){
speeda+=readString[j];
}
int angle=speeda.toInt();
if(starting>0 & ending>0){
myServo.write(angle);
Serial.print("\nSPEED: ");
Serial.println(speeda);
Serial.print("\n");
client.println(angle);
}
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
readString[0]='\0';
}
if ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
}
}
if I comment the line " myServo.write(angle);" wifi doesn't disconnect.
I am using the 1.02 version (as u know the newer versions have problem with the wifi shield)
Does anyone has a clue on what's wrong?
Thanks in advance