ESP8226 Microcontroller

ESP8226 Microcontroller The ESP8226 is a very cheap Wi-Fi microcontroller with a complete TCP/IP stack and a 32 bit microcontroller and is made by the Chinese manufacturer Espressif Systems. The chip came to attention in 2014 by a small board (ESP-01) as a cheap Wi-Fi module that could be controlled via a serial interface and through a form of Hayes commands. Soon the chip came to the attention of hackers, mainly due to its low cost, to find other uses. For the low amount of money, the specifications are impressive: a 32-bit RISC CPU (Tensilica Xtensa LX106) with an 80 MHz clock frequency, 64 Kb instruction RAM, 96 KB data RAM, external QSPI flash (512 Kb to 4 Mb), built-in IEEE 802.11 Wi-Fi stack, WEP and WPA/WPA2 authentication, 16 GPIO pins, SPI, I2C, UART and a 10-bit ADC. There are some nice cheap DIY boards for sale with this microcontroller and this page contains information about these boards, documentation, links and specifications, and development tooling. Also a full working sourcecode of a WIFI led controller. Sincerely, Hein Pragt

Wemos D1 mini

Wemos D1 board A relatively small manufacturer by the name of Wemos brings out nice new developments with the ESP-8266 family on Arduino type shields. One of these fun boards to experiment with yourself is the Wemos D1 mini, a small board equipped with a full Wi-Fi and network stack, a nice number of I/O ports, power supply, a USB connection, serial communication, bootloader, Flash memory and a 32 bit processor with an 80 MHz clock frequency. As in all very nice specifications for a board that costs less than 10 dollar. When you are already used to the standard Arduino IDE and programming environment, you can also use this for the Wemos D1. The correct boards have to be installed in the board manager of the IDE, but then it works almost immediately. There are already many libraries specifically for the ESP-8266 family available for the Wemos D1 mini but I find that many of the standard libraries written for the Arduino also work fine on the Wemos D1 mini. Because I2C and SPI also work standard, many of the boards and shields that are made for the Arduino can also be connected, please note that everything must work on 3v3, but this can also be solved with a level adjustment board or a resistance network. But a standard LCD display or a relay board can easily be connected. Sometimes a few I/O pins have to change definitions and often it works fine. But with 4 Mb of code space and 35 Kb of ram and a 32 bit processor at 80 MHz which is a huge improvement over the 16 MHz 8 bit Arduino processor with 1 to 2 Kb sram. The possibilities of the Wemos D1 mini are therefore very extensive, partly due to the built-in Wi-Fi that you can use ready-to-use.

Link: PDF with instructions for the Wemos D1 on the Arduin IDE.

Wemos OLED display

Wemos D1 mini OLED display 64x48 The first display I used is the WeMos D1 mini OLED shield 64x48 of 0.66 inch with an I2C interface. The shield has many more pins because it can also be controlled differently but of course we like to use I2C because it only uses two I/O lines. At 0.66inch it is quite a small display but is very easy to read as it has a high contrast. It uses the SSD1306 as the interface chip and uses the I2C address 0x3C or 0x3D which can be selected by a solder bridge on the back of the PCB. Very small, so I don't dare and leave them at the default value. The device was delivered with separate header pins and since you only have 4 connections If you need it, you can also solder the wires directly to the PCB.

Code and example

Wemos D1 mini met OLED display 64x48 Download: HERE my library for the Wemos D1 OLED display and install it via the IDE in your Arduino environment. Restart the IDE and look at the examples and see it says "oledtest64.ino". The library works for the combination Wemos D1 and the Wemos OLED display. I also use this library myself and develop it further. With these basic functions you can create extensions in your own code.

I like libraries that only offer basic functions because I usually want to make things in my own way, which are just not in the library or just different which means I am compiling a large amount of code from a library that grows my code and is of no use to me. I wish good luck with this code.

