Category Archives: Arduino

Connect Arduino and BMP 180 to Cloud

BMP 180 connect to Cloud

 

BMP-180

  1. SCL – Grey wire
  2. SDA – Orange Wire

 

Notes:

  • Here the hardware TX and RX has been used for performance.

 

The code:

See Arduino – Communicate with Server – Part 1

Updated code will be posted here some time soon.

For more details on ESP 8266 please see the article “https://www.kolkataonweb.com/code-bank/arduino/esp8266-esp-01/

Arduino – Bluetooth Communication Using HC-05

HC-05 is  a cheap (and easy to use) module that can be used to provide bluetooth connectivity to Arduino.

There are cheap breakout boards available on ebay that can be powered directly by the 5v supply of the Arduino. Below is a picture of such a breakout board. Though my board has “level 3.3v” written but it is working fine on 5v I/O levels. I haven’t run it continuously for days yet but at least a few hours didn’t kill the chip.

HC-05 Bluetooth Module

Jpeg

Some of these boards has one problem - the EN/Key pin, of the board, required for programming the chip (through AT commands) is not connected to the EN/Key pin of the chip. To program the chip on such a board, manual shorting is needed (using some wire) between the EN/Key chip on the board and the chip. In the above picture the EN/Key pin has been marked.

The circuit is pretty simple, connect the VCC to the 5v supply of Arduino, GND to GND, Rx of the module to Tx of Arduino and Tx of the module to Rx of Arduino. For the Rx and Tx software serial ports can be used also.

HC-05 with Arduino

 

The same circuit goes for HM-10 too, which is a BLE device.

ESP 8266 – ESP 01 – Installing Non-OS SDK

After a bit of trial and error got the Non-OS SDK installed. To flash the Non-OS SDK, two sets of files are needed. Below are the download links

 

The flashing tool is attached here for convenience.

 

Now the important part, the mapping (where I was going wrong) and flashing. Please check the documentation for the appropriate mapping. This is for Flash Size & Map: 8Mbit(512KB+512KB)

  • ESP8266_NONOS_SDK_V1.5.2_16_01_29\esp_iot_sdk_v1.5.2\bin\blank.bin    —         0x7e000
  • AT_V0.60_on_ESP8266_NONOS_SDK_V1.5.2_20160203\at\noboot\eagle.flash.bin       —      0x00000
  • ESP8266_NONOS_SDK_V1.5.2_16_01_29\esp_iot_sdk_v1.5.2\bin\esp_init_data_default.bin  —    0xfc000
  • ESP8266_NONOS_SDK_V1.5.2_16_01_29\esp_iot_sdk_v1.5.2\bin\blank.bin           —   0xfe000
  • AT_V0.60_on_ESP8266_NONOS_SDK_V1.5.2_20160203\at\noboot\eagle.irom0text.bin    —     0x40000

 

Non OS SDK Firmware Image Mapping

 

Here is the AT command manual for ESP 8266

 

As on date of writing a Patch has been released which can be downloaded from here or here  —  this patch didn’t work for me. The module is constantly sending some garbage making it unusable. 

DS-1302 RTC Clock Module for Arduino

DS-1302 from Maxim (data sheet download) is a cheap RTC chip. Below are some of the salient features.

  1. Real-Time Clock Counts Seconds,Minutes, Hours, Date of the Month, Month, Day of the Week, and Year with Leap-Year Compensation Valid Up to 2100
  2. Simple 3-Wire Interface
  3. 2.0V to 5.5V Full Operation
  4. TTL-Compatible (VCC = 5V)
  5. 31 x 8 Battery-Backed General-Purpose RAM
There are breakout boards available on ebay, which will be handy to build RTC based projects with Arduino. Look for China based sellers for a cheap price.
DS-1302 RTC 2 DS-1302 RTC 1DS-1302 RTC 3DS-1302 RTC 4
Though there are various modules available but the above two types I found to be working properly.
The below board didn't work at all. Notice the PCB trace which indicates the poor quality.Unfortunately there was no way to know this before delivery.

