Post your best Lua script examples here

User avatar
By 1achy
#62877 I try simple programm with nodemcu dev kit but my oled is black , where i wrong?

-- setup I2c and connect display
function init_i2c_display()
-- SDA and SCL can be assigned freely to available GPIOs
sda = 5 -- GPIO14
scl = 6 -- GPIO12
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
end


-- scrive su display
function print_OLED()
disp:firstPage()
repeat
disp:drawFrame(2,2,126,62)
disp:drawStr(5, 10, str1)
disp:drawStr(5, 20, str2)
disp:drawCircle(18, 47, 14)
until disp:nextPage() == false

end

-- Main Program
str1=" Hello World!!"
str2=" hello"
init_i2c_display()
print_OLED()
User avatar
By trackerj
#62888 Might worth to take a look at this Article : SSD1306 OLED Display for ESP8266 - Driver example

OLED Display general description and full code example inside.
User avatar
By 1achy
#63005 I try example firmware with set font etc. but programm is running but display is black.... do i needd external voltage_?



-- ***************************************************************************
-- Rotation Test
--
-- This script executes the rotation features of u8glib to test their Lua
-- integration.
--
-- Note: It is prepared for SSD1306-based displays. Select your connectivity
-- type by calling either init_i2c_display() or init_spi_display() at
-- the bottom of this file.
--
-- ***************************************************************************

-- setup I2c and connect display
function init_i2c_display()
-- SDA and SCL can be assigned freely to available GPIOs
local sda = 5 -- GPIO14
local scl = 6 -- GPIO12
local sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
end




-- the draw() routine
function draw()
disp:setFont(u8g.font_6x10)
disp:drawStr( 0+0, 20+0, "Hello!")
disp:drawStr( 0+2, 20+16, "Hello!")

disp:drawBox(0, 0, 3, 3)
disp:drawBox(disp:getWidth()-6, 0, 6, 6)
disp:drawBox(disp:getWidth()-9, disp:getHeight()-9, 9, 9)
disp:drawBox(0, disp:getHeight()-12, 12, 12)
end


function rotate()
if (next_rotation < tmr.now() / 1000) then
if (dir == 0) then
disp:undoRotation()
elseif (dir == 1) then
disp:setRot90()
elseif (dir == 2) then
disp:setRot180()
elseif (dir == 3) then
disp:setRot270()
end

dir = dir + 1
dir = bit.band(dir, 3)
-- schedule next rotation step in 1000ms
next_rotation = tmr.now() / 1000 + 1000
end
end

function rotation_test()
print("--- Starting Rotation Test ---")
dir = 0
next_rotation = 0

local loopcnt
for loopcnt = 1, 100, 1 do
rotate()

disp:firstPage()
repeat
draw(draw_state)
until disp:nextPage() == false

tmr.delay(100000)
tmr.wdclr()
end

print("--- Rotation Test done ---")
end

init_i2c_display()

rotation_test()