Go Down

Topic: Blink and LED while WiFi not Connected (Read 628 times) previous topic - next topic

Kernel Panic

Hi Guys,

I have a nice working project and I'm looking to add a little flash to my visual feedback.  While the Arduino (WiFi Shield) is connecting to the network via the while loop,

Code: [Select]
while (status != WL_CONNECTED)...

I want to have an LED blink.  Once it's connected, I want the LED to go solid.  Right now, I just have the LED turn on once it's connected.  How can I blink an LED during this connection process?  Is it possible?  Do I have to implement an interrupt?  That's new territory for me.

Thanks in advance
--
Never argue with an idiot.  They will drag you down to their level and beat you with experience.

Arrch

Take a look at the blink without delay example and add that into your while loop.

Kernel Panic

Thank you for your reply.  After reading the blink without delay page, I'm not sure that will apply here because the code waits for a connection before it does anything.

Code: [Select]

// Attempt to connect to WiFi network.
  while (status != WL_CONNECTED) {
    Serial.println("WiFi Shield Online");
    Serial.println();
    Serial.print("Connecting to ");
    Serial.print(ssid);
    Serial.println(" Network ...");
    //status = WiFi.begin(ssid, keyIndex, key);  // WEP
    status = WiFi.begin(ssid, key);  // WPA/WPA2
   
    // Blink networkPin until connection is established.
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis > interval) {
      previousMillis = currentMillis;
      if (ledState == LOW) {
        ledState = HIGH;
      } else {
        ledState = LOW;
      }
      digitalWrite(networkPin, ledState);
    }
   
    //tenCountDot();
    //delay(10000);  // Wait 10 seconds for WiFi to connect.
  }


I tried putting the blink code both in before and after the status = WiFi.begin() statement.  No difference.  What am I missing?
--
Never argue with an idiot.  They will drag you down to their level and beat you with experience.

Nick Gammon

Post all your code? What is interval?

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Arrch


I tried putting the blink code both in before and after the status = WiFi.begin() statement.  No difference.  What am I missing?


If WiFi.begin() is blocking, then you either need to use a timer interrupt, or rewrite the WiFi.begin() code.

Kernel Panic

@Nick:  My code is over 400 lines and on several tabs.  The interval is 1000 as in the blink without delay example.

@Aarch:  I figured it would end up an interrupt situation.  Not afraid of them just not familiar with them.  As far as rewriting the WiFi.begin() function, I haven't thought about it as it's the original library released with 1.0.3.

Any ideas how to blink the LED in the background until the WiFi.begin() function completes?

Thanks in advance for all your help.



PS: Shameless plug: MUSHClient rocks!!   :D
--
Never argue with an idiot.  They will drag you down to their level and beat you with experience.

Arrch

Check out the TimerOne library; It's pretty simple to use.

UKHeliBob

This works for me
Code: [Select]
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>

boolean status = false;
boolean ledState = true;
int ledPin = 8;
int interval = 1000;
long previousMillis = 0;
long currentMillis;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
  while (status != WL_CONNECTED)
  {
    status = WiFi.begin("foo","bar");
    currentMillis = millis();
    if (currentMillis - previousMillis > interval)
    {
      previousMillis = currentMillis;
      ledState = !ledState;
      digitalWrite(ledPin, ledState);   
    }
  }
}

void loop(){}


NOTE 1
I do not actually have a WiFi shield so all bets may be off

NOTE 2
The WiFi library appears to stop some pins acting as digital outputs, notably pin 13, but it may affect others.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


@Nick:  My code is over 400 lines and on several tabs.  The interval is 1000 as in the blink without delay example.


That's nothing. You can zip them up and make an attachment.

How to use this forum
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up