Você está na página 1de 6

24/1/2014

Como usar o Wifi Shield com o Arduino

pesquisar...

MENU PRINCIPAL
Principal Artigos de usurios Ambiente de Aprendizagem Tutoriais
Arduino Banco de Dados Celulares e Tablets Diversos Internet Mac Raspberry Pi Linguagem de Programao Linux Window s

Como usar o Wifi Shield com o Arduino


Seg, 18 de Novembro de 2013 00:20 Fernando Bryan Frizzarin

TRANSLATION
Selecione o idioma
Pow ered by

Tradutor

Avaliao do Usurio: Pior


Tw eetar 10

/4 Melhor A VA LIA R
Recom endar

Voc precisar de um Arduino ou um clone seguindo o exato projeto para que o shield possa ser acoplado sem problemas.

Um Arduino:

Frum Links Contato Webmail

ENTRAR
Nome de Usurio

O clone, Tatuino:
Senha

Remember Me
LOGIN

Forgot your password? Forgot your username? Create an account

Precisar tambm do escudo para rede sem fios (wifi shield). Para este tutorial utilizei o shield Microchip que al de ser baixo custo pode ser encontrado facilmente na Internet com venda pela Tato Equipamentos Eletrnicos.

Acople o shield sobre o Arduino ou o clone:

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

1/6

24/1/2014

Como usar o Wifi Shield com o Arduino

Note que sobram dois pinos, do lado dos pinos de alimentao. Minha opo foi no cort-los, pois no na acoplagem. Mas cuidado! Caso resolva cort-los no v cortar pinos errados!

Obviamente tambm ter que ter uma rede fio composta de um access point ou roteador para que o shield possa ser conectado a ela para nossos testes. Baixe a biblioteca WiShield-master de www.seucurso.com.br/downloads/wifishield.zip. Descompacte o contedo do arquivo baixado na pasta libraries do local onde estiver a instalao do Arduino. Minha sugesto de cdigo usar o exemplo WebServer que bem simples e auto explicativo. Voc pode encontr-lo no menu File, opo Examples e sub-opo wifishield:

O cdigo :
0 1 . / * 0 2 . *W e bS e r v e r 0 3 . * 0 4 . *As i m p l ew e bs e r v e re x a m p l eu s i n gt h eW i S h i e l d1 . 0 0 5 . * / 0 6 . 0 7 . # i n c l u d e< W i S h i e l d . h > 0 8 . 0 9 . / /W i r e l e s sc o n f i g u r a t i o np a r a m e t e r s1 0 . u n s i g n e dc h a rl o c a l _ i p [ ] ={ 1 9 2 , 1 6 8 , 0 , 2 0 0 } ; / /I Pa d d r e s so f W i S h i e l d 1 1 . u n s i g n e dc h a rg a t e w a y _ i p [ ] ={ 1 9 2 , 1 6 8 , 0 , 1 } ; / /r o u t e ro rg a t e w a yI P a d d r e s s 1 2 . u n s i g n e dc h a rs u b n e t _ m a s k [ ]={ 2 5 5 , 2 5 5 , 2 5 5 , 0 } ;/ /s u b n e tm a s kf o rt h e l o c a ln e t w o r k 1 3 . c h a rs s i d [ ] ={ " r e d e s e m f i o " } ; / /m a x3 2b y t e s 1 4 . u n s i g n e dc h a rs e c u r i t y _ t y p e=3 ; / /0-o p e n ;1-W E P ;2W P A ;3-W P A 2 1 5 . 1 6 . / /W P A / W P A 2p a s s p h r a s e 1 7 . c o n s tp r o g _ c h a rs e c u r i t y _ p a s s p h r a s e [ ]P R O G M E M={ s e n h a d a r e d e s e m f i o " } ;/ /

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

2/6

24/1/2014

Como usar o Wifi Shield com o Arduino


