Page 5 of 6

Re: ssd1306 using I2C on the esp8266

Posted: Sun Jul 31, 2016 6:35 pm
by mflmartin
deshipu wrote: Yes, you can do it -- if you are using numbers. However, if you want to save space, at some point you will want to save this as raw
strings of bytes.
When you say, "as a raw strings of bytes", you mean like this? 010101010110
Does this save space, as opossed as using numbers? In code, i would occupy more characters, no?
deshipu wrote: At some point I would probably save this as one large string, something like this:
Interesting technique, to wich I am completely new. How do you convert it to hexadecimal, and, more importantly, how do you save it as "compiled bytecode"? I looked into and I found about pyc_compile. So you would use python 3.5, for instance, and compile some parts into bytecode? How do you then implement it into the project, by putting the pyc file somewhere?

When is this technique recommended, in your oppinion?

Re: ssd1306 using I2C on the esp8266

Posted: Mon Aug 01, 2016 11:00 am
by pythoncoder
To convert it to a hex string experiment on these lines. The first step is to turn your DATA (which is a tuple of tuples) into a simple list, then convert that into a string which can be interpreted by Python:

Code: Select all

lst = []
for t in DATA:
    for d in t:
        lst.append(d)

s = "data = '"
for x, d in enumerate(lst):
    if x > 0 and not x % 16:
        s = ''.join((s, "'\\\n'"))
    s = ''.join((s, "\\x{:02x}".format(d)))

s = ''.join((s, "'"))
print(s)
You'd save the string to a file with a .py extension and check that it can be imported into Python. To freeze the code you need to be able to create a firmware build. By far the easiest way is to grab a nightly build of the toolchain from here http://www.kaltpost.de/~wendlers/micropython/, get the latest source from Github and follow the README to compile it. To freeze your code, simply put it in the esp8266/modules directory and repeat the build.

Re: ssd1306 using I2C on the esp8266

Posted: Mon Aug 01, 2016 12:06 pm
by fdufnews
May be you can consider using the export function of Gimp. Using the pbm export filter gives you a binary file with a short header. For example, a 128x64 image generates a 1073 bytes file.
The file has 49 bytes of header and following it the image is encoded eight pixels in a byte.
You can copy the file to the flashdisk and open it when necessary and just copy the data into the buffer no need to put the image in your code.

Re: ssd1306 using I2C on the esp8266

Posted: Mon Aug 01, 2016 12:42 pm
by deshipu
fdufnews wrote:May be you can consider using the export function of Gimp. Using the pbm export filter gives you a binary file with a short header. For example, a 128x64 image generates a 1073 bytes file.
The file has 49 bytes of header and following it the image is encoded eight pixels in a byte.
You can copy the file to the flashdisk and open it when necessary and just copy the data into the buffer no need to put the image in your code.
You can also export to .h or .c files, in which case you will get arrays with the data.

Re: ssd1306 using I2C on the esp8266

Posted: Tue Aug 02, 2016 5:57 am
by pythoncoder
Creating a .py file and freezing it as bytecode has the advantage of not using RAM for the buffer.

Re: ssd1306 using I2C on the esp8266

Posted: Tue Aug 02, 2016 3:32 pm
by mcauser
This is a WiFi module. One could even http get to save RAM :)

Re: ssd1306 using I2C on the esp8266

Posted: Sat Aug 13, 2016 7:42 pm
by MicroPythoneer
[quote="mcauser"]@deshipu I'd like to test your modifications to the ssd1306 driver on my WeMos OLED shield (64x48).
I think I am missing a step.

[code]
>>> import ssd1306
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'ssd1306'
[/code]

Do I need to copy/symlink the driver from /drivers/display/ssd1306.py into /esp8266/scripts and make/flash again to make it work?
Is that the same for all scripts in /drivers?[/quote]


I've got the same issue however it seems you solved it.

How exactly did you get the ssd1306 module onto the ESP8266 so that you can use the import ssd1306 without an error? I just want to drive my OLED using MicroPython and a ESP8266

I'm new to all of this, thanks!

Re: ssd1306 using I2C on the esp8266

Posted: Sun Aug 14, 2016 11:04 pm
by torwag
you "simply" have to copy the file directly onto the esp. E. g. using webrepl. After that you can call it via import. Remember for webrepl you have to establish a network connection first and start webrepl on the esp. Sounds tricky but it is well described in the docs.

Re: ssd1306 using I2C on the esp8266

Posted: Sun Aug 21, 2016 10:34 pm
by mcauser
Yes, either
a) copy /drivers/display/ssd1306.py to /esp8266/scripts/ssd1306.py and make/flash
b) start a webrepl and upload the file
c) enter paste-mode on a REPL and paste the contents of the file

Re: ssd1306 using I2C on the esp8266

Posted: Sun Oct 09, 2016 12:59 am
by joehunt588
deshipu wrote:I didn't save the snippets that I normally use, but here's one that I recently used to generate data for a 2-bit font:

Code: Select all


import pygame

colors = {
    (0, 0, 0, 255): 0,
    (102, 102, 102, 255): 1,
    (204, 204, 204, 255): 2,
    (255, 255, 255, 255): 3,
}
image = pygame.image.load("font.png")
images = []

for tile_x in range(0, image.get_size()[0]/4):
    rect = (tile_x * 4, 0, 4, 6)
    images.append(image.subsurface(rect))
    
for image in images:
    print '(%s),' % ', '.join('%d' %
        sum(colors[tuple(image.get_at((x, y)))] << (x * 2)
            for x in range(4))
        for y in range(6))
Hai deshipu,can i have file 'font.png' for the code im still learn about pixel and need example :)