Go Down

Topic: Arduino Leonardo and duinotech Wifi Shield (Read 9608 times) previous topic - next topic

OfficialEnlightGames

Mar 28, 2017, 10:39 am Last Edit: Mar 28, 2017, 10:46 am by OfficialEnlightGames Reason: forgot to add photos
hi all

i am having some trouble with these items described in the subject
the wifi shield is connected to the leonardo but the example i use says to me "Wifi Shield Not Present" and i dont see how its not present considering its right here connected

i forgot to say it also has a solid red light in the wifi shield not the leonardo

please help me i payed $63 for these boards and i cant get it to work and i researched the internet for answers and nothing!

pert

Please post a link to where you bought the duinotech wifi shield from so we can be sure what hardware you're referring to.

Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment.

When your code requires a library that's not included with the Arduino IDE please always post a link(using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

OfficialEnlightGames

the code i used was the WiFiWebServer example either used in the esp8266 pack or the preinstalled packs and i cant upload the pictures because the file size is too big and i bought the parts from jaycar electronics http://www.jaycar.com.au/

pert

the code i used was the WiFiWebServer example either used in the esp8266 pack or the preinstalled packs
That's not helpful. I need the exact code you're using, not some vague ramblings.

i cant upload the pictures because the file size is too big
I didn't ask you for pictures. If you did want to post a picture then you should be competent enough to figure out how to resize them. You're trying to learn electronics and programming, this is complex stuff, either turn your brain on or give up now.

i bought the parts from jaycar electronics http://www.jaycar.com.au/
It would be much more helpful for you to post a link to the exact product page for the shield. Why should we have to go searching all over that site for the specific product you bought. It's you asking for help, not me. When you post links to the forum please use the chain links icon on the toolbar to make them clickable.

OfficialEnlightGames

The Code Used...
Code: [Select]
/*
  WiFi Web Server

 A simple web server that shows the value of the analog input pins.
 using a WiFi shield.

 This example is written for a network using WPA encryption. For
 WEP or WPA, change the Wifi.begin() call accordingly.

 Circuit:
 * WiFi shield attached
 * Analog inputs attached to pins A0 through A5 (optional)

 created 13 July 2010
 by dlf (Metodo2 srl)
 modified 31 May 2012
 by Tom Igoe

 */

#include <SPI.h>
#include <WiFi.h>


char ssid[] = "yourNetwork";      // your network SSID (name)
char pass[] = "secretPassword";   // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port 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);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin();
  // you're connected now, so print out the status:
  printWifiStatus();
}


void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}



Arduino Leonardo: https://www.jaycar.com.au/duinotech-lite-leonardo/p/XC4430

Arduino WiFi Shield: https://www.jaycar.com.au/arduino-compatible-esp-13-wifi-shield/p/XC4614

Is this enough info?

pert

Now we have the necessary information to help you. The problem is the WiFi library you're using is not compatible with that shield. It's only for use with the Arduino WiFi Shield:
https://www.arduino.cc/en/Main/ArduinoWiFiShield
The shield you're using is completely different. What you need to know about this shield is it is using the ESP8266 running the AT firmware. The ESP8266 is connected to the Arduino via pins 0 and 1, which on your Leonardo is Serial1. You will be communicating at 115200 baud.

For that shield I recommend the WiFiEsp library:
https://github.com/bportaluri/WiFiEsp
which offers a very similar API to the Arduino WiFi library so any code written for the Arduino WiFi shield can be adapted to use that library without too much work. Since your ESP8266 communicates at 115200, rather than 9600 baud you will need to change the line in any of the example sketches included with the library from:
Code: [Select]
Serial1.begin(9600);
to:
Code: [Select]
Serial1.begin(115200);

OfficialEnlightGames

please tell me exactily in dot points what i have to do with the 0 and 1 pins and the firmware because i tried to flash the firmware but it doesnt seem to recognise it

pert

You don't need to do anything with the 0 and 1 pins. You just plug the shield into your Leonardo and they will be connected.

What do you mean by "flash the firmware"? Are you talking about the firmware on the ESP8266 or uploading a sketch to the Leonardo?

OfficialEnlightGames

so how do i include the librarys of that WifiEsp pack in arduino and import the code for the example sketch and soz im new to arduino its for school and the teacher is new too please help me i still havent got it working

pert

  • Attach the shield to your Leonardo by aligning the pins on the bottom of the shield with the female headers on the Leonardo and pressing it down as far as it will go.
  • Turn the two switches in the blue plastic box on the shield to the on position.
  • Connect the Leonardo to your computer using a USB cable.
  • Tools > Board > Arduino Leonardo
  • Select the port of your Leonardo from the Tools > Port menu
  • Download https://github.com/bportaluri/WiFiEsp/archive/v2.2.1.zip
  • Sketch > Include Library > Add .ZIP Library > Select the downloaded file > OK
  • File > Examples > WiFiEsp > select the example sketch you want to use (I recommend WebServerLed)
  • Change lines 20 and 21 to match the credentials of your WiFi
  • Change line 35 of the example sketch to:

Code: [Select]
 Serial1.begin(115200);
  • At line 37 add:

Code: [Select]
 while(!Serial){}
  • Tools > Serial Monitor
  • Set the menu at the bottom right corner of the Serial Monitor to 115200
  • Close Serial monitor
  • Sketch > Upload
  • Wait for the upload to complete
  • Tools > Serial Monitor
  • After connecting to the network the IP address of your Arduino will be shown in the Serial Monitor. Copy and paste this IP address in to the URL bar on your browser and press Enter.
  • A web page will load that allows you to control the LED on your Leonardo. This LED will be a little hard to see because it's covered by the duinotech WiFi shield but it's near the power jack on the Leonardo.