DS-1302 RTC - Bad  DS-1302 RTC - Bad 2
For those modules which has two power pins (VCC1 and VCC2), power to be connected to VCC2, VCC1 is connected to battery
The below code can be used to used to write and read time from the chip. Credit for the DS1302 library used here goes to Matt Sparks.  The library can be downloaded from Github and also from here (in case it goes off from Github).
Below is a code snippet (based on Matt Spark’s work) for setting time and reading it back easily. Please note for writing to the chip VCC2 needs to be given power (I used 5v).
    //http://datasheets.maximintegrated.com/en/ds/DS1302.pdf

    #include <DS1302.h>
    //#include <SoftwareSerial.h>

    //SoftwareSerial mySerial(2, 3); // RX, TX

    namespace {

      // Set the appropriate digital I/O pin connections.
      
      const int kCePin   = 8;  // Chip Enable (Some calls it Reset)
      const int kIoPin   = 7;  // Input/Output
      const int kSclkPin = 6;  // Serial Clock
      
      // Create a DS1302 object.
      DS1302 rtc(kCePin, kIoPin, kSclkPin);
      
      String dayAsString(const Time::Day day) {
        switch (day) {
          case Time::kSunday: return "Sunday";
          case Time::kMonday: return "Monday";
          case Time::kTuesday: return "Tuesday";
          case Time::kWednesday: return "Wednesday";
          case Time::kThursday: return "Thursday";
          case Time::kFriday: return "Friday";
          case Time::kSaturday: return "Saturday";
        }
        return "(unknown day)";
      }
      
      void printTime() {
        // Get the current time and date from the chip.
        Time t = rtc.time();
      
        // Name the day of the week.
        const String day = dayAsString(t.day);
      
        // Format the time and date and insert into the temporary buffer.
        char buf[50];
        snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
                 day.c_str(),
                 t.yr, t.mon, t.date,
                 t.hr, t.min, t.sec);
      
        // Print the formatted string to serial so we can see the time.
        Serial.println(buf);
        //mySerial.println(buf);
      }

    }  // end of namespace

    void setup() {
      Serial.begin(9600);
      //mySerial.begin(38400);
      // Initialize a new chip by turning off write protection and clearing the clock halt flag.
      rtc.writeProtect(false); //should be set to true after writing to prevent accidental writes
      rtc.halt(false);

      // Year month day hour min sec. DOW
      Time t(2016, 2, 28, 19, 9, 30, Time::kSunday);

      // Set the time and date on the chip.
      rtc.time(t);  //after writing once, comment/remove this code to prevent unnecessary/wrong re-writing of the time
    }

    // Loop and print the time every 5 seconds.
    void loop() {
      printTime(); //prints the date and time
      
      delay(5000);
    }

Arduino – Communicate With Server – Part 3 – Web Based Panel

This is the code for the web based panel (web based UI) that will display the data received from arduino or can send some command to the Arduino

All communications are done through a server (web server)

The frontend code

<?php
date_default_timezone_set("Asia/Kolkata");
$conn = mysql_connect("localhost","root","xxxxxxxxxx");
if(!$conn)
{
    echo "Error: failed to connect DB";
    die();
}

if(!mysql_select_db("xxxxxxxx",$conn))
{
    echo "Error: failed to connect DB";
    die();
}
$jsonArray1 = array();
$jsonArray2 = array();
$i=0;

