Go Down

Topic: Wifi only connects when connected to Arduino with serial monitor. (Read 6034 times) previous topic - next topic

tigerstripe40

I just got an Arduino wifi shield.
I am using my Arduino to monitor temps for a brew mashing setup and using the wifishield to transmit the temps and post to a web page.
When I view the serial monitor, the arduino connects to the wireless network and then posts the temp. However, when I do not connect via serial monitor, it drops the connection and does not post the temperatures.

I used the wifi web server example code -I noticed that it didn't work without some modification. I need to clean up some of the stuff that has been commented out.

Here is my code.

Code: [Select]
#include <SPI.h>
#include <WiFi.h>
#include <OneWire.h>

char ssid[] = "network name";      // your network SSID (name)
char pass[] = "password";   // your network password
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
int deltaTemp = 0;

int status = WL_IDLE_STATUS;

WiFiServer server(80);
OneWire ds(DS18S20_Pin);

void setup()
{
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
 
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD)
  {
    Serial.println("WiFi shield not present");
    // don't continue:
    while(true);
  }

  // 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:
    byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
    delay(10000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
}


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;
    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 (c == '\n' && currentLineIsBlank)
       // {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<body>");
            client.println("Welcome to Yoyodyne Propulsion Systems brew temp monitor");
            client.println("<br />"); 
            client.print("Current Temp ");
              float temperature = getTemp();
              float tempF = temperature * 1.8;
              tempF += 32;
            client.print(" is ");
            client.print(tempF);
            Serial.println(tempF);
            client.println("<br />");     
         //}
         client.println("</body>");
          client.println("</html>");
           break;
        // curly brace here?
        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");
}

}  // where is matching?
 
