Hello Together,
I have a xBee Shield with a WiFIBee. On my Arduino Uno it works very well without any problem. If I try it on my Arduino Mega with exactly the same Sketch I have the following errors on my console:
Starting
Free memory: 6710
setPrompt failed
Failed to enter command mode
Failed to start wifly
The Shield is a TinySine Bee Shield V1r1 configured to normal mode with Soft Serial on MCU (small switches on the board).
The WiFiBee is a RN171 from Roving.
I use the default Sketch from WiFlyHQ. I have just changed SoftwareSerial wifiSerial(8,9);
to SoftwareSerial wifiSerial(2,3);
.
Here is the whole Sketch:
/*
* WiFlyHQ Example httpclient.ino
*
* This sketch implements a simple Web client that connects to a
* web server, sends a GET, and then sends the result to the
* Serial monitor.
*
* This sketch is released to the public domain.
*
*/
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(2,3);
//#include <AltSoftSerial.h>
//AltSoftSerial wifiSerial(8,9);
WiFly wifly;
/* Change these to match your WiFi network */
const char mySSID[] = "--";
const char myPassword[] = "--";
//const char site[] = "arduino.cc";
//const char site[] = "www.google.co.nz";
const char site[] = "hunt.net.nz";
void terminal();
void setup()
{
char buf[32];
Serial.begin(9600);
Serial.println("Starting");
Serial.print("Free memory: ");
Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println("Failed to start wifly");
terminal();
}
/* Join wifi network if not already associated */
if (!wifly.isAssociated()) {
/* Setup the WiFly to connect to a wifi network */
Serial.println("Joining network");
wifly.setSSID(mySSID);
wifly.setPassphrase(myPassword);
wifly.enableDHCP();
if (wifly.join()) {
Serial.println("Joined wifi network");
} else {
Serial.println("Failed to join wifi network");
terminal();
}
} else {
Serial.println("Already joined network");
}
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
Serial.print("IP: ");
Serial.println(wifly.getIP(buf, sizeof(buf)));
Serial.print("Netmask: ");
Serial.println(wifly.getNetmask(buf, sizeof(buf)));
Serial.print("Gateway: ");
Serial.println(wifly.getGateway(buf, sizeof(buf)));
wifly.setDeviceID("Wifly-WebClient");
Serial.print("DeviceID: ");
Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
if (wifly.isConnected()) {
Serial.println("Old connection active. Closing");
wifly.close();
}
if (wifly.open(site, 80)) {
Serial.print("Connected to ");
Serial.println(site);
/* Send the request */
wifly.println("GET / HTTP/1.0");
wifly.println();
} else {
Serial.println("Failed to connect");
}
}
void loop()
{
if (wifly.available() > 0) {
char ch = wifly.read();
Serial.write(ch);
if (ch == '\n') {
/* add a carriage return */
Serial.write('\r');
}
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
/* Connect the WiFly serial to the serial monitor. */
void terminal()
{
while (1) {
if (wifly.available() > 0) {
Serial.write(wifly.read());
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
}
Where is my fault? Do I have to change something to use it on my Arduino Mega?
I hope I will find someone who can help me, thank you.
Regards, Ralph