$result = mysql_query("select * from weather");
while($rows = mysql_fetch_array($result))
{
    $jsonArray1[$i] = array(date("Y,m,d,H,i",$rows['time']), floatval($rows['temperature']));
    $jsonArray2[$i++] = array(date("Y,m,d,H,i",$rows['time']), floatval($rows['paM']));
}
?>
<html>
  <head>
  <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript">
      var chart, chart2;
      window.onload = function () {
        chart = new CanvasJS.Chart("chartContainer",
        {
          title:{
          text: "Temperature"
          },
          axisY:{
            minimum: 0,
            maximum: 50      
          },
           data: [
          {
            type: "line",
    
            dataPoints: [
            <?php
                for($j=0;$j<$i;$j++)
                {
           ?>
                       { x: new Date(<?php echo $jsonArray1[$j][0] ?>), y: <?php echo $jsonArray1[$j][1] ?> } <?php echo $j<$i-1?"," :"" ?>
           <?php         
                }
            ?>            
            ]
          }
          ]
        });
    
        chart.render();
        
        
        chart2 = new CanvasJS.Chart("chartContainer2",
        {
          title:{
          text: "paM"
          },
          axisY:{
            minimum: 1000,
            maximum: 1040      
          },
           data: [
          {
            type: "line",
    
            dataPoints: [
            <?php
                for($j=0;$j<$i;$j++)
                {
           ?>
                       { x: new Date(<?php echo $jsonArray2[$j][0] ?>), y: <?php echo $jsonArray2[$j][1] ?> } <?php echo $j<$i-1?"," :"" ?>
           <?php         
                }
            ?>            
            ]
          }
          ]
        });
    
        chart2.render();
      }
      
    function updateTemp() 
    {
        var str = JSON.parse(updateData("t"));
        var date = str[1].split(",");
        chart.options.data[0].dataPoints.push({x : new Date(date[0],date[1],date[2],date[3],date[4]),  y : parseFloat(str[0]) });
          
        chart.render();         
    };
    
    function updatePressure() 
    {
          var str = JSON.parse(updateData("p"));
          var date = str[1].split(",");
        chart2.options.data[0].dataPoints.push({ x : new Date(date[0],date[1],date[2],date[3],date[4]), y : parseFloat(str[0]) });
        chart2.render();
    };
    
    function updateData(type)
    {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", "dataPlotter.php?q=" + type, false);
        xmlhttp.send();
        return xmlhttp.responseText;
    }
    
    setInterval("updateTemp()",360000);
    setInterval("updatePressure()",480000);
    
  </script>
  </head>

  <body>
<?php
$result = mysql_query("select * from led_status");
$rows = mysql_fetch_array($result);
?>  
      LED 1 <input type="checkbox" value="<?php echo $rows['led_1']==1 ? 1 : 0 ?>" <?php echo $rows['led_1']==1 ? "checked="checked"" : "" ?> id="led_1" name="led_1" onclick="changeLEd('led_1')" />
      LED 2 <input type="checkbox" value="<?php echo $rows['led_2']==1 ? 1 : 0 ?>" <?php echo $rows['led_2']==1 ? "checked="checked"" : "" ?> id="led_2" name="led_2" onclick="changeLEd('led_2')" />
    <!--Div that will hold the column chart-->
    <div id="chartContainer" style="height: 300px; width: 100%;"></div>
    
    <div id="chartContainer2" style="height: 300px; width: 100%;"></div>
    
    <script src="canvasjs.min.js"></script>
    <script src="jquery.canvasjs.min.js"></script>
    
    <script type="text/javascript">
        function changeLEd(whichLed)
        {
            var state;
            
            if(document.getElementById(whichLed).checked == true)
            {
                state = 1;
            }
            else
            {
                state = 0;
            }
            
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", "change-led.php?which="+whichLed+"&state="+state, false);
            xmlhttp.send();
            return xmlhttp.responseText;
        }
    </script>
  </body>
</html>

The backend codes

dataplotter.php

<?php
date_default_timezone_set("Asia/Kolkata");
$conn = mysql_connect("localhost","root","xxxxxxxxxx");
if(!$conn)
{
    echo "Error: failed to connect DB";
    die();
}

if(!mysql_select_db("xxxxxxxx",$conn))
{
    echo "Error: failed to connect DB";
    die();
}
$jsonArray = array();
$i=0;

if(isset($_GET['q']) && strlen(strip_tags($_GET['q'])))
{
    $type = strip_tags($_GET['q']);
}
else
{
    $type = "t";
}

if($type == "t")
{
    $type = "temperature";
}
else
    if($type == "p")
    {
        $type = "paM";
    }

$result = mysql_query("select ".$type.",time from weather order by time desc limit 0,1");
$rows = mysql_fetch_array($result);

