Arduino Mega 2560 + Xbee Shield + WifiBee + WiflyHQ = ERROR!

Hi everybody,

I write this because i do not have any idea about how to solve it!... :fearful:

This is the situation, i'm trying to program a Wifi whield on arduino mega 2560, the WfifiBee by Tinyshine with a Xbee Shield by SainSmart on an Arduino Mega 2560. Using the library of WifliHQ...

When i try to do it i get an error, it seams that the arduino and xbee shield uses the same pin serial ports to comunicate, so i try to change the xbee shield serial port with the software: SoftwareSerial.h... But i cant find the solution! :frowning:

The Xbee Shield its working because i have programed from the console, so i can send a PING from a computer to the arduino and it responds , but i would be able to setup, control and use the configuration of the wifi shield from arduino...

Using any example from the library WIFLYHQ i get the same error: Result doing it with the HttpClient example:

Starting
Free memory: 6708
setPrompt failed
Failed to enter command mode
Failed to start wifly

The example code:

/*
 * 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(8,9);

//#include <AltSoftSerial.h>
//AltSoftSerial wifiSerial(8,9);

WiFly wifly;

/* Change these to match your WiFi network */
const char mySSID[] = "myssid";
const char myPassword[] = "my-wpa-password";

//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(115200);
    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");
    }

    //terminal();

    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());
	}
    }
}

Anybody can give some light on this darkness!!! :fearful:

P.D.: Sorry about my english!

When i try to do it i get an error, it seams that the arduino and xbee shield uses the same pin serial ports to comunicate, so i try to change the xbee shield serial port with the software: SoftwareSerial.h... But i cant find the solution! :frowning:

Why? You have 4 hardware serial ports.

http://arduino.cc/en/Reference/SoftwareSerial

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

Since you are not doing SoftwareSerial on these pins, I don't expect it to work, and you shouldn't, either.

Paul, thanx for your quick response! :grin:

Well, the first sorry to not check the notes of SoftwareSerial, i've change the ports to 10 and 11, and its not working, the same happnes with 11 and 12... so i should have some other error in my code or something...

I have tried it like that:

#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(11,12);               // and i hve tried also 10 with 11.
WiFly wifly;
...
...

The result:

Starting
Free memory: 6602
Failed to start wifly

Thanx for the help...

Why are you not using one of the other hardware serial instances?

Links to the libraries you are using?

Some questions that may be are important to be consireded:

What about the bauds to work with?
Serial.begin(9600);
wifiSerial.begin(9600);

What about the jumpers of Xbee Shield?
After upload the Sketch to the arduina do i have to change them to XBEE position, or keep it in USB Position?

... Its just to give you all the information that i have to find the problem... thanx again..

Sorry Paul,

How can i do that?

Can you write the code example for mi please?

thanx

You change them to the XBEE position.

Mark

Im here again... And im getting cracy! :astonished:

I have done all you said..

  1. After load the code to the arduino i have changed the jumpers to XBEE mode.

  2. Configured the Pins correctly: (I hope!)

#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(19,18);
WiFly wifly;
  1. This is the piece of code where you can see the config of the serials:
    Serial.begin(115200);
    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();
    }

I think the fail become in this line: wifly.begin(&wifiSerial, &Serial)

Any Idea?

  1. Configured the Pins correctly: (I hope!)

No. DO NOT DO SoftwareSerial on hardware serial pins.

Delete the SoftwareSerial include statement and the instance that you create. Use Serial1 in place of that instance.

I have try it! :drooling_face:

Sorry but does not work!

I have found this: Can't get it works with Arduino Mega 2560 · Issue #7 · harlequin-tech/WiFlyHQ · GitHub

Does it means, that i have to cut off pins 0 and 1 on the Arduino Wireless Shield to make this work?? :fearful: :fearful: :fearful: :fearful:

That says:

The Arduino Wireless Shield is pretty restricted in terms in how in connects the module's serial to the Arduino. It only connects it to the main hardware serial port (pins 0 and 1), so you would have to use that with the WiFlyHQ library. It also means you can't use the Serial Monitor for debugging since it is being used to communicate with the WiFly modules.

E.g. In your sketch do the following:

Serial.begin(9600);
wifly.begin(&Serial, NULL);

If you'd like to use another serial interface on the Mega for the WiFly and use the main one for debug output, you could cut off pins 0 and 1 on the Arduino Wireless Shield and use jumper wires to connect pin 0 on the shield to pin 19 on the Mega and pin 1 on the shield to pin 18 on the Mega and use the following code to setup the WiFly connection:

Serial1.begin(9600);
wifly.begin(&Serial1, NULL);

I can not believe it! ... shoud be an easyiest way to do it... right?

So what terminal software are using on tthe PC and how is it setup - have you connected it to the WiFly default TCP/IP address at the default baud rate?

Mark

I can not believe it! ... shoud be an easyiest way to do it... right?

You can bend the pins, rather than cutting them off. Or, ditch the shield and buy one that allows you to use other pins.

I have try it with TeraTerm (Windows 7) and CoolTerm (Mac). with the same results. Also the same results if i use the own arduino monitor serial.

The config for the terminal: 115200 baudrate / data bits 8 / parity none / stop bits 1.

And this is the configuration of my Wifi Card:

