@ctmorrision: how do I check what kind of board/card I’m using?
I figured out the reason: the battery was empty. But it looks like my device source code is sucking too much energy. Another new 9V battery also lasted only about 12 hours.
This is the device source code, why is it draining the battery?
// Configure Pins
// pin 8 is driven high to turn off temp monitor (saves power) or low to read
therm_en_l <- hardware.pin8;
therm_en_l.configure(DIGITAL_OUT);
therm_en_l.write(1);
// pin 9 is the middle of the voltage divider formed by the NTC - read the analog voltage to determine temperature
temp_sns <- hardware.pin9;
// instantiate sensor classes
function getTemp() {
// instantiate our thermistor class
myThermistor <- thermistor(temp_sns, b_therm, t0_therm, r_therm, 10, false);
therm_en_l.write(0);
local temperature = format("%.1f",myThermistor.read_c());
server.log(temperature);
agent.send(“updateTemp”, temperature);
Assumes thermistor is the high side of a resistive divider unless otherwise specified in constructor.
Low-side resistor is of the same nominal resistance as the thermistor
*/
class thermistor {
// thermistor constants are shown on your thermistor datasheet
// beta value (for the temp range your device will operate in)
b_therm = null;
t0_therm = null;
// nominal resistance of the thermistor at room temperature
r0_therm = null;
// analog input pin
p_therm = null;
points_per_read = null;
// force all of these values to floats in case they come in as integers
this.b_therm = b * 1.0;
this.t0_therm = t0 * 1.0;
this.r0_therm = r * 1.0;
this.points_per_read = points * 1.0;
this.high_side_therm = _high_side_therm;
}
// read thermistor in Kelvin
function read() {
local vdda_raw = 0;
local vtherm_raw = 0;
for (local i = 0; i < points_per_read; i++) {
vdda_raw += hardware.voltage();
vtherm_raw += p_therm.read();
}
local vdda = (vdda_raw / points_per_read);
local v_therm = (vtherm_raw / points_per_read) * (vdda / 65535.0);
This code is not designed to be kind to the battery, as it does not go into deep sleep between readings.
I have a thermometer in my garden shed which has been reporting the temperature and humidity every ten minutes for seven weeks, and is just nearing empty. This was running off an 850 mAh LiPo cell, and the key is to go into deep sleep after every reading, which reduces the current drain to about 6 microamps. I am using the reference code for a C3V0+ from MakeDeck, which includes monitoring the real battery voltage through a built-in resistive divider.
You’ll need to call server.sleepfor() when the imp goes idle (use imp.onidle(), as per the server.sleepfor() documentation).
Set it to sleep for 60s; the imp will wake, you can take a reading and send it to the agent (which will automatically bring up the WiFi, which goes off in deep sleep), and then your code can put the imp back into deep sleep again.
Bear in mind, waking from deep sleep is a warm reboot - your Squirrel code starts afresh with no variables preserved (that’s one way we get the power saving), so you’ll need to adapt your code accordingly, ie. configure the pin(s), take a reading, send the reading, go to deep sleep.