PrettyPrint JavaScript

sabato 24 ottobre 2015

Setting I2C on ESP8266MOD with ESP 07/12 Breakout

The ESP8266 module allows us to create a portable, energy-saver, arduino compliant project for IoT with low cost and without an Arduino boards.

For the technical features of this module read this.

In order to simplify working on ESP8266 with a breadboard I reccomend to connect it with the ESP 07/12 Breakout Board.

So, after Setup ArduinoIDE to work on ESP8266 and load my script, I try to connect it with an i2c sensor: the HTU21D. But Wire library seems not working.

I googled a lot and finally I found the solution.

The ESP8266 seems to needs the GPIO02 as SDA and GPIO14 as SCL for the I2C protocol! So, take a look to the ESP 07/12 Breakout pinout in order to rightly connect ours I2C module on board.

Now, we can load a simple script testing I2C:
#include <Wire.h>

void setup() {
  int sda=2;// qui SDC del sensore
  int sdc=14;// qui SDA del sensore



void loop() {


int i2cscan(){
  //scanning i2c
  byte error, address;
  int nDevices;


  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    error = Wire.endTransmission();

    if (error == 0)
      Serial.print("I2C device found at address 0x");
      if (address<16) 
      Serial.println("  !");

    else if (error==4) 
      Serial.print("Unknow error at address 0x");
      if (address<16) 
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
If it's all OK you should be able to see on Serial monitor: I2C device found at address 0x.... N.B. Another information I did not easily found is how setting ESP8266 on programming mode with ESP 07/12 Breakout Board: just hold on the reset button for at least 1 second and release. After that you are able to flash the firmware!

Nessun commento:

Posta un commento