I'm using an Arduino Mega to monitor the current & voltage input to four different sensors. This works fine - the sensors work as expected and I can view the results via the Serial Monitor or Parallax DAQ for Excel.
SETUP
I also have an Arduino wireless SD shield (now retired) with an XBee module (shown in the below image):
I would like to do the following:
- Save the current/voltage sensors' output locally to the SD card
- Send the data over a wifi connection for plotting using plotly API (see example here)
I've seen a bunch of tutorials on how to get the shield to work but can't seem to figure it out:
- Arduino WiFi shield example
- Instructables
- Can I connect to WiFi with an Arduino, "wireless SD shield" and XBee
Here's my code (removed the current/voltage sensor code for brevity):
#include <SPI.h>
#include <WiFi.h>
#include <SD.h>
void setup() {
// initialize serial and wait for the port to open:
Serial.begin(9600);
while(!Serial) ;
SPI.begin();
Serial.println("Checking WiFi status:");
Serial.print("\tWiFi Status: ");
Serial.println(WiFi.status());
if(WiFi.status() == WL_NO_SHIELD){
Serial.println("\tNo Shield present.\n");
}else{
Serial.println("\tShield found.\n");
}
Serial.println("Initializing SD card:");
if (!SD.begin(53)) {
Serial.println("\tSD card initialization failed.\n");
return;
}else{
Serial.println("\tSD card initialization successful.\n");
}
// attempt to connect using WEP encryption:
Serial.println("Initializing Wifi:");
printMacAddress();
// scan for existing networks:
Serial.println("Scanning available networks...");
listNetworks();
}
void loop() {
delay(5000);
// scan for existing networks:
Serial.println("Scanning available networks:");
listNetworks();
}
void printMacAddress() {
// the MAC address of your Wifi shield
byte mac[6];
// print your MAC address:
WiFi.macAddress(mac);
Serial.print("\tMAC: ");
for(int i = 0; i < 5; i++){
Serial.print(mac[5-i],HEX);
if(i != 5){
Serial.print(":");
}
}
Serial.println(" ");
}
void listNetworks() {
// scan for nearby networks:
Serial.println("** Scan Networks **");
byte numSsid = WiFi.scanNetworks();
// print the list of networks seen:
Serial.print("number of available networks:");
Serial.println(numSsid);
// print the network number and name for each network found:
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
Serial.println(WiFi.encryptionType(thisNet));
}
}
OUTPUT
Checking WiFi status:
WiFi Status: 255
No Shield present.
Initializing SD card:
SD card initialization successful.
Initializing Wifi:
MAC: 0:0:0:0:0:
Scanning available networks...
** Scan Networks **
number of available networks:0
Not sure what is going on here.