[Solved] On Board LED - Pin D7 -- Can't seem to get it turned ON

Hello,

So I got this line of code in my void setup():

  if (WiFi.ready()){
    digitalWrite(HB, HIGH);
  }

and for some reason it just won’t turn on the on-board LED … What am I doing wrong? :frowning:
When I click the RST button it seems to turn on the LED, but other than that, nothing.

@UST, the onboard LED is on pin D7 so I am assuming that you have set D7 as an output and that HB has been set to D7 either as int HB = D7; or as #define HB D7. Is this correct? :smile:

Hey @peekay123 !

Yes, so sorry forgot I left it as HB , I have it as

const int HB = D7;

@UST, in your setup() do you have pinMode(HB, OUTPUT); which will set D7 and an output so you can control the LED? Without that you will get a whole lot of nothing on the LED :wink:

@UST, perhaps that is because you only do a single test of WiFi.ready() in setup and the wifi may NOT be ready at that point!! :smile:

BAM! I do have it :stuck_out_tongue:

This is why I am out of ideas, I’m not sure what I could be doing wrong D:Maybe something to do with the “WiFi.ready()” ??

void setup()
{
pinMode(HB, OUTPUT); // sets the pin as output
Serial.begin(115200);
if (WiFi.ready()){
digitalWrite(HB, HIGH);
}
}

this is true !!!

Let me put it in my loop and give it a whirl

@UST, what are your trying to do exactly cause the onboard color LED will you show you the status of the LED. Do you want to wait for wifi to be ready or simply show its status? You could put it in a loop which also includes a timeout (eg 5 seconds) if that is more appropriate.

I’m trying to create a status signal, “if WiFi is ready set HIGH, if off set LOW, if going from LOW to HIGH do somethng”

So I happen to be using D7 for this operation and I remembered D7 controls the onboard LED, so I figured it would serve as a great indicator as well, LED ON = WiFi ON etc etc :slight_smile:

Actually if you want to know if you can work the LED, then just try setting it without the if statement.
As @peekay123 suggested only testing WiFi.ready() once, might not give you the expected result.

Edit: Oops, maybe I was a bit late with that reply :wink:

But if you expect WiFi status to change while your sketch is running, what SYSTEM_MODE are you running at?

1 Like

An interesting result happened:

I put:

   if (WiFi.ready()){
digitalWrite(HB, HIGH);
}

Inside my main loop, then I put my Core into listening mode, I used PuTTY to give the Core my internet credentials and bingo, once it connected to WiFi the LED was on and brighter then I’ve ever seen it before.

But then I hit RST button to disconnect the WiFi and sure enough the LED turned off with it, but once the Core connected back to the WiFi the LED did not turn on, the Core has been back with WiFi since I’ve created this reply, but the LED still hasn’t turned back on ! :frowning:

I like to write code that blinks the D7 LED to let me know my loop() is executing, and by changing the flashing rate you can know if different things are happening. Try this code:

void loop() {
  if (WiFi.ready()) {  // blink slow if Wi-Fi is ready
    digitalWrite(HB, HIGH);
    delay(500);
    digitalWrite(HB, LOW);
    delay(500);
  }
  else { // blink fast if Wi-Fi is not ready
    digitalWrite(HB, HIGH);
    delay(100);
    digitalWrite(HB, LOW);
    delay(100);
  }
}

Now if that works, obviously you’d want to use the millis() timer and some counters to manage the delays instead of hard delays (to keep your loop() executing as fast as it can), but we can cross that bridge when we get there :wink:

1 Like

I was JUST writing a reply to tackle the very same issue, thank you very much BDub, I’ll slap this code in and get back to you ASAP :wink:

1 Like

Alright, so this is what I got going on, and STILL to no avail, no blinking LED. I even took out the while loop statement, and tried it but still, no LED functionality, there has to be something fundamental I am missing :frowning:

void setup()
{
  Serial.begin(115200);
  while (!Serial.available()) {   //this is just for testing with Serial
    SPARK_WLAN_Loop(); }
  pinMode(HB, OUTPUT); // sets the pin as output
 }

void loop()
{
     if (WiFi.ready()) {  // blink slow if Wi-Fi is ready
    digitalWrite(HB, HIGH);
    delay(500);
    digitalWrite(HB, LOW);
    delay(500);
    Serial.println("WiFi ON");
  }
  else { // blink fast if Wi-Fi is not ready
    digitalWrite(HB, HIGH);
    delay(100);
    digitalWrite(HB, LOW);
    delay(100);
    Serial.println("WiFi OFF");
  }
}

UPDATE: I even threw in a Serial.print statement at the end of the loop just to see if she was printing it and nooothing. So now I think it’s something else; gonna try the BLINK LED example and see if I can get that working.

So … Got the LED example to work flawlessly … but not my code, there has to be something fundementally different, I’ll take a look post my results as soon as I find anything out.

Thanks again for the help guys @BDub @peekay123 and @ScruffR

EDIT: Even tried taking out the IF statements, still nothing, checked the rest of my code, still not sure what is up … the Blink LED example works though … which is odd.

@UST, post the code you are trying to get working :stuck_out_tongue:

When you use this code, it’s really for Windows machines… basically what it does is sit there is a loop forever waiting for you to connect your Serial monitor and send a character (i.e. press ENTER or SPACEBAR) Then your code will run.

This is the code I’m trying to get executed. I’m not sure what I’ve missed.

I have successfully got the LED Blink example to work, and I’ve even just tacked on a “if(WiFi.ready())” statement on that example code and I got it to work. I dunno @peekay123 I’m feeling spent >_<

    const int HB = D7; 
    
    void setup()
    {
      pinMode(HB, OUTPUT); // sets the pin as output
      Serial.begin(115200);
      while (!Serial.available()) {   //this is just for testing with Serial
        SPARK_WLAN_Loop(); }
    
      SyncTime(); 
    }
    
    void loop()
    {
    if (WiFi.ready()){  //or !WiFi.connecting() [seems equivalent to me] 
    digitalWrite(HB, HIGH);
    delay(1000);
    digitalWrite(HB, LOW);
    delay(1000);
    Serial.print("WiFi ON");
    }
    else {
    digitalWrite(HB, HIGH);
    delay(100);
    digtalWrite(HB, LOW);
    delay(100);
    }
    }
oid SyncTime(){
Spark.connect();
while(Spark.connected() == false) {
 delay(100);
}
while(Time.year()<=1970)
{
Spark.syncTime();  
Spark.process();
delay(100);
}
//Spark.disconnect();
/*while(Spark.connected() == true) {
delay(100);
}
*/
Time.zone(-5); //sets UTC to EST 
}

I realized that too, so I tried it without as well, but still with no avail … actaully wait … one sec !

@BDub you totally reminded me that I did change something in my SyncTime function, which was making things run forever, NOW taking out the Serial wait statement things run cleanly!!! Gah, I feel like a fool ! But thank you so much everyone :smiley: !

2 Likes