Micro Python with ESP8266 & Oled Display

How to load a test script

After loading python on your own system

Install esptool
pip install esptool –upgrade

Install AMPY
pip install adafruit-ampy

Download ssd1306.py from https://github.com/adafruit/micropython-adafruit-ssd1306/blob/master/ssd1306.py

Plug in the board and find the Com port that is created (mine was COM4)

Download the micropython from https://micropython.org/download#esp8266
Should save as a bin file like esp8266-20171101-v1.9.3.bin

Erase the board
python esptool.py –port COM4 erase_flash

Flash the board with MicroPython
python esptool.py –port COM4 write_flash –flash_size=detect -fm dio 0 esp8266-20171101-v1.9.3.bin

Bodge the ampy package

Open /usr/local/lib/python2.7/site-packages/ampy/pyboard.py. Find line 171. Specifically go to the enter_raw_repl method:

add a time.sleep(2). So it becomes
def enter_raw_repl(self):
self.serial.write(b’\r\x03\x03′) # ctrl-C twice: interrupt any running program

# flush input (without relying on serial.flushInput())
n = self.serial.inWaiting()
while n > 0:
n = self.serial.inWaiting()

Create main.py

Using a terminal open the com port and at the >>> prompt write

f = open(“main.py”, “w”)
f.write(“print(\”main.py: Hello\”)\n”)

Write the oled Library to the board

ampy –port COM4 –baud 115200 put ssd1306.py

Create a file called oledtest.py with the following content

import machine, ssd1306
i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.text(‘MicroPython on’, 0, 0)
oled.text(‘an ESP8266 with an’, 0, 10)
oled.text(‘attached SSD1306’, 0, 20)
oled.text(‘OLED display’, 0, 30)

ampy –port COM4 –baud 115200 run oledtest.py