2

I am trying to use the WiFly shield ( http://www.sparkfun.com/commerce/product_info.php?products_id=9367) with Aduino Mega board.

I am making modifications to the built in examples that ship with the WiFly. I have modified the sketch to make an http request to my personal server.

When I run the sketch through the USB port attached to my laptop, everything works fine. I can see the requests arriving at my remote machine.

When I try to run the board independently using batteries, I run into issues. Basically, the code in the "setup()" doesn't seem to be running. If I do a reset on the board by pressing and holding the push button on the Arduino Mega board, it also works fine. This proves that there is no error in the Sketch or back end server and that the hardware is also not broken.

So basically, when I start up the board via the first start up from a battery power source, it doesn't work. But subsequently resetting of the board using the power button on the mega seems to work.

Does anyone know why this is caused and how I can start running my sketch as soon as the battery pack is turned on (rather than having to do a subsequent reset?)

I had a look at the Arduino trouble shooting guide here http://arduino.cc/en/Guide/Troubleshooting2 and tried connecting the RX pin to the TX pin as well as connecting the Rx pin to GND via a 10k resistor. This doesn't help either.

Edit

I am running the sample WiFly sketch provided by Sparkfun from here. I changed the URL in the sketch from google.com to myserver.com and it works fine when running via USB connection to the laptop or after a reset. I have since added a 2000ms delay as suggested in the answer by kmort and that seems to work fine now. So it would seem there are "settling down issues" with the shield.

Chaitanya
  • 435
  • 1
  • 7
  • 15
  • 2
    Could you share the code with us? It's hard to tell what's wrong without it. Maybe there are calls in setup() that are returning errors that are being ignored. – Ricardo Jan 09 '14 at 14:58
  • Put some LED toggle in before the Ethernet initialization and do you get them before the lockup? With and or without the shield. Does normal (blink.ino) work off of battery, correctly? With and or without the Ethernet Shield attached. – mpflaga Jan 09 '14 at 19:03
  • Updated the question accordingly. – Chaitanya Jan 11 '14 at 06:47
  • Any proper library for that shield should have an initialization function that waits for the thing to boot up and then returns a code indicating the ready state of the device. You might need to look for a better library - the ones provided by Sparkfun and AdaFruit aren't really intended for "production" code. OMG, why is SO showing me these old questions as "hot" ? – Jasmine Jun 30 '14 at 17:58

2 Answers2

4

When power is first applied, any values you read could be crazy, and are certainly suspect.

Are you making any decisions based on reading values in setup()? If so, it could it be that the rest of your circuit has not settled down yet, and you get interesting bugs because of it.

Try a delay() in your startup() and see if the problem goes away.

kmort
  • 862
  • 1
  • 7
  • 12
1

In review of the schematic I see two possible causes:

  1. Your battery is not above 7.0Vdc, causing an erratic start that leads to a brown-out lockup. Or,

  2. The RC delay of the RESET is too weak. \$2 \times \pi \times 22pF \times 10K\Omega\$ is only \$1.3 \,\mu s\$ and the spec for reset is \$2.5 \,\mu s\$ minimum. Placing 1nF (aka 1000pF) across the shields RESET pin and GND will slow initial release of RESET some 50 times that of the DTR's 100nF from the FTDI.

However, the shield adds 100nF and 10K in parallel to each, respectively, which should make the delay sufficient (about \$0.5 \,ms\$). So there may be a problem with the shield.

Scott Seidman
  • 29,274
  • 4
  • 44
  • 109
mpflaga
  • 1,345
  • 6
  • 10
  • please describe the battery. is it possible to add another 1.5V cell, to get voltage above 7.0 minimum – mpflaga Jan 09 '14 at 19:19
  • This also turned out to be an issue later on. The shield does seem to take a lot of power and runs down the battery quickly. – Chaitanya Jan 11 '14 at 06:49