ssd1306 using I2C on the esp8266

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
User avatar
dhylands
Posts: 3214
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ssd1306 using I2C on the esp8266

Post by dhylands » Wed Mar 30, 2016 6:09 am

If its just frozen python source - then yes it won't save any RAM.

I was thinking about frozen bytecode, and with that I'm not sure whether data would be able to come from flash or not.

With C you could definitely have the data accessible directly from flash.

Even with python, there might be some clever tricks to get access to raw data (not using the usual python methods).

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: ssd1306 using I2C on the esp8266

Post by pfalcon » Wed Mar 30, 2016 7:00 am

With C you could definitely have the data accessible directly from flash.
Just the same as with Python. And depending on what exactly you mean. Looks like you hint at accessing flash in memory-mapped way, but that's inherently device-specific. For example, ESP8266 has memory-mapped access, but only for the portion of flash. Otherwise, you need to treat flash as a storage device and access it correspondingly, and that's exactly what pythoncoder did above.

So, the "ultimate" solution to this problem would be to develop a C module which would take a char code and returned bytes-like object with font data. (Of course, the real ultimate solution is to have good graphics API (including font rendering) backed by C implementation. As a sneak peek, u8g integration as a stretch goal for ESP8266 didn't get enough votes, so we'll leave it to you guys to decide what works best in different cases.)
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

Re: ssd1306 using I2C on the esp8266

Post by deshipu » Wed Mar 30, 2016 8:18 am

pfalcon wrote:As a sneak peek, u8g integration as a stretch goal for ESP8266 didn't get enough votes, so we'll leave it to you guys to decide what works best in different cases.)
Speaking of which, will you disclose the voting results? It would be interesting to see what people are most interested in.

pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: ssd1306 using I2C on the esp8266

Post by pfalcon » Wed Mar 30, 2016 8:48 am

Of course, please expect a KS update soon. P.S. let's keep individual topics on topic ;-).
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

User avatar
pythoncoder
Posts: 3543
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: ssd1306 using I2C on the esp8266

Post by pythoncoder » Wed Mar 30, 2016 4:22 pm

dhylands wrote:...I was thinking about frozen bytecode, and with that I'm not sure whether data would be able to come from flash or not...
In my testing it works. I have a utility which converts multiple C font files into a single Python sourcefile. This declares a (large) bytes instance for each font and instantiates a PyFont object from each bytes object. Compiled as frozen bytecode I can import the module and access the PyFonts with minimal RAM usage.

Frozen bytecode is a great way to access large data structures at RAM-like speed.
dhylands wrote:Even with python, there might be some clever tricks to get access to raw data (not using the usual python methods).
Sounds interesting!
Peter Hinch

User avatar
dhylands
Posts: 3214
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: ssd1306 using I2C on the esp8266

Post by dhylands » Wed Mar 30, 2016 5:16 pm

pythoncoder wrote:
dhylands wrote:Even with python, there might be some clever tricks to get access to raw data (not using the usual python methods).
Sounds interesting!
I was thinking that the code that Damien gave me to extract the bytecode (See post http://forum.micropython.org/viewtopic. ... 7913#p7901) might be modified to get access to variables stored in flash or something. I haven't really thought this through, and given that you've got things working with frozen bytecode, then that seems like the way to go.

User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

Re: ssd1306 using I2C on the esp8266

Post by deshipu » Thu Mar 31, 2016 1:38 pm

Perhaps it would make sense to put some standard font somewhere inside the micropython, so that it could then be used by various user libraries?

User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

Re: ssd1306 using I2C on the esp8266

Post by deshipu » Wed Apr 13, 2016 8:42 pm

I just tested a small I²C SSD1306 display with the driver that is now included in drivers/display, and it works flawlessly:
IMG_20160413_223240.jpg
IMG_20160413_223240.jpg (226.09 KiB) Viewed 4231 times
This is the result of the following code:

Code: Select all

import ssd1306
from machine import I2C, Pin
import math

i2c = I2C(sda=Pin(4), scl=Pin(5))
display = ssd1306.SSD1306_I2C(32, i2c, 60)
display.fill(0)
for x in range(0, 96):
    display.pixel(x, 16+int(math.sin(x/32*math.pi)*7 + 8), 1)
display.show()

User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

Re: ssd1306 using I2C on the esp8266

Post by deshipu » Mon May 16, 2016 8:44 pm

By the way, has anybody managed to get the SSD1306 driver to work with the SPI displays? I took a stab at rewriting it to use the new hardware API, but I haven't been able to get it to display anything.

User avatar
deshipu
Posts: 1347
Joined: Thu May 28, 2015 5:54 pm

Re: ssd1306 using I2C on the esp8266

Post by deshipu » Sun May 22, 2016 9:45 pm

Replying to myself, because I managed to get it to work. The trick is to initialize the MOSI and SCK pins to OUT when passing them to the SPI constructor, otherwise they will stay high-impedance forever. Example:

Code: Select all

>>> from machine import Pin, SPI
>>> spi = SPI(miso=Pin(12), mosi=Pin(13, Pin.OUT), sck=Pin(14, Pin.OUT))

Post Reply