2

I am new to using Arduino just bought my first one yesterday, and I also got an WiFi module. The Arduino I got is another brand but should be the same as the Arduino Uno rev 3 and I got the ESP8266-01 wifi module.

I've tried doing some simple examples projects following some YouYube videos, and all those have worked without problem.

What I am trying to create is a simple magnetic door switch. When it's opened I get a signal to my computer. Getting the magnetic door switch wired with the Arduino and getting an LED to light up when the magnetic switch opened worked without problem.

But to set up the wifi module, I can't get it to work.

I have spent hours and hours watching tutorials reading all I can find to trying everything to get this to work, but no luck.

I don't know If I am doing something wrong (probably) or if something is broken.

These are the instructions I am trying currently.

Video of my Arduino setup

For the Arduino board I use 12v DC in and USB from my PC.

Code:

#include "Arduino.h"
#include "ESP8266.h"

#include "SoftwareSerial.h"
SoftwareSerial  ConsoleOut(8, 9);

#define SSID  "ASUS"
#define PWD   "tmpPassword"

void setup() {
  char  *ipAddress, ap[31];

  WiFi.reset(WIFI_RESET_HARD);
  WiFi.begin(9600);
  ConsoleOut.print("flag2");
  if (WiFi.join(SSID, PWD) == WIFI_ERR_OK) {
    ipAddress = WiFi.ip(WIFI_MODE_STA);
    ConsoleOut.print(F("\n\rIP address:"));
    ConsoleOut.print(ipAddress);
    ConsoleOut.print(':');
    ConsoleOut.print("flag1");
    if (WiFi.isConnect(ap))
      ConsoleOut.println(ap);
    else
      ConsoleOut.println(F("not found"));
  } else
    while (1);
}

void loop() {
  if (WiFi.connect((char *)"www.google.co.jp", 80) == WIFI_ERR_CONNECT) {
    if (WiFi.send((const uint8_t *)"GET / HTTP/1.1\r\n\r\n") == WIFI_ERR_OK) {
      int16_t c;
      uint16_t len = WiFi.listen(10000UL);
      while (len)
        if ((c = WiFi.read()) > 0) {
          ConsoleOut.write((char)c);
          len--;
        }
    } else
      ConsoleOut.println(F("Send fail"));
    WiFi.close();
  } else
    ConsoleOut.println(F("TCP connect fail"));
  WiFi.disconnect();
  while (1);
}

Code:

enter image description here

Different from the example sketch is that I use 2K instead of 3K resistors for R2, R4 and 1K for R1, R3. (2K on left side in the video 1K on the right side)

The LED of the WiFi lights red constantly. I don't know what that means, and the blue LED on the wiFi module lights up whenever I upload a sketch to the Arduino.

Thanks in advance. Any help is really, really appreciated.

  • 1
    Did you set the baud rate of the esp to 9600? Setting it in code is not enough. – Jamie Dec 22 '17 at 18:10
  • @Jamie when I read other people doing that they say they bricked the esp8266, I changed it to 115200 in code, I believe that is the default?not that It really made any difference, if I try to send command in the serial monitor nothing happens. – Patrik Fröhler Dec 22 '17 at 18:55
  • SoftwareSerial can't handle that speed. 9600 is the maximum. I'll write an answer because I've to paste some code you can use. – Jamie Dec 22 '17 at 19:07
  • @PatrikFröhler What library are you using, could you send a link? – Jamie Dec 22 '17 at 19:13
  • library github.com/Hieromon/ESP8266 – Patrik Fröhler Dec 22 '17 at 19:33
1

Use this code to send commands to the ESP:

#include <SoftwareSerial.h>

    SoftwareSerial esp8266(2, 3);

    void setup() {
      Serial.begin(9600);

      esp8266.begin(9600);
    }

    void loop() {
      while(esp8266.available()) {
         Serial.write(esp8266.read());
      }

      while(Serial.available()) {
        esp8266.write(Serial.read());
      }
    }

This simply reads everything from the ESP chip and sends it to the console and vica versa.

To modify the baud rate on the chip, send the following command in the serial monitor:

AT+UART_DEF=9600,8,1,0,0

This sets the baud rate to 9600 and remembers it for further use.

  • Nothing happens with that code serial monitor blank, what should I have the serial monitor set to when trying to send commands? – Patrik Fröhler Dec 22 '17 at 19:23
  • I recommend 9600. You probably won't see anything at first. But after a reset you should see your responses. To test responses send the following command: AT, you should get OK bad. – Jamie Dec 22 '17 at 19:28
  • After I reset I only get " ⸮ ⸮ ⸮⸮ " in the serial monitor nothing happens when trying AT – Patrik Fröhler Dec 22 '17 at 19:32
  • The two other problems i can only think of is using other resistors than 1k and a different voltage than 3.3 volt.. – Jamie Dec 22 '17 at 19:58
  • Try another library, because I just tested yours and it doesn't work for me as well. github.com/itead/ITEADLIB_Arduino_WeeESP8266 – Jamie Dec 22 '17 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.