header('Content-Type: application/json');
echo json_encode(array($rows[$type],date("Y,m,d,H,i",$rows['time'])));
?>

change-led.php

<?php
$conn = mysql_connect("localhost","root","xxxxxxxxxx");
if(!$conn)
{
    echo "Error: failed to connect DB";
    die();
}

if(!mysql_select_db("xxxxxxx",$conn))
{
    echo "Error: failed to connect DB";
    die();
}

$whichLed = strip_tags($_GET['which']);
$state = strip_tags($_GET['state']);
mysql_query("update led_status set ".$whichLed." = ".intval($state));
?>

Arduino – Communicate With Server – Part 2 – Server Code for Saving Data

This article shows the server side code for a server which is gathering or sending data by polling method to an Arduino device.

This method or code is putting less load on the server (compared to socket) but data transmission is slower than socket.

<?php
date_default_timezone_set("Asia/Kolkata");
$conn = mysql_connect("localhost","root","**********");
if(!$conn)
{
    echo "Error: failed to connect DB Server";
    die();
}

if(!mysql_select_db("database_name",$conn))
{
    echo "Error: failed to connect DB";
    die();
}
$action = intval(strip_tags($_GET['action']));

if($action == 1)
{
    $temp = floatval(strip_tags($_GET['temp']));
    $paH = floatval(strip_tags($_GET['paH']));
    $paM = floatval(strip_tags($_GET['paM']));
    
    mysql_query("insert into weather (temperature, paH, paM, time) values(".$temp.",".$paH.",".$paM.",".time().")");
    //mysql_query("update led_status set led_1 = ".$led_1.", led_2 = ".$led_2);
    
    echo "success";
}
else
    if($action == 2)
    {
        $output = "";
        $result = mysql_query("select * from led_status");
        $rows = mysql_fetch_array($result);
        if($rows['led_1'] == 1)
        {
           $output = "led_1=1|";    
        }
        else
        {
           $output = "led_1=0|";    
        }
        
        if($rows['led_2'] == 1)
        {
           $output .= "led_2=1";    
        }
        else
        {
           $output .= "led_2=0";    
        }
        echo $output;
    }
    mysql_close($conn);
?>

 

The else part ( if($action == 2) ) output from the above will be

HTTP/1.1 200 OK
Date: Sun, 14 Feb 2016 20:33:16 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Content-Length: 15
Connection: close
Content-Type: text/html

led_1=0|led_2=1

Arduino – Communicate With Server – Part 1 – Arduino code

The below code send some data (temperature and pressure here) to a server and reads back some data from server. The send part works every 5 minutes and the read part works every 5 seconds. This code works by polling method.

All delays might have room for optimization

#include <SFE_BMP180.h> //from sparkfun 
#include <Wire.h>
#include <SoftwareSerial.h>

#define _SS_MAX_RX_BUFF 512 // RX buffer size //Default is 64

SoftwareSerial esp8266(2,3);

String inputBuffer = "";
boolean stringComplete = false;
int inputBufferIndex;

int led1Pin = 9;
int led2Pin = 10;

byte led1Status, led2Status;

String data1 = ""; 
String data2 = "";
String data3 = "";
String data4 = "";
String data5 = "";

unsigned long startTimeDataCapture = 0;
unsigned long lastDataSent = 0;

SFE_BMP180 pressure;

char status;
double T,P,temp,paH,paM;


void setup() {
  // put your setup code here, to run once:
  
  inputBuffer.reserve(1024); //to be optimized
  
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  
  pressure.begin();
  
  
  //Serial.begin(19200);

  esp8266.begin(9600);
  esp8266.println("AT");  delay(100);
  esp8266.println("AT+UART_CUR=4800,8,1,0,0"); //set the Baud rate 
  esp8266.flush(); delay(100);
  while(esp8266.available())
  {
      //Serial.write(esp8266.read());
      esp8266.read();  //clear the buffer
      delay(80);
  }
  esp8266.end();

  esp8266.begin(4800);
  esp8266.println("AT"); delay(100);
  
  esp8266.println("AT+CIPMUX=1"); delay(100);
  esp8266.println("AT+CWMODE=1"); delay(100); 
  esp8266.println("AT+CWJAP="TP-LINK_POCKET_3020_304764","password""); esp8266.flush();  delay(1000);  
  
  while(esp8266.available())
  {
      //Serial.write(esp8266.read());
      esp8266.read(); //clear the buffer
      delay(80);
  }
    
  delay(5000);
}


