I2C With the ESP8266-01 !? || Exploring ESP8266:Part 1

9,174

121

13

Introduction: I2C With the ESP8266-01 !? || Exploring ESP8266:Part 1

About: Electronic hobbyist : Love to explore the field of applied electronics and embedded systems with a motive to contribute and share creative ideas. Green Energy enthusiast

Hello all ! With this instructable I will be writing and documenting a series of projects mentioning and exploring the various hidden ( rather unexplored ) features of the tiny ESP8266-01 WiFi Module.

Did you know that the ESP8266-01 supports I2C communication? Yes it is true, this little module lying unattended in one corner of your electronics bench has the capability to support this amazing communication protocol. This module is mainly used to connect and provide WiFi connectivity to a project using the serial communication involving Tx and Rx pins of the module. But in reality this cheap module is in itself a very capable microcontroller that can be used as standalone projects as well.

In this instructable we will be exploring the I2C communication protocol and interfacing an OLED display to show some animations and custom data as well.

So without any further delay let's jump into some theory and finally a practical application showing the hidden talents of this little buddy!

Step 1: First: Checking the Datasheet

The main microcontroller of the ESP8266-01 module is Espressif's ESP8266EX which is pretty powerful as compared to the more popular microcontrollers on the arduino.

This little thing has the following specifications:

  1. CPU : Tensilica L106 32-bit processor
  2. 1 MB of programmable memory!
  3. A good range of communication protocols like: I2S,I2C, UART and SPI
  4. It also has a PWM feature and interestingly also an ADC!

Okay so enough of good talks.Does this acually support I2C? Yes,and a quick look through the data sheet confirms this feature as well.

In this step I have attached the snapshots of the sections of datasheet that clearly mentions the communication capability and the pins required for I2C connections.

I2C is a very powerful communication protocol and used just 2 pins to communicate:

  1. The SDA (this is the data pin)
  2. The SCL (or SCK in some cases, this is the clock pin)

Systems connected via I2C have a master slave kind of communication topology. Here we can have multiple masters and multiple slave devices as well. But how does a master device specifically communicate with a particular slave? Well here each device has a unique address of itself that can be used to access(or communicate) with that particular device. The device can be a output device, like the very popular OLED screens or it can also be an input device like the MPU6050 or a BMP180 sensor.

So coming back to the ESP8266, I have attached snapshots of the part of datasheet that mention I2C details. Here the main thing is that the SDA or the data pin is actually the GPIO2 pin which is available in the pinout of the WiFi module. What about the the SCL pin? Well, we only have the GPIO 0 pin left as an available pin so we can assign it as a SCL pin-more on this during the coding process.

I have also attached the datasheet for your reference

Step 2: Connecting Up the Modules

We now have a basic understanding of how I2C works and it's possible to implement the same in our ESP8266 module. In this step you can see a basic connection overview for the ESP8266 and the OLED display. As you can see that both module have a common power supply which ideally should be 3.3volts to 2.7volts at max as the ESP is a 3.3V compatible device and any higher voltage may potentially damage the board. But I have tested this board and does work at 5 volts logic though it gets more heated up, so let's not take any risk and stick to 3.3volts supply. here the GPIO2 is tied to SDA and the GOIP0 to SCK. The CH_PD is tied to Vcc to enable the module's functionality.

Step 3: Breadboard Setup

Now to test this setup, I have previously made a few mods and adapters so that I can easily program and fix the ESP8266 on to the breadboard. You know that ESP8266 is not a breadboard friendly module so I made a tiny little adapter that lets me plug the most important pins on to a bread board and access it conveniently.

I do have a instructable for that:

Breadboard Friendly Breakout Board for ESP8266-01: https://www.instructables.com/Breadboard-Friendly-...

You can go through this instructable to make your own little adapter in very less time.

Next up is programming: For this I have used the CH340G USB to serial converter which can communicate with the ESP via serial interface and upload codes accordingly.

I have also set this up on a bradboard,you can also buy those readymade CH340 programmer boards on which you can directly plug the ESP for programming. I personally wanted all of them to be on a breadboard so I made my choices.

In the first Image you can see the setup of the ESP along with the programmer setup.

In the next image, you can see the that I have soldered 2 wires underneath my ESP adapter to the GPIO pins which to the SDA and SCL of the OLED display. I have already loaded an animation code and it successfully displays those flawlessly.

What about the code you ask? Well, it's the next step

Step 4: The Coding..

To upload some test code is the next obvious thing to do and I thought of uploading the sample animations sketch that the Adafruit OLED library provides.

The link to the Library is: https://github.com/adafruit/Adafruit_SSD1306

The code definitely needs to be modified in order for the ESP to work and communicate with the OLED-Here in the code we also specify GPIO as the SCK pin.

