CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

esp8266 my coding

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hsogukpinar



Joined: 20 Sep 2021
Posts: 8

View user's profile Send private message Send e-mail

esp8266 my coding
PostPosted: Thu May 25, 2023 12:49 pm     Reply with quote

Dear friends,

I tried to edit ESP8266 for wifi access but it doesn't IP from modem.

Please edit my coding.
Code:

// Interfacing PIC16F877A with SSD1306 OLED display (128x64 Pixel)
// http://simple-circuit.com/
 
#define SSD1306_RST   PIN_D4
 
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP                       
#use delay(clock = 8MHz)
#use I2C(MASTER, I2C1, FAST = 400000, stream = SSD1306_STREAM)  // Initialize I2C
#use rs232 (baud=115200, xmit=PIN_C6, rcv=PIN_C7)  // Initialize UART protocol (needed for FAT library)
//#use rs232(uart1, baud = 9600)  // Initialize UART module

// Include SSD1306 OLED driver source code
#include <SSD1306.c>
#include <string.h>

#define ESP8266BUFFER_LENGHT 500
#define SSID            "G510"
#define PASSWORD         "haci123."
int16 i = 0;
   char TempStr[];
 char ESP8266Buf[ESP8266BUFFER_LENGHT];
static uint16_t ESPWriteIndex=0;

static void Clear_ESPBuffer(void)
{
    uint16_t i;
    for(i=0;i<ESP8266BUFFER_LENGHT;i++)
        ESP8266Buf[i] = 0;
    ESPWriteIndex=0;
}

void main() { 
   static uint8_t ESPInitCase=0;
  // Initialize the SSD1306 OLED with an I2C addr = 0x7A (default address)
  SSD1306_Init(SSD1306_SWITCHCAPVCC, SSD1306_I2C_ADDRESS);
  // clear the display
  SSD1306_ClearDisplay();
  SSD1306_GotoXY(1, 1);
  SSD1306_PutC("MERHABA");
  delay_ms(1000);
  SSD1306_ClearDisplay();
  SSD1306_GotoXY(6, 2);
  SSD1306_PutC("Merhaba! Merhaba");
  delay_ms(1000);
 
     fputs("AT+CWMODE=1\r\n");
       fputs("AT+RST\r\n");
    while(true)
    {
    switch(ESPInitCase)
    {
        case 0:
            // Standart AT Komutu gonderilir , Cevabi OK olmalidir.
            SSD1306_PutC("Standart AT Komutu gonderiliyor");
            delay_ms(1000);
            fputs("AT\r\n");   
            ESPInitCase = 1;
            SSD1306_ClearDisplay();
   ESPInitCase = 1;
        break;

        case 1:
            // STRSTR fonksiyonu metin icinde metin arayan bir fonksiyondur
            // Eger aranilan metni bulabilirse pointer adresi ile geri donus yapar
            // Bulamaz ise NULL dondurur. Bizde null'dan farklı mı diye sorariz.
            strcpy(TempStr,"OK");
            if (strstr(ESP8266Buf,TempStr)!=NULL)
            {
             Clear_ESPBuffer();
             SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("Module Erisildi");
  delay_ms(1000);
                ESPInitCase = 2;
            }
            else
            {
             Clear_ESPBuffer();
           SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("Modul Bulunamadi Tekrar Deneniyor");
  delay_ms(1000);
                ESPInitCase = 0;
            }
        break;

        case 2:
         SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("Modulun 3 modu var  1 olmasini istiyoruz");
  delay_ms(1000);
   Clear_ESPBuffer();
            // Modulun 3 modu var gerekli bilgi datasheet'de biz 1 olmasini istiyoruz
           
            fputs("AT+CWMODE?\r\n");
            // 1 saniye gecikme koyuyoruz.
            ESPInitCase = 3;
           
        break;

        case 3:
            // Gelen cevap mode 1 'mi
            strcpy(TempStr,"+CWMODE:1");
           
          if (strstr(ESP8266Buf,TempStr)!=NULL)
            {
            Clear_ESPBuffer();
               
  SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("MODE Ayar Dogru");
  delay_ms(1000);
               
                ESPInitCase = 4;
            }
            else
            {
            SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("Fabrika ayarları olarak 2 geliyor biz onu 1 yapip reset komutu ile tamamlariz");
                // Fabrika ayarları olarak 2 geliyor biz onu 1 yapip reset komutu ile tamamlariz.
                 Clear_ESPBuffer();
                fputs("AT+CWMODE=1\r\n");
                fputs("AT+RST\r\n");
                delay_ms(1000);

              SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
  SSD1306_PutC("MOD Degistirilir.");
    Clear_ESPBuffer();
  delay_ms(1000);
               
                ESPInitCase = 0;
            }
        break;

        case 4:
            // Baglanilacak olan wifi agina ait kullanici adi ve sifre girisi yapilir.
  Clear_ESPBuffer();
       fputs("AT+CWJAP=\"");       
      fputs("G510");
   fputs("\",\"");
    fputs("haci123.");
  fputs("\"\r\n");
 fputs("AT+CWJAP=""G510\",\"haci123.\"");
            // 1 saniye gecikme koyuyoruz.
            delay_ms(1000);
            ESPInitCase = 5;
        break;

         case 5:
             // Baglanti saglandiginde OK Cevabi alinir
            strcpy(TempStr,"OK");
               if (strstr(ESP8266Buf,TempStr)!=NULL)
             
            {
             Clear_ESPBuffer();
              SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("Modeme Baglanti yapildi.");
                delay_ms(1000);
                ESPInitCase = 6;
            }
            else
            {
             SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("Baglanti Bekleniyor.");
               ESPInitCase = 4;
                delay_ms(1000);
               
            }
        break;

        case 6:
         Clear_ESPBuffer();
            // IP adresi nedir diye soruyoruz ?
             fputs("AT+CWJAP=""G510\",\"haci123.\"");
              Clear_ESPBuffer();
            fputs("AT+CIFSR\r\n");
            // 1 saniye gecikme koyuyoruz.
            SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("IP adresi nedir diye soruyoruz");
                delay_ms(100);
            ESPInitCase = 7;
        break;

        case 7:
            // IP alana kadar error bilgisi gonderir. Onu ayırırız. =)
            strcpy(TempStr,"ERROR");
             if (strstr(ESP8266Buf,TempStr)==NULL)
            {
                SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("Alinan IP = ");
                delay_ms(100);
                // Gelen bilginin 11.karakterinden itibaren IP adresi yaziyor.
                fputs(&ESP8266Buf[11]);
               
                  SSD1306_GotoXY(2, 4);
               SSD1306_PutC(&ESP8266Buf[11]);
                delay_ms(1000);
              Clear_ESPBuffer();
                ESPInitCase=8;
            }
            else
            {
                // ERROR der ise tekrar dene
                SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("Tekrar Dene.");
                 Clear_ESPBuffer();
                delay_ms(1000);
                ESPInitCase=6;
            }

        break;

        case 8:
            // Baglanilacak siteye ait bilgiler girildi.
            fputs("AT+CIPSTART=\"TCP\",\"www.picproje.org\",80\r\n");
            // 1 saniye gecikme koyuyoruz.
            delay_ms(1000);
            ESPInitCase = 9;
        break;

        case 9:
            // Baglanti kuruldugunda Linked diye bir cevap aliriz.
            strcpy(TempStr,"Linked");
     if (strstr(ESP8266Buf,TempStr)!=NULL)
            {
               
                fputs("Server ile baglanti kuruldu");
                ESPInitCase = 10;
            }
            else
            {
                // Cevap gelene kadar bekler
                 SSD1306_ClearDisplay();
              SSD1306_GotoXY(1, 2);
               SSD1306_PutC("Tekrar Dene.");
                delay_ms(1000);
                fputs("Baglanti Bekleniyor.");
            }
        break;

        case 10:
            // We can now send our HTTP Request. With CIPSEND,
            // we write as many bytes of information as we send.
           
            fputs("AT+CIPSEND=100\r\n");
            // Komutu verdikten sonra bize '>' bilgisi geliyor.
            delay_ms(1000);
            // HTTP Request Hazirlanir.
            fputs("GET / HTTP/1.1\r\n");
            fputs("Host: www.picproje.org\r\n");
            fputs("Accept: */*\r\n");
            fputs("Content-Type: text/html\r\n");
            fputs("Content-Length: 0\r\n\r\n\r\n");

            // From here, by evaluating the answers to the http request
           // You can do whatever you want to do =)
             
         
        break;

    }
}
  }
// End of code
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri May 26, 2023 4:28 am     Reply with quote

Voltage, voltage, voltage.

The PIC16F877A is a 5v PIC. Minimum supply voltage 4v.
The genuine SSD1306, only supports operation up to 3.3v. However most
of the boards sold as SSD1306, actually now use third party controllers
that support up to 5v operation. So this may well work.

However the ESP8266, does not.
It is a 3.3v device.
Even if you have a board that has a 3.3v regulator and therefore
does not get blown up by connecting it to 5v, the chip outputs will only
be 3.3v, and will not go high enough to be recognised by a 5v PIC.
You need am interface between the ESP and the PIC to bring the serial
lines up to a voltage the PIC can accept.
If you have connected an ESP8266 to 5v without a regulator, you will
have probably killed the module. It accepts 3.6v max. It also does not
have 5v tolerant inputs.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri May 26, 2023 5:06 am     Reply with quote

Hmm, he might be using the 18f4550 ? If so Mr T's comment 'voltage,Voltage, VOLTAGE' still applies !
You'll need to use the 'L' version of whatever PIC or 'logic level translators' between the 5 volt PIC an d the 3 volt ESP chip.
If the ESP chip is really a 'module' it 'may' be designed for 5 volt operation, would have to see the datasheet to confirm/deny that though.

Since almost all peripheral devices today are '3 volt', I suggest only using 'L' version of PICs or PICs that actually will run at both 3 and 5 volts. The PIC18F46K22 is one such device.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri May 26, 2023 5:26 am     Reply with quote

Absolutely.

However problem with most 'modules', is they are built to interface to chips
like the Arduino. So they have resistive dividers to cope with the step
from a 5v output processor device driving into a 3.3v chip, but because
the Arduino has inputs that accept 2.4v as a logic '1', they have no buffering
on the 3.3v outputs. The PIC, both on it's serial inputs, and it's SPI inputs
has Schmitt inputs that require the signals to typically go up to 4v. So
hardware buffering is needed even when using one of these boards.... Sad
hsogukpinar



Joined: 20 Sep 2021
Posts: 8

View user's profile Send private message Send e-mail

esp8266
PostPosted: Mon May 29, 2023 1:46 pm     Reply with quote

Dear friends,

there is no problem for 3.3 V I am applying 5V to PIC18f4550 and 3.3V to the esp8266 and I send AT command and received OK, but problem is related to Wi-Fi connection and IP address receiving. AT, ATE, CWMODE answering but i am providing Wi-Fi from cell phone, but not connecting, no IP taking, please solve the IP address problems, I am waiting advice.
Best regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue May 30, 2023 12:03 am     Reply with quote

Seriously there _is_ a problem with 5v/3,3v.

The ESP module does not have 5v tolerant inputs.
The PIC outputs will be going up to almost 5v.
You are almost certainly driving the ESP modules supply rail up from the
PIC logic signals. Result the ESP will be above it's rated voltage, and the
PIC outputs will be overloaded, and possibly it's supply drawn down.
Try testing the actual voltages that or on the PIC and the ESP chip while
the PIC is connected. I suspect you will have a nasty surprise...
Probably the PIC voltage is dropping to perhaps 4v, and the ESP is
being driven up to perhaps 3.5v. You are getting away with it, but are
asking 'long term' for damage to both chips.
The ESP has a default IP of 192.168.4.1. If this is not in the IP range
supported by your phone's access point, you either have to change
the IP of the ESP into the range supported by the phone, or change the
range that the phone operates into with it's access point.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group