Saturday, October 22, 2016

ESP8266 SoftwareSerial Library & Level Shifter for ESP8266 - Arduino

Hello everyone,

I have found a very usefull software library for esp8266. Library works well with Arduino IDE.
In this tutorial, I will show you how you can send data between arduino running at 5V and ESP8266 running at 3.3V.

I use :
- Arduino UNO ( You can use another boards .)
- ESP8266 - 07 (You can use another version.)
- 4 x 10k resistor.
- 2 x BS138 Mosfet or ( I will explain which types of mosfets you can use.)
- Some Wires ,breadboards etc.
- Software Serial Library for ESP8266 - Download

Library on Gitbub - Go Github

Using Softwareserial library:
Import the library and open any example wich you want to use.

3.3V - 5V Level Shifter
The Circuit that we use shows in Fig1 and Fig2.

Fig1





I use BSS138 mosfet for my circuit. You can see details on arduino offical web site. (Go Orginal Site)




Fig2

Connection ESP8266 and Arduino :

3.3V SDA -> ESP8266 GPIO-12 as TX
3.3V SCL -> ESP8266 GPIO-14 as RX

5V SDA -> Arduino RX
5V SCL -> Arduino TX

Here is the code that i use : 

#include <SoftwareSerial.h>
//RX Pin 14
//TX Pin 12
#BufferSize 256;
#BAUDRATE 9600
SoftwareSerial mSerial(14, 12, false, BufferSize);

void setup() {
  Serial.begin(9600);
  mSerial.begin(BAUDRATE);
}

void loop() {
  while (mSerial.available() > 0) {
    Serial.write(mSerial.read());
  }
  while (Serial.available() > 0) {
    mSerial.write(Serial.read());
  }
}


If your code is slow and your loop time is too longer, You can increase buffer size and you can keep data for longer.

Why we use BSS138 ? What types of mosfets i can use ?

I test that circuit and software serial library @9600 baudrate. It works very well with very very low bit erros.  You can use different mosfet if you cant find bss138. BSS138 is N-Channel Logic Level Enhancement Mode Field Effect Transistor. You need to be carefull that the mosfet you use should be fast enough.





No comments:

Post a Comment

ESP8266 SoftwareSerial Library & Level Shifter for ESP8266 - Arduino

Hello everyone, I have found a very usefull software library for esp8266. Library works well with Arduino IDE. In this tutorial, I will s...