I think I am missing a step.
Code: Select all
>>> import ssd1306
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'ssd1306'
Is that the same for all scripts in /drivers?
Code: Select all
>>> import ssd1306
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'ssd1306'
Yes, precisely.mcauser wrote: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?
Code: Select all
def draw_bitmap(self, x, y, bitmap, w, h, col=1):
byteWidth = (w + 7) // 8
for j in range(h):
for i in range(w):
if i & 7:
byte <<= 1
else:
byte = bitmap[byteWidth * j + i // 8]
if byte & 0x80:
self.framebuf.pixel(x + i, y + j, col)
Code: Select all
import ssd1306
from machine import I2C, Pin
import math
i2c = I2C(sda=Pin(4), scl=Pin(5))
display = ssd1306.SSD1306_I2C(64, 48, i2c, 60)
display.fill(0)
display.pixel(0,0,1)
display.pixel(63,0,1)
display.pixel(0,47,1)
display.pixel(63,47,1)
display.text('SSD1306',4,2,1)
display.text('64x48',12,11,1)
display.text('Awesome!',1,36,1)
display.show()
display.invert(True)
smiley = [7,192,24,48,32,8,64,4,64,4,255,254,167,154,175,186,156,114,128,2,64,36,67,196,32,8,24,48,7,192]
display.draw_bitmap(24, 20, smiley, 15, 15, 1)
display.show()
Thanks,deshipu wrote:Personally I just write a short program in PyGame that reads that image and then iterates over all the pixels and generates whatever I need.
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))