Go Down

Topic: Help: cant get the esp8266-01 work with my oled (Read 303 times) previous topic - next topic

TorNim0s

Hello, I am building a project and i need to use the esp8266-01 to get data from the internet and the oled to show the data in real time.
But when i use the library of the oled - #include <SFE_MicroOLED.h>
it appears that the esp8266 cant get the data right.
here some pictures of the problam:
the picture that you can see get the data and transfer it correctly is without including the library and the second that i get the data but it wont translate the data is with the library


i hope someone can help.
and here is the code :


int hour=0;
int minute=0;
int second=0;
int b=0;
#define ESP8266_BAUD  9600  // You may need change it (to 56700, 115200 or other) based on your ESP8266 configuration
// If SoftwareSerial is used:
#define SS_RX 5
#define SS_TX 6

// Uncomment the below line for using Serial1 (for ex. on Arduino MEGA)
#define SW_SERIAL

#ifdef SW_SERIAL
  #include <SoftwareSerial.h>
  SoftwareSerial ESP8266_PORT(SS_RX, SS_TX);
#else
/*
 * On Arduino MEGA, you can choose between three serial ports:
 * Serial1 on pins 19 (RX) and 18 (TX)
 * Serial2 on pins 17 (RX) and 16 (TX)
 * Serial3 on pins 15 (RX) and 14 (TX)
*/
  #define ESP8266_PORT  Serial1
#endif

#define ONBOARD_LED   12    // Onboard indicator
int button=2;
int led=13;
int bazzer=7;

/* Replace with your AP name/password */
const String ESP8266_APNAME  = "Name";
const String ESP8266_APPSWD  = "Pass";

String ESP8266_CMD;
int CheckButton;

void setup()
{
  pinMode(led,OUTPUT);
  pinMode(button,INPUT);
  pinMode(bazzer,OUTPUT);
  pinMode(ONBOARD_LED, OUTPUT);
  digitalWrite(bazzer,HIGH);
 
  Serial.begin(115200);             // Debug port
  ESP8266_PORT.begin(ESP8266_BAUD); // ESP8266 port

  delay(1000);

  ESP8266_Init();
}


void ESP8266_Init()
{
  String ESP8266_CMD, WWWResponse;

 
  Serial.println("Connecting to WiFi (" + ESP8266_APNAME + ", " + ESP8266_APPSWD + "), please wait...");
  ESP8266_Send("AT+CWMODE=1", 100, false);
  WWWResponse=ESP8266_Send("AT+CWJAP=\"" + ESP8266_APNAME + "\",\"" + ESP8266_APPSWD + "\"", 5000, false);
  if(find_text("CONNECTED", WWWResponse) == 0)
  {
    Serial.println("Error: can't connect to AP.");

    digitalWrite(ONBOARD_LED, 0);
    while(1);
  }
  else
  {
    Serial.println("Ready!");


      if (ESP8266_PORT.available()) {
    int inByte = ESP8266_PORT.read();
    Serial.write(inByte);
     }

      eldad_connect();

         
           
     
         
           
   
   
    while(Serial.available())
      Serial.read();
  }
}
void eldad_connect(){
   String ESP8266_CMD, WWWResponse;
     String hour1;
  String minute1;
  String second1;

          ESP8266_Send("AT+CIPSTART=\"TCP\",\"ortyuvali.arduino2web.com\",80", 1000, false);
          ESP8266_CMD="GET /Eldad/watch/time.txt HTTP/1.1\r\nHost: ortyuvali.arduino2web.com\r\n\r\n";
          ESP8266_Send("AT+CIPSEND="+String(ESP8266_CMD.length()), 1000, false);
          WWWResponse=ESP8266_Send(ESP8266_CMD, 1000, true);
          // Access the file
          Serial.println("accesing hour");
            int idPos=(find_text("hour", WWWResponse));
            if(WWWResponse.substring(idPos, idPos+4) == "hour")
           {
           hour1 = WWWResponse.substring(idPos+5,idPos+7);
           minute1 = WWWResponse.substring(idPos+8,idPos+10);
           second1 = WWWResponse.substring(idPos+11,idPos+13);
           b=5;

           while(Serial.available())
              Serial.read();
           }
           Serial.println(hour1);
           Serial.println(minute1);
           Serial.println(second1);

           hour = hour1.toInt();
           minute = minute1.toInt();
           second = second1.toInt();

           Serial.println(hour);
           Serial.println(minute);
           Serial.println(second);       

           


}