void loop() {

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

  inputBuffer = "";
  stringComplete = false;
  
  /***** Read the LED status for sending to server  -- will be implemented later */
  if(digitalRead(led1Pin) == HIGH)
  {
    led1Status = 1;
  }
  else
  {
    led1Status = 0;
  }

  if(digitalRead(led2Pin) == HIGH)
  {
    led2Status = 1;
  }
  else
  {
    led2Status = 0;
  }
  
  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      temp = T;

      
      // Start a pressure measurement
      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);


        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          paM = P;
          paH = P*0.0295333727;
        }
        else
        {
          paM = -1;
          paH = -1;
        }
      }
      else
      {
          paM = -1;
          paH = -1;
      }
    }
    else
    {
      temp = -1;
    }
  }
  else
  {
    temp = -1;
  }

   
   //send the data to server
  
  if(millis() - lastDataSent > 300000) //send data every 5 minutes 
  {
      lastDataSent = millis();
      data1 = "GET /webservice.php?action=1&temp="+String(temp)+"&paM="+String(paM)+"&paH="+String(paH)+" HTTP/1.1";
  }
  else
  {
      data1 = "GET /webservice.php?action=2 HTTP/1.1";
  }
  //Serial.println(data1);
  data2 = "Host: xxx.xxx.xxx.xxx";
  data3 = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
  data4 = "Accept: text/html";
  data5 = "Connection: close";
  //Serial.println(data1.length()+data2.length()+data3.length()+data4.length()+data5.length());
  
  esp8266.println("AT+CIPSTART=4,"TCP","xxx.xxx.xxx.xxx",80");  delay(1000); 
   while(esp8266.available())
  {
      //Serial.write(esp8266.read());
      esp8266.read();
      delay(10);
  }
  esp8266.println("AT+CIPSEND=4,"+String(data1.length()+data2.length()+data3.length()+data4.length()+data5.length()+12)); // the 12 here is related to the data being sent below. Each dataline is sent using println (required to sent) which adds a \r\n after every line. \r and \n makes 2 chars. So for every data sent using println 2 count is increased in the total data length paramter of AT+CIPSEND
  delay(1000);
  while(esp8266.available())
  {
      //Serial.write(esp8266.read());
      esp8266.read();
      delay(10);
  }
  
  
  esp8266.println(data1); delay(1);
  esp8266.println(data2); delay(1);
  esp8266.println(data3); delay(1);
  esp8266.println(data4); delay(1);
  esp8266.println(data5); delay(1);
  esp8266.println();  delay(1); esp8266.flush();

  startTimeDataCapture = millis();
  while(1)
  {
    if(esp8266.available())
      inputBuffer += (char)esp8266.read();
      
    if(inputBuffer.indexOf("CLOSED")> 0 || millis() - startTimeDataCapture > 10000) //The server sends a close after a successful transmission. In case that didn't come (net failure, server failure whatever) then don't wait more than 20 seconds
    {
      stringComplete = true;
      //Serial.println(inputBuffer);
      //delay(1);
      break;
    }
  }

  //check if data came from server
  if(stringComplete)
  {
    inputBufferIndex = inputBuffer.indexOf("led_1=");
    if(inputBufferIndex > -1)
      led1Status = (int)(inputBuffer[inputBufferIndex+6]-'0');  // int conversion required else it was being considered as string by the codes
          
    inputBufferIndex = inputBuffer.indexOf("led_2=");
    if(inputBufferIndex > -1)
      led2Status = (int)(inputBuffer[inputBufferIndex+6]-'0');

    if(led1Status == 1)
    {
      led1Status = 1;
    }
    else
       if(led1Status == 0)
        {
          led1Status = 0;
        }
    
    if(led2Status == 1)
    {
      led2Status = 1;
    }
    else
       if(led2Status == 0)
        {
          led2Status = 0;
        }
  
    digitalWrite(led1Pin,led1Status);
    digitalWrite(led2Pin,led2Status);

    stringComplete = false;
    inputBuffer = "";
  }  
  else
  {
    esp8266.println("AT+CIPCLOSE=4"); // if for any reason  the server didn't reply properly, then close the connection
  }
  delay(5000); // wait 5 secs before making next server call
}

