Hi there!
I'm currently trying to implement a Wifi-controlled robot, using the official Arduino wifi shield bound to an Arduino UNO R3. A computer is supposed to send a one char instruction to be executed by the Arduino under the form of orders sent to 2 servos. The pure wifi part of the connection works like a charm.
Unfortunately, it seems, as several topics on this forum suggest it, that the ability to connect is rather random. I can get this to work once or twice between two initialization sequence, with the Arduino acting either as a client or as a server but whatever the configuration, all this stops working after a few seconds. It looks like the wifi shield stops responding as if it was hung forever until the next reset.
I tried maintaining a continuous TCP connection and opening/closing the connection whenever needed (every second) but neither seem to work reliably. After a few seconds, the packets seem to be lost (as a Wireshark analysis shows). No ACK coming from the Arduino.
- Did someone get something working reliably using some similar configuration (two servos on pins 5 and 6)?
- Would there be some usable alternative for such use case? If so what would you, guys, advise? Another wifi module? Another class of wireless device (bluetooth, zigbee...)?
Many thanks in advance for your guidance. May you have any further questions, feel free to ask. I can post the code I use on the computer side if this helps.
Benoît
Below, an excerpt of my code :
const int srv1 = 5;
const int srv2 = 6;
const int SERVO_ZERO = 94;
Servo servo1;
Servo servo2;
void setup()
{
// initialize serial:
Serial.begin(9600);
servo1.attach(srv1);
servo1.write(SERVO_ZERO);
servo2.attach(srv2);
servo2.write(SERVO_ZERO);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// you're connected now, so print out the status:
printWifiStatus();
}
void loop() {
Serial.println("connecting...");
if (client.connect(server, port)) {
Serial.println("connected");
}
else {
// if you couldn't make a connection:
Serial.println("connection failed disconnecting");
client.stop();
}
while (client.available()) {
char c = client.read(); // Read only one char
processChar(c);// Mostly sending orders to the servos, nothing rocket-science here
client.flush();
Serial.println("disconnecting");
}
delay(1000);
}