venerdì 28 dicembre 2012

How to interface Arduino Mega 2560 to Weburban WiFi board



First you need an Arduino Mega 2560 board (http://arduino.cc/en/Main/arduinoBoardMega2560) and a Weburban WiFi board (http://store.weburban.com/wifi.html). This board uses standard connectors over SPI to an Arduino compatible Microchip 802.11b/g/n MRF24WB0MA.
In this example I use ArduinoIDE version 0021.



                                                          Arduino Mega 2560



                                                          Weburban WiFi board


                                                       Weburban WiFi board pin mapping


The WiFi board uses the WiShield library, available at  https://github.com/asynclabs/WiShield

How to connect Arduino to WiFi board:

Just follow this schema:


WiFi (pin)       Function        Arduino (pin)

1                GND             Power GND (left side, power supply connector)
2                +3.3V           +3.3V (left side, power supply connector)
3                Reset           Reset(left side, power supply connector)
4                CLOCK (SPI)     52 (lower side)
5                MISO (SPI)      50 (lower side)
6                MOSI (SPI)      51 (lower side)
7                CS (SPI)        53 (lower side)
8                Interrupt       2 (digital pin 0)



Then you need to modify the apps-conf.h file to include the header file for the application(s) you use in your project. For example, if you want to use "wiserver" in your sketch, you must modify the file like this:

//#define APP_WEBSERVER
//#define APP_WEBCLIENT
//#define APP_SOCKAPP
//#define APP_UDPAPP
#define APP_WISERVER



Finally, to make the WiShield work on Arduino Mega 2560 make the following changes to spi.h file (see at http://asynclabs.com/forums/viewtopic.php?f=13&t=19&hilit=mega&start=10):


#define SPI0_SS_BIT      BIT0            
#define SPI0_SCLK_BIT    BIT1
#define SPI0_MOSI_BIT    BIT2
#define SPI0_MISO_BIT    BIT3

#define SPI0_Init()      PRR0 = 0x00;\
                         DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                         DDRB  &= ~SPI0_MISO_BIT;\
                         PORTB = SPI0_SS_BIT;\
                         SPCR  = 0x50;\
                         SPSR  = 0x01

#define ZG2100_CS_BIT    BIT0

#define LEDConn_BIT      BIT5



Here is the complete modified spi.h file: https://github.com/rickit69/techrm/blob/master/WiShield_mod/spi.h


Here you can find some examples from Asynclabs:  http://asynclabs.com/wiki/index.php?title=WiServer


ATTENTION:  Arduino IDE new versions need some  modifications in the WiShield library.

                          For Arduino IDE version 1.0.3 I'm using this one:    https://github.com/rickit69/techrm/tree/master/WiShield_Arduino_IDE_1.0.3