In future revision will implement exception handling (e.g – if the wi-fi is not found then go to sleep and try after certain intervals till connection is established, and only after connection is established move to the next step)

BMP-180 Digital Barometric Pressure Sensor

BMP-180 is a compact and cheap Digital Barometric Pressure Sensor. Below is an image of the breakout board commonly available on ebay

BMP 180 Digital Barometric Pressure Sensor

There is some confusing information about the required voltage, so safest would be to go with 3.3v. As per datasheet (download here) from Bosch, the chip manufacturer, the max voltage is 3.6v

It has a temperature sensor also inbuilt.

The library from Sparkfun is very good. It can be found here on Github (another is under development). It also has a very good example sketch.  The library has been uploaded here to ensure availability.

Below is a code snippet for reading the temperature and pressure

#include <SFE_BMP180.h>
.............
.............
SFE_BMP180 pressure;
double T,P,temp,paH,paM;
...........
...........
pressure.begin();
...........
...........

// You must first get a temperature measurement to perform a pressure reading.
// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = pressure.startTemperature();
if (status != 0)
{
  // Wait for the measurement to complete:
  delay(status);

  // Retrieve the completed temperature measurement:
  // Note that the measurement is stored in the variable T.
  // Function returns 1 if successful, 0 if failure.

  status = pressure.getTemperature(T);
  if (status != 0)
  {
    // Print out the measurement:
    temp = T;

    // Start a pressure measurement:
    // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
    // If request is successful, the number of ms to wait is returned.
    // If request is unsuccessful, 0 is returned.

    status = pressure.startPressure(3);
    if (status != 0)
    {
      // Wait for the measurement to complete:
      delay(status);

      // Retrieve the completed pressure measurement:
      // Note that the measurement is stored in the variable P.
      // Note also that the function requires the previous temperature measurement (T).
      // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
      // Function returns 1 if successful, 0 if failure.

      status = pressure.getPressure(P,T);
      if (status != 0)
      {
        // Print out the measurement:
        paM = P;
        paH = P*0.0295333727;
      }
      else
      {
        paM = -1;
        paH = -1;
      }
    }
    else
    {
        paM = -1;
        paH = -1;
    }
  }
  else
  {
    temp = -1;
  }
}
else
{
  temp = -1;
}
...........
...........

ESP8266 ESP-01 – Part 2 – Useful AT Commands And Their Outputs

Below are some AT commands for ESP8266 and their outputs

AT
OK
AT+GMR
This will display firmware version and some other details 
AT+CIPMUX=1 
OK
AT+CWMODE=3 
OK
AT+CWJAP="WIRELESS-ROUTER","password"
[WIFI DISCONNECTED] (if it is already connected)
WIFI CONNECTED
WIFI GOT IP
OK
AT+CIPSTART=4,"TCP","x.x.x.x",80
4,CONNECT
OK
AT+CIPSEND=4,205
OK
> [at this point HTTP request will be made, read below for details]
Recv 205 bytes
SEND OK
+IPD,4,203:HTTP/1.1 200 OK
Date: Sun, 14 Feb 2016 20:33:16 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Content-Length: 15
Connection: close
Content-Type: text/html

led_1=0|led_2=14,CLOSED

[The blue colored text above is what the server has sent in reply to the HTTP request]
AT+UART_CUR=2400,8,1,0,0
OK

