Measuring ESP8266 power usage with uCurrent and a scope
Introduction
This is a follow up to the ESP8266 article on agocontrol news. The GY-63 sensor board is drawing a lot current (around 2mA) due to its level shifters and the voltage regulation. Hence I’ve abandoned my plan to use one. I’ll probably get a few test units of the Bosch BE280, it might be a good option for a esp8266 based battery powered weather station. For now I’m going to use a DHT22 as I want to measure a scenario with real sensors. I’m providing the complete files so that Robert Hekkers can compare his measurements to mine.
Test setup
This is the „init.lua“:
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","secret")
tmr.alarm(0, 2000, 0, function()
dofile("mqtt.lc")
end)
And here we’re doing the measurement and transmit the data – „mqtt.lua“:
BROKER = "192.168.1.1"
BRPORT = 1883
BRUSER = "user"
BRPWD = "pwd"
CLIENTID = "ESP8266-" .. node.chipid()
PIN = 6 -- GPIO 12
dht22 = require("dht22")
dht22.read(PIN)
t = dht22.getTemperature() /10
h = dht22.getHumidity() /10
-- print "Connecting to MQTT broker. Please wait..."
m = mqtt.Client( CLIENTID, 120, BRUSER, BRPWD)
m:connect( BROKER , BRPORT, 0, function(conn)
-- print("Connected to MQTT:" .. BROKER .. ":" .. BRPORT .." as " .. CLIENTID )
m:publish("sensors/".. CLIENTID .. "/temperature",t,0,0, function(conn)
-- print ("temp published")
-- tmr.delay(10000)
m:publish("sensors/".. CLIENTID .. "/humidity",h,0,0, function(conn)
-- print ("pressure published")
node.dsleep(5*1000000)
end)
end)
end)
The dht22.lua comes from the nodemcu git. dht22.lua and mqtt.lua have been compiled.
Scope captures
Complete wake-up phase (200ms/DIV horizontal, 30mA/DIV vertical with the uCurrent being in mA mode)
Next steps
Verify measurements and calculate total power usage over time: The scope is calculating the area as 174.2mVs. So with a total wakeup time of about 2.6s that would be an average of 66mA current draw while being awake. With 4 wakeups/h what would give 0.19mAh (4*2.6s/3600*66mA). The rest of the hour sleeping would draw 0.022mAh, resulting in 0.212mAh total. With 2500mAh AA NiMH (low self discharge, assuming 80% after 1y) that would be about a year (ignoring step-up losses).