1 8 . 1 9 . / /W E P1 2 8 b i tk e y s 2 0 . p r o g _ u c h a rw e p _ k e y s [ ]P R O G M E M={ 2 1 . 0 x 0 1 ,0 x 0 2 ,0 x 0 3 ,0 x 0 4 ,0 x 0 5 ,0 x 0 6 ,0 x 0 7 ,0 x 0 8 ,0 x 0 9 ,0 x 0 a ,0 x 0 b ,0 x 0 c , 0 x 0 d ,/ /K e y0 2 2 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0 ,/ /K e y1 2 3 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0 ,/ /K e y2 2 4 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0/ /K e y3 2 5 . } ; 2 6 . 2 7 . / /s e t u pt h ew i r e l e s sm o d e ;i n f r a s t r u c t u r e-c o n n e c tt oA P ;a d h o cc o n n e c tt oa n o t h e rW i F id e v i c e 2 8 . # d e f i n eW I R E L E S S _ M O D E _ I N F R A1 2 9 . # d e f i n eW I R E L E S S _ M O D E _ A D H O C2 3 0 . u n s i g n e dc h a rw i r e l e s s _ m o d e=W I R E L E S S _ M O D E _ I N F R A ; 3 1 . u n s i g n e dc h a rs s i d _ l e n ; 3 2 . u n s i g n e dc h a rs e c u r i t y _ p a s s p h r a s e _ l e n ; 3 3 . / /E n do fw i r e l e s sc o n f i g u r a t i o np a r a m e t e r s3 4 . 3 5 . 3 6 . v o i ds e t u p ( ) 3 7 . { 3 8 . W i F i . i n i t ( ) ; 3 9 . } 4 0 . 4 1 . / /T h i si st h ew e b p a g et h a ti ss e r v e du pb yt h ew e b s e r v e r 4 2 . c o n s tp r o g _ c h a rw e b p a g e [ ]P R O G M E M={ " H T T P / 1 . 12 0 0O K \ r \ n C o n t e n t T y p e : t e x t / h t m l \ r \ n \ r \ n 4 3 . < h 1 > H e l l oW o r l d ! !Ia mW i S h i e l d < / h 1 > 4 4 . < f o r ma c t i o n = " \ "m e t h o d = " \ " > T o g g l eL E D : < i n p u tn a m e = " \ "t y p e = " \ "v a l u e = " \ " / > < / f o r m > 4 5 . " } ; 4 6 . 4 7 . 4 8 . v o i dl o o p ( ) 4 9 . { 5 0 . W i F i . r u n ( ) ; 5 1 . } m a x6 4c h a r a c t e r s

Para que esse cdigo funcione voc ter que alterar algumas variveis para que reflitam a configurao de sua rede sem fio. Sendo elas: O nmero IP a ser designado para seu shield:
1 . u n s i g n e dc h a rl o c a l _ i p [ ] ={ 1 9 2 , 1 6 8 , 0 , 2 0 0 } ;

O nmero IP do gateway:
1 . u n s i g n e dc h a rg a t e w a y _ i p [ ] ={ 1 9 2 , 1 6 8 , 0 , 1 } ;

A mscara de sub-rede:
1 . u n s i g n e dc h a rs u b n e t _ m a s k [ ]={ 2 5 5 , 2 5 5 , 2 5 5 , 0 } ;

O SSID (identificao) da sua rede:


