|
HUZZAH 8266 OLED |
HUZZAH ESP8266 OLED Output
There are many OLED Led displays available for a reasonable price these days. Ebay and Amazon are prolific sellers of these devices:
Using the HUZZAH ESP8266 to output to an OLED is straightforward as the following example hopefully demonstrates:
function init_OLED(sda,scl) --Set up the u8glib lib
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
init_OLED(6,7) --Run setting up
--Output IP Address and MAC Address of HUZZAH ESP8266 to the OLED
disp:firstPage()
repeat
disp:drawStr(0,0,"ESP8266 Info") -- Starting on line 0
disp:drawStr(0,11*2,"IP Address:") --Output IP Address to OLED
disp:drawStr(0,11*3,wifi.sta.getip())
disp:drawStr(0,11*4,"MAC Address:") --Output MAC Address of ESP8266 to OLED
disp:drawStr(0,11*5,wifi.sta.getmac())
until disp:nextPage() == false
HUZZAH OLED GPIO PIN Numbering
|
HUZZAH OLED GPIO PIN Numbering |
NOTE: I'm connecting the OLED pins SCL and SDA to the pins on the HUZZAH board numbered 12 and 13 i.e.
OLED SDA Pin -> Pin number 12 on the Huzzah Board = 6 in the Lua code
OLED SCL Pin -> Pin number 13 on the Huzzah Board = 7 in the Lua code
The Lua code above then uses IO index numbers 6 and 7:
init_OLED(6,7) --Run setting up
If you look at the table below, pin 12 on the HUZZAH board corresponds to GPIO 6 in code, pin 13 on the HUZZAH board corresponds to GPIO 7 in code.
IO
index
|
ESP8266 pin
|
IO
index
|
ESP8266 pin
|
0
[*]
|
GPIO16
|
7
|
GPIO13
|
1
|
GPIO5
|
8
|
GPIO15
|
2
|
GPIO4
|
9
|
GPIO3
|
3
|
GPIO0
|
10
|
GPIO1
|
4
|
GPIO2
|
11
|
GPIO9
|
5
|
GPIO14
|
12
|
GPIO10
|
6
|
GPIO12
|
|
Display Nearby WiFi Access Points On An OLED
So, for example, to display all of the nearby WiFi Access Points on the OLED:
wifi.setmode(wifi.STATION) --Set mode to STATION so he chip can receive the SSID broadcast
function init_OLED(sda,scl) --Set up the u8glib lib
sla = 0x3c
i2c.setup(0, sda, scl, i2c.SLOW)
disp = u8g.ssd1306_128x64_i2c(sla)
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end
init_OLED(6,7) --Run setting up
disp:firstPage()
repeat
disp:drawStr(0,0,"ESP8266 Info") -- Starting on line 0
disp:drawStr(0,11*2,"IP Address:")
disp:drawStr(0,11*3,wifi.sta.getip())
disp:drawStr(0,11*4,"MAC Address:")
disp:drawStr(0,11*5,wifi.sta.getmac()) --
until disp:nextPage() == false
tmr.delay(7000000) --7 second delay
tmr.alarm(0,3000,1,function()
wifi.sta.getap(function(t)
disp:firstPage()
repeat
disp:drawStr(0,0,"WiFi AP Search") -- Starting on line 0
lines = 2
for k,v in pairs(t) do
disp:drawStr(0,lines * 11,k.." "..v:sub(3,5).."dbi")
lines = lines + 1
end
until disp:nextPage() == false
end)
end)
No comments:
Post a Comment