empowering creative people

Wi-Fly with Feather Boards

I’ll level with you; the idea of microcontrollers and wireless networks was a little daunting to me initially. How on earth was I going to connect and control it with Wi-Fi?! But when I eventually I waded into the world of networking microcontrollers, and the fog began to clear, and I realized how simple our friends over at Adafruit and Arduino had made it! In the hopes of averting similar learning curve crisis’, we’ve decided to create a quick guide that shows you how to connect to a wireless network with Adafruit’s Feather Board.

board-management-gif

The first thing we will need to do before we get to that point, though, is to initialize our Feather board to our IDE, the process is just like any other board. We will connect it to the PC, download the relevant board information, install the specific board drivers and select the board from the Tools > Boards menu. For the M0 Feathers, we will need to install the Adafruit SAMD21 Boards, for the 32u4 Feathers we will need the Adafruit AVR Boards files.

Adafruit Board Manager Link for IDE: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json

Then install the drivers from Adafruit to make sure your PC supports your board. Download from here.

You might need to restart your IDE once you’ve installed all these new features. That’s it for the installation and initialization of our M0 Wi-Fi Feather. Now we can look at programming with it.

The Official Arduino Wi-Fi101 Library

The ATWINC5000 Wi-Fi Module that we are using with our M0 Feather has an official Arduino library to support all the normal operations in the IDE. Go ahead and grab that with using the Library Manager (Search WiFi101 in the Libraries Manager). Now it’s as easy as entering the SSID and Password of your network to connect and provides a sensible list of functions users can call upon to perform standard wireless functions like Scanning networks, Ping, etc. Check out Arduino’s Reference Pages for the Library here.

To use the Wi-Fi library, you’ll need to include it in your sketch and use the setPins command to connect your Wi-Fi module to pins on your feather.

#include WiFi101.h
#include SPI.h
WiFi.setPins(8,7,4,2); //Configures the four pins that are used for SPI communication with the wireless module.

We’re just going to write a little program that will connect our Feather up to our local network today; it will output the process to the serial monitor. There’s a handy function available to us that can return many different statuses’ of the Wi-Fi module.  WiFi.status() //This will return one value back to the program Values returned from the Status check can be:

  • WL_CONNECTED: assigned when connected to a Wi-Fi network;
  • WL_NO_SHIELD: assigned when no Wi-Fi shield is present;
  • WL_IDLE_STATUS: it is a temporary status assigned when WiFi.begin() is called and remains active until the number of attempts expires (resulting in WL_CONNECT_FAILED) or a connection is established (resulting in WL_CONNECTED);
  • WL_NO_SSID_AVAIL: assigned when no SSID are available;
  • WL_SCAN_COMPLETED: assigned when the scan networks are completed;
  • WL_CONNECT_FAILED: assigned when the connection fails for all the attempts;
  • WL_CONNECTION_LOST: assigned when wireless connection is lost;
  • WL_DISCONNECTED: assigned when disconnected from a network;

Before our module tries to connect to our network, we should make sure that our module is connected to our processor. We can do that with an if statement too:

If (WiFi.status == WL_NO_SHIELD){
Serial.println(“Your wireless module isn’t connected!”); //let a user know the Wi-Fi module isn’t talking with their processor
Delay(1000); //wait 1 second
}

Now we can use the same function to know whether our module is connected to any networks and perform and action if it isn’t. We will set our program to run whilst the value WL_CONNECTED is not returned; we can do this with an If statement and the not equal to comparator (!=).

If (WiFi.status != WL_CONNECTED) //if you aren’t connected to a network and your SSID is available, connect to it!
{   
Serial.println(“Attempting to connect to your Wi-Fi network”);
WiFi.begin(SSID, pass); //now we can either pass our SSID and password directly to our program, or we could have set Char variables at the beginning of our program
}

All together that code will look like this:

#include 
#include 

char ssid[] = "yourNetwork";     //  your network SSID (name)
char pass[] = "secretPassword";  // your network password

void setup() {
  Serial.begin(9600);
  
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println(“Your wireless module isn’t connected!”);
    Delay(1000); //wait 1 second   
  }
}

void loop() {
  If (WiFi.status != WL_CONNECTED)    //if you aren’t connected to a network and your SSID is available, connect to it!
{    
        Serial.println(“Attempting to connect to your Wi-Fi network”);
        WiFi.begin(ssid, pass); //now we can either pass our SSID and password directly to our program, or we could have set Char variables at the beginning of our program
}
  If (WiFi.status == WL_CONNECTED)
{
        Serial.println(“You are now connected to the network”);  
}

}

You can also view the WiFi101 Examples in the IDE to see the use of other operators from the WiFi101 library

That’s how simple it is to connect your Feather to your Wi-Fi! The serial monitor will reflect where your module is up to in the program!

I’ll level with you; the idea of microcontrollers and wireless networks was a little daunting to me initially. How on e...

Have a question? Ask the Author of this guide today!