ESP8266 and OLED Micropython example

In this example we show an example written in Micropython using the uPycraft IDE. This time we will be trying out the Wemos OLED shield connected to a Wemos Mini.

Requirements

Lets take a look a the shields and boards that are required for this project

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
A  64×48 OLED screen
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side – optional

Parts List

I connect the Wemos Mini to the dual base and then put the OLED shield along side this. You can connect the OLED shield directly to the Wemos Mini if you want.

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
Wemos OLED shield OLED Shield for WAVGAT D1 mini 0.66″ inch 64X48 IIC I2C
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Code

This is a basic example

[codesyntax lang=”python”]

from machine import Pin,I2C
import ssd1306

i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)  #Init i2c

lcd=ssd1306.SSD1306_I2C(64,48,i2c)             #create LCD object,Specify col and row
lcd.text("ESP8266",0,0)                        
lcd.text("test",0,16)                       
lcd.text("123456",0,32)                        
lcd.show()                                      #display

[/codesyntax]

and another example

[codesyntax lang=”python”]

import time
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C


width = 64
height = 48

i2c = I2C(scl=Pin(5), sda=Pin(4))
oled = SSD1306_I2C(width, height, i2c)

oled.fill(1)
oled.show()

time.sleep(2)

oled.fill(0)
oled.show()

time.sleep(2)

oled.pixel(0, 0, 1)
oled.show()

time.sleep(2)

oled.pixel(63, 47, 1)
oled.show()

time.sleep(2)

oled.text('Hello', 0, 0)
oled.text('World', 0, 10)
oled.show()

time.sleep(2)

oled.invert(True)

time.sleep(2)

oled.invert(False)

[/codesyntax]