[b]<4.00> get everything[/b]
wifly-EZX Ver 4.00.1, Apr 19 2013 11:47:20 on RN-171
Beacon=102
Reboot=0
IF=UP
DHCP=OFF
IP=192.168.0.222:2000
NM=255.255.255.0
GW=192.168.0.1
HOST=0.0.0.0:2000
PROTO=TCP,
MTU=1524
FLAGS=0x7
TCPMODE=0x0
BACKUP=0.0.0.0
OPEN=*OPEN*
CLOSE=*CLOS*
REMOTE=*HELLO*
FlushSize=1420
MatchChar=0
FlushTimer=5
IdleTimer=0
CmdChar=$
DNS=8.8.8.8
Name=dns1
Backup=rn.microchip.com
Lease=86400
FTP=0.0.0.0:21
File=wifly-EZX.img
User=roving
Pass=Pass123
Dir=public
Timeout=200
FTP_mode=0x0
SSID=mywifissid
Chan=0
ExtAnt=0
Join=1
Auth=OPEN
Mask=0x1fff
Rate=12, 24 Mb
Linkmon-Infra=30
Linkmon-AP=3600
Passphrase=mywifipassword
TxPower=12
EAP_Id=userid
EAP_User=peap-user
SleepTmr=0
WakeTmr=0
Trigger=0x1
Autoconn=0
IoFunc=0x0
IoMask=0x21f0
IoValu=0x0
DebugReg=0x0
PrintLvl=0x0
LaunchStr=web_app
TimeEna=0
TIMEADR=64.90.182.55:123
Zone=7
Baudrate=9600
Flow=0x0
Mode=0x0
Cmd_GPIO=0
JoinTmr=1000
Replace=0x24
DeviceId=WiFly-EZX
Password=
Format=0x0
Signal=0
Average=5
BCAST=255.255.255.255:55555
Interval=0x7
Backup=0.0.0.0:0
Sensor=0x0
SensePwr=0x0
[b]<4.00>[/b]

Well, i dont know if to have the wifi already pre-configured with the ipconfiguration, and ready to connect to my network when arduino start its bodering to the program when try to comunicate with it.

what do you think?

thanx to all of you. :blush:

Im going to try the same Sketch but first im going to RESET FACTORY de Wifi Module...

Later on i will tell everybody the results...

:roll_eyes:

thanx

After make a FACTORY RESET in the wifi Module, and load de sketch. The results are the same... ERROR!

Those are the steps i follow to test it:
1) Set the two Xbee Shield jumpers in USB Mode.
2) Load de Sketch to the arduino.
3) Turn arduino off.
4) Change both jumpers to XBEE Mode.
5) Turn it on. (Connected to the PC by USB).
6) Open TeraTerm or CoolTerm (With the config: 9600 8 N 1).
7) Wait For the results: :frowning:

do I do anything wrong? I dont know what to try more.

Note: As you can see befero, in other posts, i use the Serial1, not use SoftwareSerial any more, so i use another serial pin for the Xbee Shield.

Well... I'll be waiting for your help, because im really stopped in this caos!. thanx a lot. :~

  1. Change both jumpers to XBEE Mode.

Which connects what to what?

As you can see in this Url: http://www.cooking-hacks.com/documentation/tutorials/arduino-xbee-shield#step5

Jumper settings:

The Xbee shield has two jumpers (the small removable plastic sleeves that each fit onto two of the three pins labelled Xbee/USB). These determine how the Xbee's serial communication connects to the serial communication between the microcontroller (ATmega8 or ATmega168) and FTDI USB-to-serial chip on the Arduino board.

With the jumpers in the Xbee position (i.e. on the two pins towards the interior of the board), the DOUT pin of the Xbee module is connected to the RX pin of the microcontroller; and DIN is connected to TX. Note that the RX and TX pins of the microcontroller are still connected to the TX and RX pins (respectively) of the FTDI chip - data sent from the microcontroller will be transmitted to the computer via USB as well as being sent wirelessly by the Xbee module. The microcontroller, however, will only be able to receive data from the Xbee module, not over USB from the computer.

With the jumpers in the USB position (i.e. on the two pins nearest the edge of the board), the DOUT pin the Xbee module is connected to the RX pin of the FTDI chip, and DIN on the Xbee module is connected to the TX pin of the FTDI chip. This means that the Xbee module can communicate directly with the computer - however, this only works if the microcontroller has been removed from the Arduino board. If the microcontroller is left in the Arduino board, it will be able to talk to the computer normally via USB, but neither the computer nor the microcontroller will be able to talk to the Xbee module.

With the shield in its correct position on the mega you must use serial not serial1.

When you open the terminal you need to connect via tcp/ip to the mega to get anything over the wifi. If you open the serial monitor in the IDE you should see a copy of everything sent to the wifi chip.

Mark

With the shield in its correct position on the mega you must use serial not serial1.

Yep. Get a real shield that allows you some control over which pins the WiFi device talks to.

Or, bend pins 0 and 1 of the shield so that they do NOT connect to pins 0 and 1 of the Mego. Jumper from pins 0 and 1 of the shield to 18 and 19 of the Mega, and use Serial1.

SOLVED!!!!

The problem was the serial to use... i mean, as Holmes4 said, i had have to use Serial and not Serial1.

With the shield in its correct position on the mega you must use serial not serial1.

Now Is working, It start, configure itself, and i can make a ping from a computer... so the network is working fine!