Here is a brief summary of the code, which for your reference is also attached in this step.

  1. Importing the Libraries that are used for initialising and setting up the OLED display
  2. Importing the Wire Library for the I2C communication.
  3. Setting up the width and height of the OLED
  4. Initialising GPIO 0 as the SDA pin
  5. Specifying the OLED address and setting up the text size and colour of the display
  6. The remaining part of the code can be found in the Adafruit library example. I have just added hose codes from there.

With everything in place, now we have to select the proper COM port and select generic ESP8266 as our target board.You can check the code snippets in this step.

Step 5: Making Things a Little Easier..

To make working with ESP8266-01 a little easier, I decided to make a sort of development board for the same. This little board includes the following:

  1. USB to serial programmer
  2. A microUSB port for programming
  3. A voltage regulator
  4. GPIO and power pins female header
  5. A switch to toggle between programming mode and running mode
  6. LED's to indicate data communication

With this is is way more easier to upload and test programs and I have made the pinout in such a way that I can plug the OLED directly into the female headers!

I am sure this will be very helpful for you and if you wish to make this well then you guessed it right, I have a instructable for this as well :)

ESP-O-One : Making Your Own ESP Development Board :https://www.instructables.com/ESP-O-One-Making-You...

Step 6: Final Words

Phew! I feel that knowing this cool feature opens up a lot of possibilities with this powerful and minimalistic board because we know that a lot of sensors and devices use I2C communication.

You can see that I have attached the OLED with my development board running the animations sketch and I hope that this information would help you in many ways to experiment with this board.

Feel free to share your feedbacks and suggestions in the comment section below and do watch the video at the beginning of the tutorial so as to get detailed information about this project and while you are there, don't forget to give that video a like and even consider subscribing! that would be awesome.

I will be documenting the later stages of this project and other capabilities of the ESP boards as mentioned earlier. Thanks again for going through my instructable and have a good day!

2 People Made This Project!

Recommendations

  • Colors of the Rainbow Contest

    Colors of the Rainbow Contest
  • Make it Real Student Design Challenge #3

    Make it Real Student Design Challenge #3
  • Arduino Contest

    Arduino Contest

13 Comments

1
nils2u
nils2u

4 months ago

Excellent tutorial!
Yes, of course I2C has been around a while and lots of people have written about it....
I only stumbled across it recently and was also impressed what can be done with it - and wrote an Instructional mentioning it, simply because I wanted to share the fun I had - without researching first, about who, what, where....

You certainly did a much better job in covering the topic, covering it in far better detail.
Therefore, thank you very much for this great job!
I also really enjoyed the ESP-O-One, as well as your Part2 :-)

0
Utsav_25
Utsav_25

Reply 4 months ago

Hey! Thanks a lot for sharing your feedback. Even I was very fascinated when I discovered this feature and though why not document is properly!
Glad that my related instructables were also useful!

1
jteramoto
jteramoto

4 months ago

Thanks for sharing your project. BTW, how big memory requires for this project? There are several ESP8266-01 available from 512K till 16MB.

0
Utsav_25
Utsav_25

Reply 4 months ago

Hello! You can make this project in 512K of program memory as well because the codes are not very memory hungry unless your project demands such high program memory. For small projects, 512KB of space is just fine.

0
gta18
gta18

4 months ago

Thanks for sharing!

0
Utsav_25
Utsav_25

Reply 4 months ago

Welcome!

0
throbscottle
throbscottle

4 months ago

This is great - I've been thinking of trying out an ESP module, so this is very informative. Thanks!

0
Utsav_25
Utsav_25

Reply 4 months ago

Great! Thanks for sharing your feeback!

1
Utsav_25
Utsav_25

Reply 5 months ago

Thanks for bringing this to my attention. As a matter of fact I discovered the feature by myself until I stumbled upon your comment and went through that Instructable and saw that people have already documented it, probably in a much better way. There's always a possibility that 2 similar things can politely co-exist :)

0
JosepAlAziz
JosepAlAziz

Reply 5 months ago

From my side, your instructable is very clear and good written. The same idea (not two different ones, as you claim) can be explained with two different aproaches. That's all instructables is about: teaching. And this is so, as long as you don't pretend to be the original author and give him the credit he deserves. And I don't mind diy_bloke instructable, I mean whatever your source is. Or maybe are you trying to convince us that you discovered I2C on ESP8266 on your own?

0
Utsav_25
Utsav_25

Reply 5 months ago

Completely agreed. What I am trying to say is I had read the datasheet and then implemented the feature. I had not seen the instructable by diy_bloke till I came across it in your comment. Well for someone who is seeing both the instructables, it may seem I have somewhat copied the concepts, but it is not. I went ahead and documented my findings in the form of this instructable. To believe that I have discovered the feature by my own is upto the readers and I respect that :)

2
JosepAlAziz
JosepAlAziz

Reply 5 months ago

It's not wiser who works harder, but who reads more.