ESP-01 ADC Extra Pin Connect With NodeMCU Server OLED Display
by murphypoon in Circuits > Sensors
11695 Views, 16 Favorites, 0 Comments
ESP-01 ADC Extra Pin Connect With NodeMCU Server OLED Display
ESP-01 ADC Extra Pin connect with NodeMCU Server OLED Display
Extra Pin on ESP-01
- GPIO 0 and 2 are already exist.
- GPIO 4, 5 and ADC are extra and will show you home to make it here
ESP-01 Parts :
- (1) ESP8266 - ESP01
- (2) Button
- (1) 3.3v converter
- (1) Light Sensor with 1KOhm
NodeMCU Parts:
- (1) 0.9 OLED
- (2) LED
- (2) 220Ohm
Tester :
- (6) LED
- (6) 220 Ohm
Home Make soldering iron head show as photo above.
Some steady hands and a small iron could tap it. So, i made it, it small.
Warning : make sure connect deep-sleep mode pin before silk it PIN 8 (XPD-DCDC)
But i forget it !!! So, i can not test deep sleep function
Ref : http://www.bntdumas.com/2015/07/23/how-to-battery-...
More Detail : www.imediabank.com
Connect Together
Connect all Together
Test ESP-01 Extra ADC PIN
Test Extra
Test GPIO 0, 2, 4, 15
<p>for i=0, 6, 1 do <br> gpio.mode(i, gpio.OUTPUT)
end</p><p>for i = 0, 6, 1 do
print(i)
gpio.write(i, gpio.HIGH)
print("HIGH")
tmr.delay(1000000);
gpio.write(i, gpio.LOW)
print("LOW")
tmr.delay(1000000);
end</p>Test ADC Pin
This example is connect a light sensor with 220Ohm.
<p>-- in you init.lua:<br>if adc.force_init_mode(adc.INIT_VDD33)
then
node.restart()
return -- don't bother continuing, the restart is scheduled
end</p><p>for i=0,10 do
print("System voltage (mV):", adc.readvdd33(0))
tmr.delay(1000000)
end</p>Result
<p>System voltage (mV): 635<br>System voltage (mV): 685 System voltage (mV): 637 System voltage (mV): 574 System voltage (mV): 0 System voltage (mV): 0 System voltage (mV): 209 System voltage (mV): 213 System voltage (mV): 616 System voltage (mV): 672 System voltage (mV): 673</p> Now you can do anything analog read by esp01
Test Client / Server With OLED Display
The following test is to send analog signal by ESP-01 ADC Extra Pin to NodeMCU and show on OLED
Test Client / Server with OLED Display
Client LUA
<p>function initADC() <br> if adc.force_init_mode(adc.INIT_VDD33) then
node.restart()
return -- don't bother continuing, the restart is scheduled
end
--for i=0,10 do
-- print("System voltage (mV):", adc.readvdd33(0))
-- tmr.delay(1000000)
--end
end </p><p>wifiUp = function()
wifi.setmode(wifi.STATION)
wifi.sta.config(conf.wifi.ssid, conf.wifi.pwd)
wifi.sta.connect()
end</p><p>setPin = function()
gpio.mode(0, gpio.INPUT)
end</p><p>check = function()
gpio.mode(2, gpio.OUTPUT)
ip = wifi.sta.getip()
if ip ~= nil then
print(ip)
gpio.write(2, gpio.HIGH)
end
end</p><p>--tempStatus = function()
-- status,temp,humi,temp_decimial,humi_decimial = dht.read11(conf.pins.temp)
-- t = {
-- plain = temp,
-- hash = crypto.toHex(crypto.hmac("md5", tostring(temp), conf.secret))
-- }
-- return cjson.encode(t)
--end</p><p>function urlEncode( str )
if ( str ) then
str = string.gsub( str, "\n", "\r\n" )
str = string.gsub( str, "([^%w ])",
function (c) return string.format( "%%%02X", string.byte(c) ) end )
str = string.gsub( str, " ", "+" )
end
return str
end</p><p>readSensor = function()
return adc.readvdd33(0)
end</p><p>b = true
ctr = 0</p><p>payload = function( code )
--local t = tempStatus()
--print(b)
urlstr = ""
if (b == true) then
b = false
urlstr = "GET /?pin=ON1&" ..
"sensor=" .. readSensor() .. "&" ..
-- "name=" .. urlEncode("Sanki Poon") .. "&" ..
"value=" .. tmr.now() .. "&" ..
"ctr=" .. ctr ..
" HTTP/1.1\r\nHost: " .. conf.server.ip .. "\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n";
--return urlstr;
--return "GET /?pin=ON1&abc=101&name=Sanki%20Poon HTTP/1.1\r\nHost: 192.168.0.102\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n";
else
b = true
--return "GET /?pin=OFF1 HTTP/1.1\r\nHost: 192.168.0.105\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n";
urlstr = "GET /?pin=OFF1&" ..
"sensor=" .. readSensor() .. "&" ..
-- "name=" .. urlEncode("Sanki Poon") .. "&" ..
"value=" .. tmr.now() .. "&" ..
"ctr=" .. ctr ..
" HTTP/1.1\r\nHost: " .. conf.server.ip .. "\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n";
end
ctr = ctr + 1;
return urlstr;</p><p>-- return "POST /proxy HTTP/1.1\r\n"
-- .. "Host: localhost\r\n"
-- .. "User-Agent: foo/7.43.0\r\n"
-- .. "Accept: */*\r\n"
-- .. "Content-Type: application/json\r\n"
-- .. "Content-Length: " .. string.len(t) .. "\r\n\r\n"
-- .. t
end</p><p>sendData = function()
sk = net.createConnection(net.TCP, 0)</p><p> retStr = payload(1)</p><p> sk:on("connection", function()
--sk:send(payload(1))
sk:send(retStr)
end)</p><p> sk:on("sent", function()
sk:close()
end)</p><p> sk:connect(conf.server.port, conf.server.ip)
print("Sending..." .. retStr)
end</p><p>conf = {
wifi = { ssid='SweetHome', pwd='<Password>' },
pins = { board=3, temp=6 },
server = { port=80, ip='192.168.0.105' },
secret = "secret",
}</p><p>wifiUp()
setPin()</p><p>tmr.alarm(0, 1000, 0, initADC)
tmr.alarm(0, 4000, 0, check)
tmr.alarm(1, 2000, 1, sendData)</p>NodeMCU Server LUA
<p>-- setup SPI and connect display<br>function init_spi_display()
-- Hardware SPI CLK = GPIO14
-- Hardware SPI MOSI = GPIO13
-- Hardware SPI MISO = GPIO12 (not used)
-- CS, D/C, and RES can be assigned freely to available GPIOs
local cs = 8 -- GPIO15, pull-down 10k to GND
local dc = 4 -- GPIO2
local res = 0 -- GPIO16</p><p> spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
disp = u8g.ssd1306_128x64_hw_spi(cs, dc, res)
end</p><p>-- graphic test components
function prepare()
disp:setFont(u8g.font_6x10)
disp:setFontRefHeightExtendedText()
disp:setDefaultForegroundColor()
disp:setFontPosTop()
end</p><p>--init_i2c_display()
init_spi_display()
--disp:firstPage()</p><p>function showOLED(sensor, ctr)
disp:firstPage()
repeat
prepare()
-- SANKI
--disp:setScale2x2()
--
-- LINE ~ +9
--
disp:drawStr(36, 3, wifi.sta.getconfig())
disp:drawStr(0, 15, "IP : " .. wifi.sta.getip())
disp:drawStr(0, 24, "Mac:" .. wifi.sta.getmac())
if (wifi.ap.getip() ~= nil) then
disp:drawStr(0, 33, "AP : ")
disp:drawStr(30,32, wifi.ap.getip())
end
if (ctr ~= nil) then
disp:drawStr(0, 42, "PWM: " .. sensor)
disp:drawStr(0, 51, "Ctr: " .. ctr)
end
--disp:undoScale()
until disp:nextPage() == false
end</p><p>wifi.setmode(wifi.STATION)
wifi.sta.config("SweetHome","<Password>")</p><p>led1 = 2
led2 = 3
gpio.mode(led1, gpio.OUTPUT)
gpio.mode(led2, gpio.OUTPUT)
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 = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."
</p> ESP8266 Web Server<p>";
buf = buf.."
</p><p>GPIO0 ON OFF</p><p>";
buf = buf.."
</p><p>GPIO2 ON OFF</p><p>";
local _on,_off = "",""
if(_GET.pin == "ON1")then
gpio.write(led1, gpio.HIGH);
elseif(_GET.pin == "OFF1")then
gpio.write(led1, gpio.LOW);
elseif(_GET.pin == "ON2")then
gpio.write(led2, gpio.HIGH);
elseif(_GET.pin == "OFF2")then
gpio.write(led2, gpio.LOW);
end
print("....... Start ............")
print(_GET.pin);
print(_GET.sensor);
print(_GET.value);
--str = "Counter : " .. _GET.ctr;
print(_GET.ctr);
showOLED(_GET.sensor, _GET.ctr);
print("......... END ..........");
client:send(buf);
client:close();
collectgarbage();
end)
end)</p><p>print(wifi.sta.getip())</p>
<br>