Hi, I have problems connecting the Wifi Shield (http://arduino.cc/en/Main/ArduinoWiFiShield) to the Arduino Robot (http://arduino.cc/en/Guide/Robot). What I have done is, I have connected the components via the ICSP port and the SS pin for the shield to TKD3 on the robot; the 'Handshake' pin, pin 7, to TKD5 on the robot; and the LED pin, pin 9 to TKD4 on the robot. I had to use these pins on the robot, because the designated pins are occupied by the LCD. I changed the pin definitions in the WIFI Library file as follows:
#define DATAOUT 10 // MOSI (was pin 11; changed to pin 10)
#define DATAIN 11 // MISO (was pin 12; changed to pin 11)
#define SPICLOCK 9 // sck (was pin 13; changed to pin 9)
#define SLAVESELECT TKD3 // ss (was pin 10; changed to pin TKD3)
#define SLAVEREADY TKD5 // handshake pin (was pin 7; changed to pin TKD5)
#define WIFILED TKD4 // led on wifi shield (was pin 9; changed to pin TKD4)
Following this, I tried to load one of the Wifi example codes and adapted it to work for the robot as follows:
/*
This example prints the Wifi shield's MAC address, and
scans for available Wifi networks using the Wifi shield.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.
Circuit:
* WiFi shield attached
created 13 July 2010
by dlf (Metodo2 srl)
modified 21 Junn 2012
by Tom Igoe and Jaymes Dec
*/
#include <ArduinoRobot.h>
#include <SPI.h>
#include <WiFi.h>
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
Robot.begin();
Robot.beginTFT();
Robot.beginSD();
SPI.begin();
}
// Print WiFi MAC address:
printMacAddress();
// scan for existing networks:
Robot.println("Scanning available networks...");
listNetworks();
}
void loop() {
delay(10000);
// scan for existing networks:
Robot.println("Scanning available networks...");
listNetworks();
}
void printMacAddress() {
// the MAC address of your Wifi shield
byte mac[6];
// print your MAC address:
WiFi.macAddress(mac);
Robot.print("MAC: ");
Robot.print(mac[5],HEX);
Robot.print(":");
Robot.print(mac[4],HEX);
Robot.print(":");
Robot.print(mac[3],HEX);
Robot.print(":");
Robot.print(mac[2],HEX);
Robot.print(":");
Robot.print(mac[1],HEX);
Robot.print(":");
Robot.println(mac[0],HEX);
}
void listNetworks() {
// scan for nearby networks:
Robot.println("** Scan Networks **");
int numSsid = WiFi.scanNetworks();
if (numSsid == -1)
{
Robot.println("Couldn't get a wifi connection");
while(true);
}
// print the list of networks seen:
Robot.print("number of available networks:");
Robot.print(numSsid);
// print the network number and name for each network found:
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
Robot.print(thisNet);
Robot.print(") ");
Robot.print(WiFi.SSID(thisNet));
Robot.print("\tSignal: ");
Robot.print(WiFi.RSSI(thisNet));
Robot.print(" dBm");
Robot.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
}
}
void printEncryptionType(int thisType) {
// read the encryption type and print out the name:
switch (thisType) {
case ENC_TYPE_WEP:
Robot.println("WEP");
break;
case ENC_TYPE_TKIP:
Robot.println("WPA");
break;
case ENC_TYPE_CCMP:
Robot.println("WPA2");
break;
case ENC_TYPE_NONE:
Robot.println("None");
break;
case ENC_TYPE_AUTO:
Robot.println("Auto");
break;
}
}
However, when compiling, I get the following error:
SPI\SPI.cpp.o: In function
SPIClass::end()': C:\Users\...\arduino-1.0.5\libraries\SPI/SPI.cpp:44: multiple definition of
SPIClass::end()'
Robot_Control\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:44: first defined here
SPI\SPI.cpp.o: In functionSPIClass::setBitOrder(unsigned char)': C:\Users\...\arduino-1.0.5\libraries\SPI/SPI.cpp:49: multiple definition of
SPIClass::setBitOrder(unsigned char)'
Robot_Control\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:49: first defined here
SPI\SPI.cpp.o: In functionSPIClass::setDataMode(unsigned char)': C:\Users\...\arduino-1.0.5\libraries\SPI/SPI.cpp:58: multiple definition of
SPIClass::setDataMode(unsigned char)'
Robot_Control\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:58: first defined here
SPI\SPI.cpp.o: In functionSPIClass::setClockDivider(unsigned char)': C:\Users\...\arduino-1.0.5\libraries\SPI/SPI.cpp:63: multiple definition of
SPIClass::setClockDivider(unsigned char)'
Robot_Control\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:63: first defined here
SPI\SPI.cpp.o: In functionSPIClass::begin()': C:\Users\...\arduino-1.0.5\libraries\SPI/SPI.cpp:19: multiple definition of
SPIClass::begin()'
Robot_Control\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:19: first defined here
SPI\SPI.cpp.o:C:\Users...\arduino-1.0.5\libraries\SPI/SPI.cpp:44: multiple definition of `SPI'
Robot_Control\SPI.cpp.o:C:...e\arduino-1.0.5\libraries\Robot_Control/SPI.cpp:44: first defined here
I guess that I have to change the SPI Library, according to how the Wifi Shield operates; i.e. change the following functions:
void SPIClass::end() {
SPCR &= ~_BV(SPE);
}
void SPIClass::setBitOrder(uint8_t bitOrder)
{
if(bitOrder == LSBFIRST) {
SPCR |= _BV(DORD);
} else {
SPCR &= ~(_BV(DORD));
}
}
void SPIClass::setDataMode(uint8_t mode)
{
SPCR = (SPCR & ~SPI_MODE_MASK) | mode;
}
void SPIClass::setClockDivider(uint8_t rate)
{
SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK);
SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK);
}
...But how, and what exactly?
I would really appreciate your help.
Thank you.
Kind regards
Stefan