- ajouté pleins de choses, mais en particulier les tests du mini affichage OLED pour le NodeMCU mini D1 de WeMos
This commit is contained in:
Binary file not shown.
Binary file not shown.
9
init_oled_minid1.lua
Normal file
9
init_oled_minid1.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- mini bootstrap pour le OLED NodeMCU mini D1
|
||||
print("\ninit_oled_minid1.lua zf20180724.2251 \n")
|
||||
|
||||
tmr.alarm(0, 10000, tmr.ALARM_SINGLE, function()
|
||||
dofile("oled_first_minid1.lua")
|
||||
dofile("web_oled_minid1.lua")
|
||||
dofile("telnet_srv.lua")
|
||||
dofile("wifi_ap_start.lua")
|
||||
end)
|
||||
146
oled_demo_minid1.lua
Executable file
146
oled_demo_minid1.lua
Executable file
@@ -0,0 +1,146 @@
|
||||
-- Affiche simplement un Hello Wolrd sur le mini display OLED
|
||||
-- Source: https://wiki.wemos.cc/products:d1_mini_shields:oled_shield
|
||||
-- font_10x20,font_6x10,font_7x13,font_8x13,font_9x15,font_chikita
|
||||
print("\noled_demo_minid1.lua zf20180722.1422 \n")
|
||||
|
||||
-- setup I2c and connect display
|
||||
function init_i2c_display()
|
||||
-- SDA and SCL can be assigned freely to available GPIOs
|
||||
local scl = 1 -- GPIO12
|
||||
local sda = 2 -- GPIO14
|
||||
local sla = 0x3c -- 0x3c or 0x3d
|
||||
i2c.setup(0, sda, scl, i2c.SLOW)
|
||||
disp = u8g.ssd1306_64x48_i2c(sla)
|
||||
end
|
||||
|
||||
|
||||
-- graphic test components
|
||||
function prepare()
|
||||
disp:setFont(u8g.font_6x10)
|
||||
disp:setFontRefHeightExtendedText()
|
||||
disp:setDefaultForegroundColor()
|
||||
disp:setFontPosTop()
|
||||
end
|
||||
|
||||
function box_frame(a)
|
||||
disp:drawStr(0, 0, "drawBox")
|
||||
disp:drawBox(5, 10, 20, 10)
|
||||
disp:drawBox(10+a, 15, 30, 7)
|
||||
disp:drawStr(0, 30, "drawFrame")
|
||||
disp:drawFrame(5, 10+30, 20, 10)
|
||||
disp:drawFrame(10+a, 15+30, 30, 7)
|
||||
end
|
||||
|
||||
function disc_circle(a)
|
||||
disp:drawStr(0, 0, "drawDisc")
|
||||
disp:drawDisc(10, 18, 9)
|
||||
disp:drawDisc(24+a, 16, 7)
|
||||
disp:drawStr(0, 30, "drawCircle")
|
||||
disp:drawCircle(10, 18+30, 9)
|
||||
disp:drawCircle(24+a, 16+30, 7)
|
||||
end
|
||||
|
||||
function r_frame(a)
|
||||
disp:drawStr(0, 0, "drawRFrame/Box")
|
||||
disp:drawRFrame(5, 10, 40, 30, a+1)
|
||||
disp:drawRBox(50, 10, 25, 40, a+1)
|
||||
end
|
||||
|
||||
function stringtest(a)
|
||||
disp:drawStr(30+a, 31, " 0")
|
||||
disp:drawStr90(30, 31+a, " 90")
|
||||
disp:drawStr180(30-a, 31, " 180")
|
||||
disp:drawStr270(30, 31-a, " 270")
|
||||
end
|
||||
|
||||
function line(a)
|
||||
disp:drawStr(0, 0, "drawLine")
|
||||
disp:drawLine(7+a, 10, 40, 55)
|
||||
disp:drawLine(7+a*2, 10, 60, 55)
|
||||
disp:drawLine(7+a*3, 10, 80, 55)
|
||||
disp:drawLine(7+a*4, 10, 100, 55)
|
||||
end
|
||||
|
||||
function triangle(a)
|
||||
local offset = a
|
||||
disp:drawStr(0, 0, "drawTriangle")
|
||||
disp:drawTriangle(14,7, 45,30, 10,40)
|
||||
disp:drawTriangle(14+offset,7-offset, 45+offset,30-offset, 57+offset,10-offset)
|
||||
disp:drawTriangle(57+offset*2,10, 45+offset*2,30, 86+offset*2,53)
|
||||
disp:drawTriangle(10+offset,40+offset, 45+offset,30+offset, 86+offset,53+offset)
|
||||
end
|
||||
|
||||
function ascii_1()
|
||||
local x, y, s
|
||||
disp:drawStr(0, 0, "ASCII page 1")
|
||||
for y = 0, 5, 1 do
|
||||
for x = 0, 15, 1 do
|
||||
s = y*16 + x + 32
|
||||
disp:drawStr(x*7, y*10+10, string.char(s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function extra_page(a)
|
||||
disp:drawStr(0, 12, "setScale2x2")
|
||||
disp:setScale2x2()
|
||||
disp:drawStr(0, 6+a, "setScale2x2")
|
||||
disp:undoScale()
|
||||
end
|
||||
|
||||
|
||||
-- the draw() routine
|
||||
function draw(draw_state)
|
||||
local component = bit.rshift(draw_state, 3)
|
||||
|
||||
prepare()
|
||||
|
||||
if (component == 0) then
|
||||
box_frame(bit.band(draw_state, 7))
|
||||
elseif (component == 1) then
|
||||
disc_circle(bit.band(draw_state, 7))
|
||||
elseif (component == 2) then
|
||||
r_frame(bit.band(draw_state, 7))
|
||||
elseif (component == 3) then
|
||||
stringtest(bit.band(draw_state, 7))
|
||||
elseif (component == 4) then
|
||||
line(bit.band(draw_state, 7))
|
||||
elseif (component == 5) then
|
||||
triangle(bit.band(draw_state, 7))
|
||||
elseif (component == 6) then
|
||||
ascii_1()
|
||||
elseif (component == 7) then
|
||||
extra_page(bit.band(draw_state, 7))
|
||||
end
|
||||
end
|
||||
|
||||
function graphics_test()
|
||||
|
||||
disp:firstPage()
|
||||
repeat
|
||||
draw(draw_state)
|
||||
until disp:nextPage() == false
|
||||
|
||||
if (draw_state <= 7 + 8*8) then
|
||||
draw_state = draw_state + 1
|
||||
else
|
||||
print("--- Restarting Graphics Test ---")
|
||||
draw_state = 0
|
||||
end
|
||||
|
||||
print("Heap: " .. node.heap())
|
||||
-- retrigger timer to give room for system housekeeping
|
||||
tmr.start(0)
|
||||
end
|
||||
|
||||
draw_state = 0
|
||||
|
||||
init_i2c_display()
|
||||
--init_spi_display()
|
||||
|
||||
-- set up timer 0 with short interval, will be retriggered in graphics_test()
|
||||
tmr.register(0, 100, tmr.ALARM_SEMI, function() graphics_test() end)
|
||||
|
||||
print("--- Starting Graphics Test ---")
|
||||
tmr.start(0)
|
||||
|
||||
55
oled_first_minid1.lua
Executable file
55
oled_first_minid1.lua
Executable file
@@ -0,0 +1,55 @@
|
||||
-- Affiche simplement quelque chose sur le mini display OLED du nodeMCU mini D1
|
||||
-- Source: https://wiki.wemos.cc/products:d1_mini_shields:oled_shield
|
||||
-- font_10x20,font_6x10,font_7x13,font_8x13,font_9x15,font_chikita
|
||||
print("\noled_first_minid1.lua zf20180724.2232 \n")
|
||||
|
||||
pin_scl = 1
|
||||
pin_sda = 2
|
||||
disp_sla = 0x3c
|
||||
|
||||
function init_OLED(sda, scl) --Set up the u8glib lib
|
||||
i2c.setup(0, sda, scl, i2c.SLOW)
|
||||
disp = u8g.ssd1306_64x48_i2c(disp_sla)
|
||||
disp:setFontRefHeightExtendedText()
|
||||
disp:setDefaultForegroundColor()
|
||||
|
||||
end
|
||||
|
||||
function draw()
|
||||
-- https://github.com/olikraus/u8glib/wiki/fontsize
|
||||
-- font_10x20,font_6x10,font_7x13,font_8x13,font_9x15,font_chikita
|
||||
disp:setFont(u8g.font_10x20)
|
||||
disp:setFontPosTop()
|
||||
disp:drawStr(0,15,disp_text)
|
||||
--[[
|
||||
disp:setFont(u8g.font_6x10)
|
||||
disp:setFontPosTop()
|
||||
disp:drawStr(0,0,"Hauteur de")
|
||||
disp:drawStr(0,10,"la cuve:")
|
||||
disp:drawStr(0,20,"185cm")
|
||||
disp:drawStr(0,30,"Capacit"..string.char(233)..":")
|
||||
disp:drawStr(0,40,"3'840l")
|
||||
]]
|
||||
end
|
||||
|
||||
function disp_page()
|
||||
print("coucou."..disp_text..".")
|
||||
disp:firstPage()
|
||||
repeat
|
||||
draw()
|
||||
until disp:nextPage() == false
|
||||
end
|
||||
|
||||
|
||||
disp_text="3'247W"
|
||||
init_OLED(pin_sda, pin_scl) --Run setting up
|
||||
disp_page()
|
||||
|
||||
|
||||
--[[ source OLED:
|
||||
https://www.google.ch/search?q=nodemcu+lua+oled+display&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjG8ba8ra3cAhVDCpoKHedlDS4Q_AUICigB&biw=1536&bih=828
|
||||
https://www.hackster.io/kayakpete/esp8266-oled-display-52ae50
|
||||
http://blog.rl.cx/2017/01/08/bien-d%C3%A9buter-avec-nodemcu/
|
||||
https://github.com/FredThx/nodemcu_iot/blob/master/i2c_display.lua
|
||||
https://www.instructables.com/id/NODEMCU-LUA-ESP8266-With-I2C-LCD-128-X-64-OLED-Dis/
|
||||
]]
|
||||
@@ -1,5 +1,5 @@
|
||||
-- a simple telnet server
|
||||
print("\nzf180719.1043 \n")
|
||||
print("\ntelnet_srv.lua zf180724.2241 \n")
|
||||
|
||||
-- restart server if needed
|
||||
if telnet_srv ~= nil then
|
||||
@@ -41,5 +41,5 @@ telnet_srv:listen(23, function(socket)
|
||||
end)
|
||||
|
||||
print("Telnet server running...\nUsage: telnet -r ip\n")
|
||||
dofile("get_ip.lua")
|
||||
--dofile("get_ip.lua")
|
||||
|
||||
|
||||
81
web_oled_minid1.lua
Executable file
81
web_oled_minid1.lua
Executable file
@@ -0,0 +1,81 @@
|
||||
--Petit serveur WEB pour allumer/éteindre une LED en mode client WIFI
|
||||
print("\nweb_oled_minid1.lua zf20180724.2230\n")
|
||||
|
||||
--[[
|
||||
hvtime=tmr.create()
|
||||
wifi.sta.connect()
|
||||
tmr.alarm(hvtime, 1000, tmr.ALARM_AUTO , function()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
else
|
||||
print("Connected! IP: ",wifi.sta.getip())
|
||||
tmr.stop(hvtime)
|
||||
end
|
||||
end)
|
||||
]]
|
||||
|
||||
|
||||
srv = net.createServer(net.TCP)
|
||||
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
local buf = ""
|
||||
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
if (method == nil) then
|
||||
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
||||
end
|
||||
local _GET = {}
|
||||
print("\nNouvelle entrée !")
|
||||
if (vars ~= nil) then
|
||||
print("Input: "..vars)
|
||||
for k, v in string.gmatch(vars, "(%w+)=([%w+-@%%]+)&*") do
|
||||
_GET[k] = v
|
||||
print(k..": "..v)
|
||||
end
|
||||
end
|
||||
|
||||
buf = buf .. "<!DOCTYPE html><html><body><h1>web_oled</h1></br><form name=\"hform\">"
|
||||
|
||||
if _GET.hinput=="Valider" then
|
||||
disp_text=string.gsub(unescape(_GET.htext),"+"," ")
|
||||
print(disp_text)
|
||||
disp_page()
|
||||
end
|
||||
|
||||
buf = buf .. "<textarea name=\"htext\">1'545W</textarea> </br> <input name=\"hinput\" type=\"submit\"></input></form></body></html>"
|
||||
client:send(buf)
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
|
||||
|
||||
--source: https://github.com/diegonehab/luasocket/blob/master/src/url.lua
|
||||
function unescape(s)
|
||||
return (string.gsub(s, "%%(%x%x)", function(hex)
|
||||
return string.char(tonumber(hex, 16))
|
||||
end))
|
||||
end
|
||||
|
||||
--[[
|
||||
--t1="hello+zuzu+%26+une+belle+%E9cole"
|
||||
t1="hello+zuzu+%26+une+belle+%E9cole%5Cnun+b%E2teau"
|
||||
|
||||
print(string.char(tostring(tonumber("3F", 16))))
|
||||
print(string.char(63))
|
||||
print(unescape("%26"))
|
||||
t3=string.gsub(unescape(t1),"+"," ")
|
||||
print(t3)
|
||||
t2="école\ntoto"
|
||||
print(t2)
|
||||
|
||||
]]
|
||||
|
||||
--print( string.gsub("hello+zuzu+%26+une+belle+%E9cole%5Cun+b%E2teau","+"," ")
|
||||
|
||||
--[[ source OLED:
|
||||
https://www.google.ch/search?q=nodemcu+lua+oled+display&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjG8ba8ra3cAhVDCpoKHedlDS4Q_AUICigB&biw=1536&bih=828
|
||||
https://www.hackster.io/kayakpete/esp8266-oled-display-52ae50
|
||||
http://blog.rl.cx/2017/01/08/bien-d%C3%A9buter-avec-nodemcu/
|
||||
https://github.com/FredThx/nodemcu_iot/blob/master/i2c_display.lua
|
||||
https://www.instructables.com/id/NODEMCU-LUA-ESP8266-With-I2C-LCD-128-X-64-OLED-Dis/
|
||||
]]
|
||||
5
wifi_ap_start.lua
Executable file
5
wifi_ap_start.lua
Executable file
@@ -0,0 +1,5 @@
|
||||
-- Démarre un WIFI AP
|
||||
print("\wifi_ap_start.lua zf20180724.2220 \n")
|
||||
|
||||
wifi.setmode(wifi.SOFTAP)
|
||||
wifi.ap.config({ ssid = "NodeMCU", pwd = "12345678" })
|
||||
Reference in New Issue
Block a user