Professional Documents
Culture Documents
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
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
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.
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
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.