Hardware Reference
In-Depth Information
through the SPI bus, and communication is normally handled with a small
microcontroller, “translating” messages on the SPI bus to the network controller.
Several vendors manufacture Wi-Fi shields, and there is also an ofi cial Arduino
shield. Each board has its strong points: external antenna connectors, ultra-low
power, and bridging possibilities. It all depends on your project. This chapter
talks about standard connections without any external components or antennae.
The WiFi library can connect to a variety of Wi-Fi standards: typically B,
G, and N networks. It can handle both WEP and WPA-2 Personal encryption
but cannot connect to a WPA-2 Enterprise network. Also, it cannot connect to
hidden SSIDs.
The WiFi library uses the SPI bus and requires the SPI pins to be free. It uses
pins 11, 12, and 13 on the Arduino Uno, and 50, 51, and 52 for the Arduino Mega.
Pin 10 is used as a Slave Select pin, and pin 7 is used as a digital handshake;
these pins should not be used by the rest of the sketch.
The WiFi library methods are similar to those in the Ethernet library, and
many of the functions are identical—only changed slightly to handle wireless
networks and the subtle differences they face.
CROSS REFERENCE
Ethernet is presented in Chapter 9.
Importing the Library
To use the WiFi library, it must i rst be imported, which you can do in the Arduino
IDE (menu Sketch
Add Library
WiFi) or by adding the library manually:
#include <WiFi.h>
You need to import other libraries, depending on your project:
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
The WiFiServer.h header i le is used if the Arduino is to be a server. If a client
connection is going to be made, the WiFiClient.h header i le should be used. The
WiFiUdp.h library should be imported if UDP communications are to be used.
Initialization
To initialize the WiFi subsystem, you must use begin() . It can take several
parameters, depending on your coni guration. To start the WiFi subsystem
without any parameters (network SSID, password), just call begin() :
WiFi.begin();
 
Search WWH ::




Custom Search