1 . c h a rs s i d [ ] ={ r e d e s e m f i o " } ;

O tipo de segurana utilizada, sendo 0 para rede aberta (open), 1 para WEP, 2 para WPA e 3 para WPA2:
1 . u n s i g n e dc h a rs e c u r i t y _ t y p e=3 ;

A senha para sua rede sem fio, no caso deste tutorial para WPA2:
1 . c o n s tp r o g _ c h a rs e c u r i t y _ p a s s p h r a s e [ ]P R O G M E M={ s e n h a d a r e d e s e m f i o } ;

Se voc ainda usa WEP, primeiro pense em mudar para WPA ou WPA2 que so criptografias mais seguras, depois se ainda assim quiser usar WEP ter que mudar a varivel abaixo com as chaves em valores hexadecimais:
1 . p r o g _ u c h a rw e p _ k e y s [ ]P R O G M E M={ 2 . 0 x 0 1 ,0 x 0 2 ,0 x 0 3 ,0 x 0 4 ,0 x 0 5 ,0 x 0 6 ,0 x 0 7 ,0 x 0 8 ,0 x 0 9 ,0 x 0 a ,0 x 0 b ,0 x 0 c , 0 x 0 d ,/ /K e y0 3 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0 ,/ /K e y1 4 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0 ,/ /K e y2 5 . 0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 ,0 x 0 0 , 0 x 0 0/ /K e y3 6 . } ;

Agora compilar e enviar para o seu Arduino. Feito isso o shield ir conectar-se em sua rede sem fio em alguns segundos e o LED indicativo de WIFI ON deve acender:

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

3/6

24/1/2014

Como usar o Wifi Shield com o Arduino

Para test-lo entre em seu navegador de Internet preferido e aponte para o IP que designou ao seu shield:

Caso queira usar qualquer outro exemplo deste shield lembre-se de editar o arquivo apps-conf.h e comentar ou descomentar a aplicao que deseja utilizar. O cdigo desse arquivo para este tutorial ficou como segue. Note que est descomentada a linha #define APP_WEBSERVER, pois o exemplo que estamos utilizando. As demais continuam comentadas.
0 0 1 . 0 0 2 . / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 0 3 . 0 0 4 . F i l e n a m e :a p p s c o n f . h 0 0 5 . D e s c r i p t i o n :W e ba p p l i c a t i o nc o n f i g u r a t i o nf i l e 0 0 6 . 0 0 7 . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 0 0 8 . 0 0 9 . T C P / I Ps t a c ka n dd r i v e rf o rt h eW i S h i e l d1 . 0w i r e l e s sd e v i c e s 0 1 0 . 0 1 1 . C o p y r i g h t ( c )2 0 0 9A s y n cL a b sI n c .A l lr i g h t sr e s e r v e d . 0 1 2 . 0 1 3 . T h i sp r o g r a mi sf r e es o f t w a r e ;y o uc a nr e d i s t r i b u t ei ta n d / o rm o d i f yi t 0 1 4 . u n d e rt h et e r m so fv e r s i o n2o ft h eG N UG e n e r a lP u b l i cL i c e n s ea s 0 1 5 . p u b l i s h e db yt h eF r e eS o f t w a r eF o u n d a t i o n . 0 1 6 . 0 1 7 . T h i sp r o g r a mi sd i s t r i b u t e di nt h eh o p et h a ti tw i l lb eu s e f u l ,b u t W I T H O U T 0 1 8 . A N YW A R R A N T Y ;w i t h o u te v e nt h ei m p l i e dw a r r a n t yo fM E R C H A N T A B I L I T Yo r 0 1 9 . F I T N E S SF O RAP A R T I C U L A RP U R P O S E . S e et h eG N UG e n e r a lP u b l i cL i c e n s e f o r 0 2 0 . m o r ed e t a i l s . 0 2 1 . 0 2 2 . Y o us h o u l dh a v er e c e i v e dac o p yo ft h eG N UG e n e r a lP u b l i cL i c e n s ea l o n g w i t h 0 2 3 . t h i sp r o g r a m ;i fn o t ,w r i t et ot h eF r e eS o f t w a r eF o u n d a t i o n ,I n c . ,5 9 0 2 4 . T e m p l eP l a c e-S u i t e3 3 0 ,B o s t o n ,M A 0 2 1 1 1 1 3 0 7 ,U S A . 0 2 5 . 0 2 6 . C o n t a c tI n f o r m a t i o n : 0 2 7 . 0 2 8 . 0 2 9 . A u t h o r D a t e C o m m e n t 0 3 0 . 0 3 1 . A s y n c L a b s0 5 / 2 9 / 2 0 0 9I n i t i a lp o r t 0 3 2 . 0 3 3 . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / 0 3 4 . 0 3 5 . # i f n d e f_ _ A P P S _ C O N F _ H _ _ 0 3 6 . # d e f i n e_ _ A P P S _ C O N F _ H _ _ 0 3 7 . 0 3 8 . / /0 3 9 . / /-B e g i nu I P / W i S h i e l ds t a c kc o n f i g u r a t i o ns e t t i n g s 0 4 0 . 0 4 1 . / / 0 4 2 . / /A p p l i c a t i o nt y p ed e f i n e s ;u n c o m m e n tt oe n a b l eA P P _ T Y P E S 0 4 3 . / / A P P _ U D P A P Pi su s e df o rU D Po n l ya p p sa sw e l la sD N Sa n dD H C Pa p p s ; i fy o u ra p pw i l lu s e 0 4 4 . / / D N Sa n d / o rD H C Pt h e ny o u rA P P _ T Y P E( e . g .A P P _ W I S E R V E R )A N D A P P _ U D P A P Pm u s tb ed e f i n e d 0 4 5 . / / ( u n c o m m e n t e d ) .C u r r e n t l yo n l yA P P _ U D P A P Pm a yb ed e f i n e da tt h es a m e t i m ea sa n yo t h e rA P P _ T Y P E 0 4 6 . / / 0 4 7 . # d e f i n eA P P _ W E B S E R V E R 0 4 8 . / / # d e f i n eA P P _ W E B C L I E N T 0 4 9 . / / # d e f i n eA P P _ S O C K A P P 0 5 0 . / / # d e f i n eA P P _ U D P A P P

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

4/6

24/1/2014
0 5 1 . 0 5 2 . 0 5 3 . 0 5 4 . 0 5 5 . 0 5 6 .

Como usar o Wifi Shield com o Arduino


/ / # d e f i n eA P P _ W I S E R V E R / / / /A d do nf e a t u r e s ;u n c o m m e n tt oe n a b l ea d d i t i o n a lf u n c t i o n a l i t y / / / / # d e f i n eU I P _ D N S / /A d dD N Sc a p a b i l i t i e s-A P P _ U D P A P P m u s tb ed e f i n e d ! 0 5 7 . / / # d e f i n eU I P _ D H C P / /A d dD H C Pc a p a b i l i t i e s-A P P _ U D P A P P m u s tb ed e f i n e d ! 0 5 8 . / / # d e f i n eU I P _ S C A N / /A d dA c c e s sP o i n ts c a nc a p a b i l i t i e s 0 5 9 . 0 6 0 . / / 0 6 1 . / /C o m m o n l ya c c e s s e dW i S e r v e rs e t t i n g s 0 6 2 . / / 0 6 3 . # d e f i n eW I S E R V E R _ G E T _ S T R I N G _ M A X6 4/ /L e n g t ho fb u f f e rw h i c hh o l d s U R L / G E Tp a s s e dt oW i S e r v e r 0 6 4 . / /S i m p l e S e r v e rs e n d M y P a g e ( )p a g es e r v i n gf u n c t i o n 0 6 5 . 0 6 6 . / / 0 6 7 . / /C o m m o n l ya c c e s s e du I Ps t a c ks e t t i n g s 0 6 8 . / / 0 6 9 . # d e f i n eU I P _ W E P _ K E Y _ L E N 1 3/ /W E PK e yl e n g t h :5b y t e s( 6 4 b i t W E P ) ;1 3b y t e s( 1 2 8 b i tW E P ) 0 7 0 . # d e f i n eU I P _ W E P _ K E Y _ D E F A U L T 0/ /D e f a u l tW E Pk e yI D :K e y0 ,1 ,2 ,3 0 7 1 . # d e f i n eM A X _ T C P _ C O N N S 2/ /M a xT C Pc o n n e c t i o n sd e s i r e d 0 7 2 . # d e f i n eM A X _ T C P _ L I S T E N P O R T S 2/ /M a xT C Pl i s t e n i n gp o r t s 0 7 3 . # d e f i n eM A X _ U D P _ C O N N S 1/ /M a xU D Pc o n n e c t i o n sd e s i r e d 0 7 4 . / /D o n ' tp l a yw i t hU I P _ C L O C K _ D I Vu n l e s sy o uk n o ww h a ty o ua r ed o i n g ! 0 7 5 . # d e f i n eU I P _ C L O C K _ D I V 2/ /R e f e r e n c e di ns t a c k . c ;d e f a u l t2 0 7 6 . 0 7 7 . / /-E n du I P / W i S h i e l ds t a c kc o n f i g u r a t i o ns e t t i n g s 0 7 8 . / /0 7 9 . 0 8 0 . 0 8 1 . # i f d e fA P P _ W E B S E R V E R 0 8 2 . # i n c l u d e" w e b s e r v e r . h " 0 8 3 . # e n d i f 0 8 4 . 0 8 5 . # i f d e fA P P _ W E B C L I E N T 0 8 6 . # i n c l u d e" w e b c l i e n t . h " 0 8 7 . # e n d i f 0 8 8 . 0 8 9 . # i f d e fA P P _ S O C K A P P 0 9 0 . # i n c l u d e" s o c k e t a p p . h " 0 9 1 . # e n d i f 0 9 2 . 0 9 3 . # i f d e fA P P _ U D P A P P 0 9 4 . # i n c l u d e" u d p a p p . h " 0 9 5 . # d e f i n eU I P _ U D P _ E N A B L E D1 0 9 6 . # e l s e 0 9 7 . # d e f i n eU I P _ U D P _ E N A B L E D0 0 9 8 . # e n d i f 0 9 9 . 1 0 0 . # i f d e fA P P _ W I S E R V E R 1 0 1 . # i n c l u d e" s e r v e r . h " 1 0 2 . # e n d i f 1 0 3 . 1 0 4 . # i f d e fU I P _ D H C P 1 0 5 . # i n c l u d e" u i p _ d h c p . h " 1 0 6 . # e n d i f 1 0 7 . 1 0 8 . # i f d e fU I P _ D N S 1 0 9 . # i n c l u d e" u i p _ d n s . h " 1 1 0 . # e n d i f 1 1 1 . 1 1 2 . # e n d i f/ * _ _ A P P S _ C O N F _ H _ _ * /

Com um pouco de conhecimento de HTML e TCP/IP agora s usar a imaginao para resolver seu problema ou criar sua aplicao!

MOSTRAR OUTROS ARTIGOS DESTE AUTOR


COMENTRIOS #3 Problema Fernando Bryan Frizzarin 23-01-2014 13:19 0 Matheus, voc ajustou o endereo IP, nome da rede e senha corretamente? Por favor, verifique isso e qualquer coisa me fale novamente. Citar

#2 problema Matheus Prado 23-01-2014 09:50 0 O Wifi Shield conecta rede pois o led verde ascende, mas a pgina no abre. O que fazer?? Citar

#1 Pinos disponiveis Mauricio Nascimento 31-12-2013 11:42 +1 Muito boa tarde. Gostaria de saber quais pinos que posso utilizar para receber sinais externos ou acionar leds sem interferir na comunicao. Citar Atualizar lista de comentrios Assine o RSS dos comentrios ADICIONAR COMENTRIO Nome (obrigatrio) E-mail (obrigatrio) Ttulo (obrigatrio)

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

5/6

24/1/2014

Como usar o Wifi Shield com o Arduino

Voc ainda pode digitar 1000 caracte re s

Notifique-me de comentrios futuros

Atualizar

Enviar
J C omments

http://www.seucurso.com.br/index.php?option=com_content&view=article&id=317:como-usar-o-wifi-shield-com-o-arduino&catid=901:arduino&Itemid=65

6/6

Você também pode gostar