You are on page 1of 8

DFRobot WiFi Shield V2.

1 Arduino Tutorial
By Frikkie Du Toit

Table of Contents
Overview..............................................................................................................................................3 Requirements........................................................................................................................................3 WiFi Shield Setup.................................................................................................................................4 Setting WiFi Shield Configuration.......................................................................................................4 Arduino Interfacing in WiFi Mode.......................................................................................................6 What Next?...........................................................................................................................................8

Overview
This is a tutorial for the DFRobot WiFi Shield v2.1 For Arduino. The tutorial will guide you through the steps of how to set up the WiFi Shield, how to configure it, how to communicate with a PC and how to use it with the Arduino. Note: In the tutorial there is a sketch that turns on and off a LED. The LED is set to be on pin 13 of the Arduino. The Arduino Uno has a built in LED on pin 13 so you don't have to worry. But if you have an older Arduino you might not have a LED on pin 13 so you will have to connect one yourself. The WiFi Shield has different modes for different operations. The tutorial will tell you when to use which mode. There is a USB mode which allows you to have WiFi Shield to PC communication. Put both jumpers on the USB side of the header for USB mode. Note: There will be pictures later on for the different modes to show where the jumpers should be. Then there is WiFi mode which allows WiFi Shield to Arduino communication. For WiFi mode but both jumpers on the WiFi side of the header. To program your Arduino, remove both the headers. This will disconnect the WiFi Shield from the serial port lines.

Requirements
Software requirements: 1. Terminal emulator like Putty for serial and raw TCP support. 2. Arduino IDE Hardware requirements: 1. Arduino 2. DFRobot WiFi Shield v2.1 For Arduino 3. Wireless Router or Access Point 4. Standard USB cable for Arduino

WiFi Shield Setup


1. First upload a sketch onto your Arduino that doesn't use the serial port on the Arduino. The Blink example sketch that comes with the Arduino IDE works nicely. 2. Power up your Arduino and WiFi shield. The WiFi Shield uses a lot of power, so I recommend to use an external power supply. Plug your Arduino into the computer's USB port. 3. Make sure your WiFi Shield is set to USB mode using the jumpers (Like shown in the picture). Both jumpers should be on the USB side of the header.

USB Mode The WiFi Shield should now be set up to be configured.

Setting WiFi Shield Configuration


Now we are going to configure the WiFi Shield to automatically connect to a Wireless Access Point (AP). Run a Serial Terminal like Putty to send AT commands to the WiFi Shield: 1. Set the connection type to Serial. 2. Set the Serial line to the port where your Arduino is connected to. 3. Set the Speed or baudrate to 115200. 4. Next you can save the session to be able to start it easily later again. 5. Click on open and a terminal should open. 4

Now you are ready to send AT commands to the WiFi Shield to set the configuration. Enter the following AT commands to set up your WiFi Shield to automatically connect to a Wireless Access Point. Note that after each AT command it usually returns [OK] if the command was successfully executed. If you enter a command and you delete some characters it gives an error like [ERROR invalid input]. Try not to delete while entering your command. Setup commands: AT [OK] AT+WD [OK] AT+WWPA=<passphrase> //Set WPA passphrase. Replace <passphrase> with your passphrase [OK] AT+NDHCP=0 [OK] AT+NSET=192.168.0.100,255.255.255.0,192.168.101 //Set Static IP, Subnet Mask, Gateway. Note: this is just an example IP and Gateway. You should replace them with a IP and Gateway that fits your network [OK] AT+WAUTO=0,<SSID>,,0 // Set to AP mode and connects to AP <SSID> Through channel 0. Replace <SSID> with the SSID of your AP. [OK] AT+NAUTO=1,1,,4000 [OK] ATC1 [OK] AT&W0 [OK] ATA IP [OK] //Connect automatically Subnet Mask Gateway //Save settings //Connect automatically after restart //Set as TCP server on port 4000 //Disables DHCP //Test if WiFi Shield is connected //Module is connected and ready //Disconnects from current network

192.168.0.100: 255.255.255.0: 192.168.0.101

This is just an example setup. You can go look in the WizFi210 v1.01 datasheet for more AT commands and short description of what the command does and parameters. After these commands the LEDs on the WiFi Shield labelled STW and ASSOC should be on. You will not be able to send AT commands to the WiFi Shield for further configuration. If you want to change the configuration you will have to restore the WiFi Shield to it's factory default settings by pressing the GPIO10 button twice. Your Wireless Access Point should show that a new device has connected to it.

Arduino Interfacing in WiFi Mode


Now your WiFi Shield should be set up to connect to your Wireless Access Point. Now we are going to upload an Arduino sketch that can communicate with the WiFi Shield. We are going to use a sketch that switches on an LED if it receives a 1 character and switches off if it receiver a 0 character. Steps: 1. Remove the jumpers to disconnect the serial port from the WiFi Shield to be able to program your Arduino. I recommend switching off the power when changing jumpers for safety. 2. Upload the sketch given below. 3. Set the WiFi Shield to WiFi mode by putting both the jumpers on the WiFi side of the header (Like shown in picture).

WiFi Mode

#define LED_PIN 13 byte incoming_byte = 0; //Store data received over serial port void setup() { Serial.begin(115200); //Initialize serial port with baudrate //115200 pinMode(LED_PIN, OUTPUT); } void loop() { if (Serial.available() > 0) //If serial data available { incoming_byte = Serial.read(); //Read the data and store if (incoming_byte == '1') //If received data == '1' { digitalWrite(LED_PIN, HIGH); //Turn on LED } else if (incoming_byte == '0') // Else if received data // == '0' { digitalWrite(LED_PIN, LOW); //Turn off LED } } } Source code for Arduino sketch. Next open Putty again. We are going to open a terminal to send and receive data from your Arduino. //Sets LED pin as output

digitalWrite(LED_PIN, LOW); //Turn off LED

Steps: 1. Select Raw as the connection type. 2. Enter the WiFi Shield's IP Address in the Host Name field and set port to 4000. 3. Click open to start the terminal. You can now send data to your Arduino with the terminal. Send a '1' character. The LED should turn on. If you send a '0' character again it should turn off. Note: the Arduino also receives a carriage return and line feed character after the data you sent. But the Arduino LED sketch should ignore it so no need to worry about it for now.

What Next?
You can also use your Arduino to transmit data over the network. Just use the Serial.print() and the Serial.println() functions to transmit data. The data will be captured by the terminal you opened in the previous part and it will display the data captured. This tutorial is just to show you the basics of setting up your WiFi Shield and Arduino. You can configure your WiFi Shield to your specific needs with the AT commands. There is also a script available at Wiznet with a Graphical User Interface (GUI) that can be used to configure the WiFi Shield instead of using the AT commands directly. The script is called WIZSmartScript. This tutorial does not show how to use the script, but there is a short tutorial available at DFRobot that shows how to use it. You can use the script, but the AT commands might give you more flexibility to configure to your specific needs. You can try to write more interesting Arduino sketches to do more than just turn on a LED. For example, you could build a remote controlled vehicle or robot that can be controlled over a network or the internet, or a data logger that posts it's readings on the internet.

You might also like