[This command work with AT ver 6.0 and SDK ver 1.5.2. The changes will be temporary and will be restored to default on resetting. Use ]
AT+UART_DEF=2400,8,1,0,0

[This will make the change permanent. In case things gets wrong then reflash]

If AT+UART doesn't work then use 
AT+IPR

 

An extensive guide can be found here
https://github.com/espressif/ESP8266_AT/wiki/CWSAP

https://docs.espressif.com/projects/esp-at/en/latest/AT_Command_Set/Basic_AT_Commands.html

 

ESP8266 ESP-01 – Part 1 – Flashing and AT commands

This article is about the one that looks like this (aka ESP-01).

esp8266-esp-01-wifi-module-for-iot

 

Flasher version is 2.3
Firmware version is 1.5

Firmware update might be necessary just after purchase. Without firmware update mine was not able to connect to Wi-fi routers (though they were able to find them)

The current firmware available for this is “ESP8266_AT_v0.51”. The direct link to the download http://bbs.espressif.com/viewtopic.php?f=46&t=1451 . The download is at the bottom of the page as an Attachment.

firware files and readme

The flasher (for flashing firmware) can be found here http://bbs.espressif.com/viewtopic.php?f=57&t=433. The .rar version contains the necessary files to update the firmware.

WARNING: read the readme file that came with the firmware.

esp8266-flasher

Please note New chips need DOUT specifically, whereas old ones work with both QIO and DOUT

 Latest Flasher and Firmware Downloads (6th Feb, 2016):

 

Pin configuration of the module

esp8266 - pin

IMPORTANT NOTES:

  • This board runs on 3.3v
  • The default Baud rate is 115200
  • Boot errors are output over 74800. This is default and fixed.
  • For the RX TX line voltage divider using resistors doesn’t work. Using a 150 ohms in series for now, waiting for my Logic Level converter. But then so far (many years now) direct connection didn’t damage the ESP-01.

 

Flashing

  1. Used an Arduino Uno to flash the firmware.
  2. Upload a blank sketch to the Arduino.
  3. The module’s RX will go to Arduino RX and similarly TX will go TX.
  4. GPIO_0 will go to GND
  5. VCC and CH_PD will go to the 3.3v supply line
  6. Load the flasher
  7. Mine one came with “Ai-Cloud insid8” written. This module has a Flash size of 8Mbit: 512KB+512KB. QuadIO and 26MHZ crystal.
  8. Select the appropriate files in the “Download Path Config” section in the flasher tool. Some of the addresses might also need to be adjusted. READ the readme file that came with the firmware.
  9. Select the COM port on which Arduino is connected and the set the Baud rate to 115200 (the default of this board)
  10. Press start. If all goes well it will show finish to the left of the “Start” and “Stop” button
  11. If it fails – press “Stop”. Reset the board by Grounding RESET pin. And press Start again
  12. If the flashing is going on properly then the TX light of Arduino and the Blue light of the module will flash.
  13. Once firmware has been flashed disconnect the GPIO_0 pin from GND. Reset the module and start working

Useful links:
http://www.electrodragon.com/w/Category:ESP8266_Firmware_and_SDK

 

AT Commands

  1. Used Arduino Serial monitor for sending AT commands to the Module.
  2. The RX and TX pin configuration will remain same as above.
  3. Start with the AT command.
  4. List of some useful AT commands : http://www.pridopia.co.uk/pi-doc/ESP8266ATCommandsSet.pdf

 

Notes

  • After flashing the default baud rate becomes 115200. And also the CWMODE might need to be changed to 1 or 3 manually (mine somehow went to mode 2 that is AP mode)
  • If the RTOS firmware is flashed then the “user1.1024.new.2.bin” file inside the AT directory cannot be flashed – it makes the chip non-responsive.
  • The required files for RTOS firmware comes in the zip file named “AT_V0.60_on_ESP8266_NONOS_SDK_V1.5.2_20160203” and is inside “noboot” folder.

 

Updated version of this here: https://www.kolkataonweb.com/code-bank/arduino/esp-01-burning-at-rom-new-and-updated/