void loop() {
  // read from port 1, send to port 0:
  if (ESP8266_PORT.available()) {
    int inByte = ESP8266_PORT.read();
    Serial.write(inByte);
  }

      Serial.println("Accessing http://ortyuvali.arduino2web.com/ESP8266/id.txt...");
      ESP8266_Connect();

}


void ESP8266_Connect()
{
  String ESP8266_CMD, WWWResponse;
 
  ESP8266_Send("AT+CIPSTART=\"TCP\",\"ortyuvali.arduino2web.com\",80", 1000, false);
  ESP8266_CMD="GET /Eldad/value.txt HTTP/1.1\r\nHost: ortyuvali.arduino2web.com\r\n\r\n";
  ESP8266_Send("AT+CIPSEND="+String(ESP8266_CMD.length()), 1000, false);
  WWWResponse=ESP8266_Send(ESP8266_CMD, 1000, false);
  // Access the file
  int idPos=(find_text("Ring", WWWResponse));
  if(WWWResponse.substring(idPos, idPos+4) == "Ring")
  {
    Serial.println("Led is on");
    digitalWrite(led,HIGH);
     digitalWrite(bazzer,LOW);
    CheckButton = digitalRead(button);
    while(CheckButton<1){
    CheckButton = digitalRead(button);
    }
    ESP8266_Send("AT+CIPSTART=\"TCP\",\"ortyuvali.arduino2web.com\",80", 1000, false);
    ESP8266_CMD="GET /Eldad/fupdate.php?value=not HTTP/1.1\r\nHost: ortyuvali.arduino2web.com\r\n\r\n"; // send to not to the web so it will not continue to vipe
    ESP8266_Send("AT+CIPSEND="+String(ESP8266_CMD.length()), 1000, false);
    ESP8266_Send(ESP8266_CMD, 1000, false);
 
    while(Serial.available())
      Serial.read();
  }
  else
  Serial.println("Led is off");
    digitalWrite(led,LOW);
    digitalWrite(bazzer,HIGH);
   
}


// Send command to ESP8266
String ESP8266_Send(String command, const int timeout, boolean debug)
{
    String response = "";
   
    ESP8266_PORT.println(command); // Send the command to ESP8266
   
    long int time = millis();
   
    while( (time+timeout) > millis())
    {
      while(ESP8266_PORT.available())
      {
        // The ESP8266 has data, so display its output to the serial window
        char c = ESP8266_PORT.read(); // read the next character.
        response+=c;
      } 
    }
   
    if(debug)
    {
      Serial.print(response);
    }
   
    return response;
}


int find_text(String needle, String haystack) {
  int foundpos = 0;
  for (int i = 0; i <= haystack.length() - needle.length(); i++) {
    if (haystack.substring(i,needle.length()+i) == needle) {
      foundpos = i;
    }
  }
  return foundpos;
}

ieee488

#1
Dec 11, 2017, 10:26 pm Last Edit: Dec 11, 2017, 10:26 pm by ieee488
If your OLED display and your ESP-01 are both using the same serial port on the Arduino Uno, it is no wonder your sketch won't work.

TorNim0s

they are not in the same serial port, and i dont even use the oled i only including the library of it in the code and it makes the data that i get from the esp8266 unable to translate to use like in the picture.

ieee488

#3
Dec 12, 2017, 04:23 am Last Edit: Dec 12, 2017, 04:24 am by ieee488
If each work alone, then the OLED library is conflicting with the ESP-01 library in some manner.
You need to investigate the OLED library and the ESP8266 library that you are using.

TorNim0s

allready done that and i found nothing that conflicting betwin them

TorNim0s

If someone have another code that connects to the internet and show the data in the oled i would like it to make it an example of another way to do it.

Go Up