The code of this libray is compact and contains only a few basic functions:


  public:
    Ssd1306(uint8_t i2caddr,uint8_t width,uint8_t height,uint8_t orientation);
    void begin(void); 
    void oledSetPixel(int16_t x, int16_t y, uint16_t color);
    void oledDrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
    void oledDrawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
    void oledFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
    void oledDrawCircle(int16_t x0, int16_t y0, int16_t r,uint16_t color);
    void oledDrawChar(int16_t x, int16_t y, unsigned char c, uint16_t color);
    void oledPrintLine(int16_t x, int16_t y, unsigned char *c, uint16_t color);
    void oledInvert(void); 
    void oledNormal(void);
    void oledCopyDisplayBuffer(void);
    void oledClearDisplayBuffer(uint8_t value);


The displays can actually show only a little text, with a font of 5x7 this is the division on the screen and a resolution of 64 x 48 pixels, this gives ten columns and 5 rows, so you can effectively lose 50 characters on the screen.

rij en kolomn verdeling oled

Sourcecode Wi-Fi led control

This piece of sample code clearly shows the tremendous power of the Wemos D1 mini. The example uses my OLED library and otherwise only use standard supplied / built-in parts. Through this piece of code you can use your mobile phone via the web browser to find an output pin of the Wemos D1 mini module (read: connected relay) on and off. In this example I control the built-in LED. Since the more complete Wi-Fi stack and network stack are in the module as far as we don't write our own code for this. First you make on your phone to a mobile hotspot and gives it a name and a password, you enter this name and password at const char* ssid and const char* password after which you can compile the code and upload it in the Wemos module. After turning on of the module, it will try to contact your mobile hotspot and then display its IP address on the screen. You then only need to enter this address in the address bar of the browser on your mobile phone and the Wemos module will now behave like an HTTP server and send you a page with the status of the led. Then you can click on a click on the links or switch the LED on the Wemos module on and off by means of a URL parameter. This is just a small example that can be food for many ideas, but I leave that to your imagination. kind regards, Hein Pragt.

// -----------------------------------------------
// Example code WI-FI led control
// -----------------------------------------------
#include 
#include 
#include 
 
const char* ssid = "HotspotVanUwTelefoon";
const char* password = "WachtwoordHotspotTelefoon";
 
int ledPin = BUILTIN_LED;
WiFiServer server(80);
 
Ssd1306 ssd1306(0x3C,64,48,0);

void setup() 
{
String ip;
char buffer[20];

  Serial.begin(9600);
  delay(10);  

  ssd1306.begin(); 
  // Clear the buffer.
  ssd1306.oledClearDisplayBuffer(0);
  ssd1306.oledCopyDisplayBuffer();

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
 
  // Connect to WiFi network
  ssd1306.oledPrintLine(0,0,"Connecting",1);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  ssd1306.oledPrintLine(0,10,(char *)ssid,1); 
  ssd1306.oledCopyDisplayBuffer();
  
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  ssd1306.oledClearDisplayBuffer(0);
  Serial.println("WiFi connected");
  ssd1306.oledPrintLine(0,0,"Connected ",1);
  ssd1306.oledCopyDisplayBuffer();
  
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL : ");
  ssd1306.oledPrintLine(0,10,"MY IP:",1);
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  ip = WiFi.localIP().toString();
  ip.toCharArray(buffer, 20);
  ssd1306.oledPrintLine(0,20,buffer,1);
  Serial.println("/");
  ssd1306.oledCopyDisplayBuffer();
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = HIGH;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, LOW);
    value = LOW;
  } 
  if (request.indexOf("/LED=OFF") != -1){
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
 
 
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("");
  client.println("");
 
  client.print("Led pin is now: ");
 
  if(value == LOW) {
    client.print("On");  
  } else {
    client.print("Off");
  }
  client.println("

"); client.println("Click here turn the LED on pin 5 ON
"); client.println("Click here turn the LED on pin 5 OFF
"); client.println(""); delay(1); Serial.println("Client disconnected"); Serial.println(""); }

ESP8226 download and links

Here are some external links to pages and documents that will be helpful and helpful when getting started with the ESP8226.

Download the Arduino IDE

The ESP8266 Datasheet (Engels)

Overview nice Wemos D1 projects.

 
Last update: 14-05-2022


Disclaimer: All pages on this Web site are copyrighted by Hein Pragt, unless otherwise noted. I strive for accuracy but cannot be held responsible for any errors in the content. For questions about the content of this site or persmission to copy you can contact me at: (email: heinpragt@outlook.com). Heinpragt.com is registered under KvK number: 73839426.