NEW Wifi Shield Review
Wanna take advantage of already-have Ethernet or Internet to implement your IoT project? Wifi module is a must. We have an XBee compatible Wifi Bee in the bazaar for those Bee lovers. It’s a good choice if you are familiar with Bee products. As for Arduino hardcore, we believe shield can be a convenient and neat choice. That’s why we have a new plug-n-play Wifi shield now.
This review is written from a view of a beginner. If you are new to wifi module and wanna try, this review can help you gain some tips on hardware connection, basic coding and application. If you are experienced with Wifi module, you can totally ignore this review (well, if you feel like solving some problems I met as listed at the bottom of this review, bravo!).
1. Hardware Connection
This Wifi shield utilizes one of the most popular wifi chip, RN171, to provide your project with serial Ethernet function. It only requires 2 I/O pins of Arduino/Seeeduino to fulfill the function, saving more pins for extending development. The 2 pins occupied, RX and TX, are shown below. The first row and the last row of pins are connected to TX and RX of the RN171 chip respectively, and the pins of the middle row are connected to D0~D7 from right to left.
We ship this Wifi shield with D2 shorted to TX and D3 shorted to RX as shown below. You can absolutely change it. Just move the shorted jumpers to pins you like and change one line of the software programming in the example we provide in Wifi shield’s wiki page.
This line describes the config of TX and RX:
WiflyClass Wifly(2,3);
Which means D2 is connected to TX and D3 is connected to RX. If you wanna change, change these parameters also.
2. DigitalRead Demo
The original example provided on wiki page shows you how to communicate between a virtual remote server and a soft serial COM. TCP server and SSCOM are two tools packed for them. Because there are off-the-peg Grove sockets on this new wifi shield, I tried to read a sensor value from the server end in this demo.
Feel uncertain about the two tools we are going to use? Find background info on the wiki page.
I did some modifications to the original example and used a tilt switch to achieve the function:
#include “Wifly.h”
#include <SoftwareSerial.h>
WiflyClass Wifly(2,3);
int tiltswitch = 9; // the digital Gove socket is connected to D8 & D9 of the microcontroller
void setup()
{
Serial.begin(9600);
Wifly.init();
Wifly.setConfig(“HOME”,”11111111″); //the Ethernet information
Wifly.join(“HOME”);
Wifly.checkAssociated();
while(!Wifly.connect(“192.168.1.68″,”90”)); //remote server address and port number
Wifly.writeToSocket(“Connected!”);
}
void loop()
{
if(Wifly.canReadFromSocket()) //check if any message sent from the server
{
Wifly.readFromSocket(); //print message sent from the server on SSCOM
if(Wifly.readFromSocket()== ‘Z’) //set a key word to collect sensor value
{
Wifly.print(digitalRead(tiltswitch)+48); //get the sensor value printed by “+48”,
//changeing int into char format
}
}
if(Serial.available())
{
Wifly.print((char)Serial.read()); // print message sent from SSCOM
//on the screen of the server
}
}
There are two functions that might be used pretty often:
1) Wifly.readFromSocket();
This function is used to print message sent from server end onto the screen of SSCOM.
2) Wifly.print();
This function is used to print message onto the screen of server, no matter where the message comes from. The source can be SSCOM or sensors we used above.
Upload the sketch, run TCP server and SSCOM. When “<–Connected!” appears on the screen of server, the bridge is built. Let’s run up the communication in an old-school way, try “Hello world!”, then here is what I get:
Then test the command I set to collect sensor value on the Wifi shield: “Z”:
I get “1” sent from SSCOM end, which is the sensor value of tilt switch on the digital Grove socket. Now send “Z” to SSCOM when you want to read the status of sensor on the Wifi shield.
3. Problems
When I used “Wifly.print(digitalRead(tiltswitch)+48);” to get int printed, I need +48 to change the sensor value into corresponding ASCII code. And when it comes to float number, bugs happen. Both of these mean more types of supports are needed for Wifly.readFromSocket(); and Wifly.print();.
Besides, Wifi Shield shouldn’t be limited within Ethernet. If you have any fabulous Internet based projects, welcome to share with us! Looking forward to your work!