float getTemp(){
  //returns the temperature from one DS18S20 in DEG Celsius

  byte data[12];
  byte addr[8];

  if ( !ds.search(addr)) {
      //no more sensors on chain, reset search
      ds.reset_search();
      return -1000;
  }

  if ( OneWire::crc8( addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return -1000;
  }

  if ( addr[0] != 0x10 && addr[0] != 0x28) {
      Serial.print("Device is not recognized");
      return -1000;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1); // start conversion, with parasite power on at the end

  byte present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE); // Read Scratchpad

 
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
 
  ds.reset_search();
 
  byte MSB = data[1];
  byte LSB = data[0];

  float tempRead = ((MSB << 8) | LSB); //using two's compliment
  float TemperatureSum = tempRead / 16;
 
  return TemperatureSum;
 
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


Wi11turner


tigerstripe40

Yes, WifiShield firmware has been updated to the latest version.



tigerstripe40

Possibly.
I will try it when I get home...
I bought a 5V 1 amp power supply so I could run this thing independently of a computer.
If that's not going to work, I guess I will send the PS back...

tigerstripe40

9v battery input did not make a difference.

The arduino will only connect to the wireless network if I open the serial port monitor in the Arduino IDE.
Otherwise, it does not make the connection or post the data to the web.

I guess my next step is to comment out the serial write stuff...

SurferTim

Is it the serial monitor or the usb power that starts the wifi shield working? When it fails, are you still powering the Arduino with the usb cable? Or do you have the usb cable disconnected?

If you are connecting the 5v power supply to the power jack, that is not enough voltage. It requires minimum 7 volts on Vin to work.

The 9v battery may not provide enough current to power the wifi shield. They normally take a bit over 100ma.

Have you checked the 5v pin to insure you have 5 volts there?

tigerstripe40


Is it the serial monitor or the usb power that starts the wifi shield working? When it fails, are you still powering the Arduino with the usb cable? Or do you have the usb cable disconnected?



Its opening up the serial monitor that starts things working.
I can leave the USB cable connected and it won't start transmitting/receiving until I open the serial monitor.
Then it works great.
I close the serial monitor, but leave the USB cable connected, and it drops out within 30 seconds.

sierrasmith71

Ahh..


Had the same problem. I am using a Mega1280 as the host Arduino for the WiFi shield.

I have a Webclient sketch that would connect only when the USB (useb to download and for the serial monitor)  was connected. Added an external 12v power supply and found it would not connect ( no green LED, nothing sent to the server) I found that pressing the reset a few times ( on the base Arduino or the Shield) would start it up....h'mm ....I had pins 7 and three jumper-ed as suggested somewhere. So I whet back to the drawing board and re-read : http://arduino.cc/en/Guide/ArduinoWiFiShield#toc2..there was the answer..

in the section on using the Shield with older boards...

"put a jumper in from the 3.3 V pin to the IOREF pin on the WiFi Shield..."

As there was no reference to adding a jumper from pin 3 to pin 7; I removed it. I don't remember were I found that instruction

Did that and and it now connects and functions with no USB connected and just an external power supply.

David G.

Gaithersburg MD


sierrasmith71

More on ...adding a jumper pin 3 to pin 7 on the Wifi Shield.

I found the reference to that, it's in the comments section at the bottom of :

http://arduino.cc/en/Main/ArduinoWiFiShield

Odd thing is that there is NO reference in this document to possibly needing to add a jumper from the 3.3 V pin to the IOREF pin...YIKES!!!!!

David G.

Gaithersburg MD

tigerstripe40

I've tried the 3-7 pin jumper and that didn't work either.

Another thing I have been having difficulty with, which just started, is that 1 of my machines (windows 7 ultimate) isn't recognizing the COM port the Arduino is emulating. When I load up the IDE, and click on tools, serial port is greyed out. And I cannot for the life of me get the computer to recognize it any more.

This happened after the arduino and wifi shield got wet (water was leaking in through a badly sealed window and the arduino got wet.
I cleaned up the corrosion and dried the parts using some isopropyl alcohol. Put it back together and connect it to my Laptop (MacOS X 10.8.4) and the arduino connects and I can see it with my serial monitor. When I put it on the windows 7 machine, nothing....

jacksons

Windows 7 machines have problems like that a lot. Possibly for another topic?

liuzengqiang

Strange thing about the IOREF. I swear I saw a wifi schematic in which the IOREF is not connected to anything. I can't open their EAGLE file. My EAGLE version must be too old.
What I found out that may be relevant to you is that older boards such as MEGA 2560 or 1280 (not REV3 stuff) will fail to recognize wifi or sd card upon opening the serial monitor and take forever to start up after the monitor is opened. But a press on the reset key may help. The power could be an issue but a 9V 1A AC adapter should solve it.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

sierrasmith71

The IOREF line connects to pin 19 of IC 4/2  a TXB0108 octal level shifter, see .pdf at :

http://arduino.cc/en/uploads/Main/arduino-wifi-shield-schematic.pdf


David G.

sierrasmith71

Really odd this IOREF  connection. After having a look at the schematic and the instructions* for the connection required if you are using a non R3 pinout board.... I became more confused.. As it appears that connecting 3.3 volts to IOREF causes NO level change as pin 19 is the B side VCC pin (connection to the Arduino pins). The instructions [copied below] suggest that one can make a permanent connection by soldering a jumper on the shield ...looking at the schematic reveals that this connects 5 Volts to the IOREF pin!!  Huh????

Seeing that, I tried jumping  3.3V or 5.0V to IOREF and found both worked....Ah,  I love electronics.

In any case, if a jumper is NOT installed when using a non R3 Arduino the shield will not work properly. 


*"Using the Shield With Older Boards
If you are using the WiFi shield with an Arduino earlier than the Uno rev3, you need to make the connection below for the board to work. The WiFi board uses the IOREF pin on newer Arduino pin layouts (Uno rev3, Mega2560 rev3, and later) to sense the reference voltage for the I/O pins of the board to which it is attached. If you are using the shield with an older board, you need to connect the shield's IOREF pin to 3.3V. You can do this either with a jumper wire connecting IOREF to 3.3V as shown in the photo below, or by soldering the IOREF jumper on the bottom of the shield, shown below. WARNING: If you use the solder jumper, do not connect the shield to a rev3 or later board. To be safe, remove the IOREF pin on the shield. Otherwise, you will be shorting 3.3V to 5V through the IOREF pin."


David G.

Go Up