U8G

Поддерживаемые экраны
u8g Module
U8glib is a graphics library developed at olikraus/u8glib with support for many different displays. The NodeMCU firmware supports a subset of these.
I²C and SPI mode:
sh1106_128x64
ssd1306 - 128x64 and 64x48 variants
ssd1309_128x64
ssd1327_96x96_gr
uc1611 - dogm240 and dogxl240 variants
SPI only:
ld7032_60x32
pcd8544_84x48
pcf8812_96x65
ssd1322_nhd31oled - bw and gr variants
ssd1325_nhd27oled - bw and gr variants
ssd1351_128x128 - gh and hicolor variants
st7565_64128n - variants 64128n, dogm128/132, lm6059/lm6063, c12832/c12864
uc1601_c128032
uc1608 - 240x128 and 240x64 variants
uc1610_dogxl160 - bw and gr variants
uc1611 - dogm240 and dogxl240 variants
uc1701 - dogs102 and mini12864 variants
Собственно собранный на коленке датчик температуры/влажности с выводом на экранчик.
ESP8266.jpg
128x64.jpg
Ниже демо взятое за основу.
Я чутка переработал под DHT11 сенсор.
---------------------------------------------------------------------
-- File: oled_dht22_demo.lua
-- Author: RSP @ Embedded Systems Lab (ESL), KMUTNB
-- Date: 2015-04-19
-- Description:
-- This Lua script for NodeMCU demonstrates how to
-- read temperature and himidity values from DHT2x.
-- Sensor values will be displayed on the ssd1306_128x64 I2C OLED.
---------------------------------------------------------------------
local sda_pin = 5 -- the SDA pin => GPIO14
local scl_pin = 6 -- the SCL pin => GPIO12
local dht_pin = 4 -- the data pin of the DTH2x module => GPIO2
pin = 4
local oled_addr = 0x3c
i2c.setup(0, sda_pin, scl_pin, i2c.SLOW)
local disp = u8g.ssd1306_128x64_i2c(oled_addr)
local cnt = 1
local humi = nil
local temp = nil
status, temp, humi, temp_dec, humi_dec = dht.read11(pin)
if status == dht.OK then
-- Float firmware using this example
print("DHT Temperature:"..temp..";".."Humidity:"..humi)
elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." )
end
function read_sensor_values()
-- dht = require("dht2x") -- load 'dht2x.lua' or ''dht2.lc
status, temp, humi, temp_dec, humi_dec = dht.read11(pin)
if humid ~= nil then
humid = humi
else
humid = '--.-'
end
if temp ~= nil then
temp = temp/1
else
temp = '--.-'
end
dht = nil
-- package.loaded["dht2x"]=nil -- unload module 'dht2x'
end
function display_sensor_values()
disp:firstPage()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
local x,y
repeat
disp:drawRFrame(0, 0, 128-1, 64-1, 1)
x=4
y=8
disp:drawStr(x, y, 'Temp. : ' .. (temp) .. ' deg.C' )
y = y+14
disp:drawStr(x, y, 'Humid.: ' .. (humid) .. ' %RH' )
y = y+14
disp:drawStr(x, y, 'Heap : ' .. (node.heap()) .. ' bytes' )
y = y+14
disp:drawStr(x, y, 'Count : ' .. (cnt) )
until disp:nextPage() == false
cnt = cnt + 1
if cnt > 1000 then
tmr.stop(1)
end
end
local state = 0
tmr.alarm( 1, 2000, 1, function()
if state == 0 then
read_sensor_values()
end
if state == 1 then
display_sensor_values()
end
state = (state + 1) %2
collectgarbage()
end)
---------------------------------------------------------------------