简体   繁体   中英

Arduino Wifi Shield 101 Connection Issues

So I recently bought the Arduino Wifi Shield 101. I went through the getting started steps, and just copied and pasted their "scan for networks" code. The code that I used is down below. So to help you guys help me, I should say my school's wifi is wpa2 encrypted. However, the code is simply looking for possible networks to connect to. The code runs fine until it gets to the "Wifi.macAddress(mac)" line. I don't understand why the code stops working here. There aren't any errors in compiling or uploading, the code just seems to not be working. Im obviously a beginner with the arduino wifi board, so any help at all would be great.

Here's the code:

`#include <SPI.h>
 #include <WiFi101.h>

 void setup() {
 // initialize serial and wait for the port to open:
 Serial.begin(9600);

 while(!Serial);

 // attempt to connect using WEP encryption:
 Serial.println("Initializing Wifi...");
 printMacAddress();

 // scan for existing networks:
 Serial.println("Scanning available networks...");
 listNetworks();
}

void loop() {
  delay(10000);
  // 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:
Serial.print("The code got to here");
WiFi.macAddress(mac); //why won't this method work?
Serial.print("The code never reaches this point ... Why?!?!?");
Serial.print("MAC: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX); 
}

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));
  }
}`

Are you powering the boards via USB? If so, you're likely experiencing an under-power issue.

My original answer was deleted (so I don't know what you can and cannot see), but the link to the Arduino bug I filed is here: Arduino 101 + Wifi 101 Shield board freeze. #50

As it turns out, my board was simply under-powered as I was using a USB port rather than a wall outlet. I actually ended up using a different USB port and the scanNetworks example now works for me.

EDIT Actually, as it turns out, it was the USB cable. Either way, power was the issue.

I would recommend powering the board via a wall wart or choosing a different USB port and trying again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM