-->
Page 1 of 1

esp8266-01 and arduino

PostPosted: Thu Nov 26, 2015 2:44 pm
by alexgr2006
Hello I use App inventor for android applications and arduino and esp8266-01
(My esp8266 is:Image).

my connection esp8266+arduino is:
ESP8266 ====== Arduino
TX ====== 11 pin
RX ====== 10 pin
GND ====== GND
CH_PD ====== 3.3V
+3v3 ====== 3.3V
RST ====== -------
GPIO2 ====== -------
GPIO0 ====== -------

My code for app inventor:
Image

if i press the button from my android app the led is on and if realease the button the led is off but sometimes stuck..
can help anyone?

My arduino code is:
Code: Select all
    #include <SoftwareSerial.h>
   
    #define DEBUG false
     
    SoftwareSerial esp8266(11,10); // make RX Arduino line is pin 11, make TX Arduino line is pin 10.
                                 // This means that you need to connect the TX line from the esp to the Arduino's pin 11
                                 // and the RX line from the esp to the Arduino's pin 10
    void setup()
    {
     
     
      Serial.begin(9600);     
      esp8266.begin(115200); // your esp's baud rate might be different
     
      pinMode(8,OUTPUT);
      digitalWrite(8,LOW);
     
      pinMode(6,OUTPUT);
      digitalWrite(6,LOW);
     
      pinMode(9,OUTPUT);
      digitalWrite(9,LOW);
     
     
     sendData("AT+RST\r\n",2000,DEBUG); // reset module
     sendData("AT+CWMODE=2\r\n",1000,DEBUG); // configure as access point   AP=2, STA=1, 3=BOTH
     sendData("AT+CIFSR\r\n",1000,DEBUG); // get ip address
     sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections
     sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80
     
       
     
    }
     
    void loop()
    {
     
 
     
      if(esp8266.available()) // check if the esp is sending a message
      {
     
       
        int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
                                               // the ASCII decimal value and 0 (the first decimal number) starts at 48
//**************************************************
               String t;
               
                esp8266.find("/?"); // advance cursor to "pin="
               while (esp8266.available())
                 {
                 
                  t+=(char)esp8266.read();//read byte,convert to char and append it to string
                  if (t.length()==2){break;}
                 }
             
              if(t=="on")
                    {
             digitalWrite(8, HIGH);
                Serial.write("ON \n");
               
                    }
              else if(t=="of")
                {
                  digitalWrite(8, LOW);
                Serial.write("OFF \n");
               
                }

                if(t=="6o")
                    {
             digitalWrite(6, HIGH);
                Serial.write("LED is ON \n");
               
                    }
              else if(t=="6f")
                {
                  digitalWrite(6, LOW);
                Serial.write("LED is OFF \n");
               
                }
                 
//***************************************************
             
     
         
       
         
         // make close command
       String closeCommand = "AT+CIPCLOSE=";
       closeCommand+=connectionId; // append connection id
       closeCommand+="\r\n";
         
         sendData(closeCommand,10,DEBUG); // close connection.

     // }
    }
   
    }//loop
   
    /*
    * Name: sendData
    * Description: Function used to send data to ESP8266.
    * Params: command - the data/command to send; timeout - the time to wait for a response; debug - print to Serial window?(true = yes, false = no)
    * Returns: The response from the esp8266 (if there is a reponse)
    */
    String sendData(String command, const int timeout, boolean debug)
    {
        String response ="";
       
        esp8266.print(command); // send the read character to the esp8266
       
        long int time = millis();
       
        while( (time+timeout) > millis())
        {
          while(esp8266.available())
          {
           
            // The esp has data so display its output to the serial window
            char c = esp8266.read(); // read the next character.
            response+=c;
           
          } 
         
       
        }
       
        if(debug)
        {
          Serial.print(response);
        }
       
        return response;
    }//end sendData

Re: esp8266-01 and arduino

PostPosted: Fri May 06, 2016 2:30 am
by wildhorse
Hi
I am unable to see any images on your page
Re: app inventor image
can you send them to my email account
thanks
keven

Re: esp8266-01 and arduino

PostPosted: Fri May 06, 2016 2:32 pm
by wildhorse
Hi very well infomed sketch
It seems i can not see any images of the appinventor
Could you please send them to me
Keven@wildhorsegraphics.com.au