Note that the code I instructed you to add at line 37 will prevent the sketch from running until the Serial Monitor is opened. This was necessary in order for you to get the Serial Monitor open in time to see the IP address but if you later want to run the sketch without opening the Serial Monitor you should comment out that line.



OfficialEnlightGames

#10
Mar 29, 2017, 11:03 am Last Edit: Mar 29, 2017, 11:21 am by OfficialEnlightGames
thanks very much for the instructions but...
i got this instead

[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
WiFi shield not present

oh and on top of that is there a way to connect this ESP to a WPA2-Enterprise Network like a school network for e.g

and is it normal for that light on the top board just to be solid red and no blue light? because instantly i thought it was fried when i got it out of the box

the code used was the edited one you told me to edit
Code: [Select]
/*
 WiFiEsp example: WebServerLed
 
 A simple web server that lets you turn on and of an LED via a web page.
 This sketch will print the IP address of your ESP8266 module (once connected)
 to the Serial monitor. From there, you can open that address in a web browser
 to turn on and off the LED on pin 13.

 For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif

char ssid[] = "Test";            // your network SSID (name)
char pass[] = "12345678";        // your network password
int status = WL_IDLE_STATUS;

int ledStatus = LOW;

WiFiEspServer server(80);

// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);

void setup()
{
  Serial.begin(115200);   // initialize serial for debugging
  Serial1.begin(115200);    // initialize serial for ESP module
  WiFi.init(&Serial1);    // initialize ESP module

  while(!Serial){}    //wont run toll serial monitor is opened
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  Serial.println("You're connected to the network");
  printWifiStatus();
  
  // start the web server on port 80
  server.begin();
}


void loop()
{
  WiFiEspClient client = server.available();  // listen for incoming clients

  if (client) {                               // if you get a client,
    Serial.println("New client");             // print a message out the serial port
    buf.init();                               // initialize the circular buffer
    while (client.connected()) {              // loop while the client's connected
      if (client.available()) {               // if there's bytes to read from the client,
        char c = client.read();               // read a byte, then
        buf.push(c);                          // push it to the ring buffer

        // printing the stream to the serial monitor will slow down
        // the receiving of data from the ESP filling the serial buffer
        //Serial.write(c);
        
        // you got two newline characters in a row
        // that's the end of the HTTP request, so send a response
        if (buf.endsWith("\r\n\r\n")) {
          sendHttpResponse(client);
          break;
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (buf.endsWith("GET /H")) {
          Serial.println("Turn led ON");
          ledStatus = HIGH;
          digitalWrite(13, HIGH);
        }
        else if (buf.endsWith("GET /L")) {
          Serial.println("Turn led OFF");
          ledStatus = LOW;
          digitalWrite(13, LOW);
        }
      }
    }
    
    // close the connection
    client.stop();
    Serial.println("Client disconnected");
  }
}


void sendHttpResponse(WiFiEspClient client)
{
  // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
  // and a content-type so the client knows what's coming, then a blank line:
  client.println("HTTP/1.1 200 OK");
  client.println("Content-type:text/html");
  client.println();
  
  // the content of the HTTP response follows the header:
  client.print("The LED is ");
  client.print(ledStatus);
  client.println("<br>");
  client.println("<br>");
  
  client.println("Click <a href=\"/H\">here</a> turn the LED on<br>");
  client.println("Click <a href=\"/L\">here</a> turn the LED off<br>");
  
  // The HTTP response ends with another blank line:
  client.println();
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print where to go in the browser
  Serial.println();
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
  Serial.println();
}

pert

I own two of these shields but I bought them from Aliexpress for $7 USD with free shipping (what an absolute ripoff Jaycar is for charging a >$30 markup!!!). They came with this weird DOIT firmware, which is not compatible with the WiFiEsp library or any other library or example code I know of. I replaced that firmware with the standard Espressif AT firmware and was immediately able to successfully use the shield with the WiFiEsp library. My understanding from other people posting here about buying that shield from Jaycar is that it came with the AT firmware instead of the DOIT firmware and there is some evidence to support this in the description on the product page ("Simple AT command interface with Arduino main board", Manual is an AT command reference) but it also says "Web configuration interface" which would indicate the DOIT firmware. The firmware download link on that page includes the AT firmware and the DOIT firmware. So it's quite possible you have the DOIT firmware on your shield, which would cause the error you're seeing when trying to use the WiFiEsp library. You can check by following the instructions for the DOIT firmware here:
https://fineshang.gitbooks.io/esp8266-based-serial-wifi-shield-for-arduino-user/content/chapter4.html

OfficialEnlightGames

what... i never got a "DoitWiFi_Config" when i put together the first time and i tried flashing new firmware on it and it only made the RX light blink it didnt do anything and i tried that web page and i tried this on 4 other computers. when i press the "KEY" button for 3 seconds and i type "!@!" in the serial monitor it gave me a blue screen on 4 DIFFERENT COMPUTERS!?!?!?! serously i hate this thing but i want to pass my subject and i honestly have no idea what the hell is going on with this thing its like i got a stack of paper that was shredded and cant get a refund... im almost loosing it

pert

i tried flashing new firmware on it and it only made the RX light blink it didnt do anything
Please give more details of what you did

OfficialEnlightGames

this was when i didnt know about jaycars failed attempt to provide me with correct firmware

Go Up