Monday, 30 March 2015

ArduinoDay2015 #ArduinoD15 Quick project: Battery capacity tester

Last Saturday was Arduino Day and, of course, I felt obliged to build a little project. As there was just over an hour of ArduinoDay left in my timezone, I had to hurry up and make a few compromises.

The result was this rather simple circuit:

Somehow a relay with two sets of switches had made it into my sparkfun inventor's kit, So I used that second set to switch between two status LEDs, just for the heck of it.
The only thing not contained my (somewhat older) Sparkfun Inventor's kit was a suitable load resistor. I found a 15 Ohms resistor that looked like it could dissipate a few watts. For the 3.7V lithium cell I wanted to test, that should result in a current of approx. 250mA and around 1 Watt of heat that has to be radiated off.

If you want to build this, I'd strongly recommend to use thicker, shorter wires, because the lousy jumper wires and breadboard add an awful lot of resistance.

 int sensorPin = 0;  
 int sensorValue = 0;  
 int time = 0;  
 int rel = 13;  
 float cur = 0;  
 float cap = 0;  
 void setup()  
 pinMode(rel, OUTPUT);  
 digitalWrite(rel, HIGH);  
 delay (1000);  
 void loop()  
 sensorValue = analogRead(sensorPin);  
 float voltage= sensorValue * (5.0 / 1023.0);  
 if (voltage > 3)  
  cur = voltage / 15; //current through the 15 Ohms Resistor   
  cap = cap + (cur / 60);   
  delay(60000); //1 minute delay between readings.  
  digitalWrite(rel, LOW);  

The sketch cuts out at 3V to protect the cell from deep discharges. That is very safe, but it leaves some capacity in the cell. Keeppower's protection circuits cut off at 2.75V.

I then fed the Time/Volts (the first two columns) to LibreOffice Calc:
Gaaaah! This is one ugly graph. I suppose it is mainly because of contact issues. Thermal effects might also contribute.
On the other hand, the capacity measured is 776 mAh. Not far off for a 800 mAh cell. This is because the current is derived from the voltage drop over the 15 Ohms resistor. And that stays valid, even if the surrounding wiring is poor and adds extra resistance.

Warning: If you need to measure cells over 5V, you need a voltage divider. Otherwise you'll damage your Arduino board. Or at least the microcontroller chip.

Here is the link to my video:

Edit: 20150401 Corrected circuit diagram.

Wednesday, 18 March 2015

Safe makeshift alternative to solar eclipse glasses

The solar eclipse is coming and I am was not prepared!
All special solar eclipse glasses are sold out here and the Kindergarden was desperately looking for glasses for the kids to watch the eclipse.
This morning I had some time and with some household items, I built a camera obscura.
These items alsong with my trusty old tripod make a safe alternative to the special solar eclipse glasses.
The projected image is about 3mm in size, just sufficient to make out the disk of the sun. - And hopefully the missing bits during the eclipse.
That is what the projected image looks like with my digital camera's macro lens.

Looks promising to me.

Here are the instructions in detail:

Worked great!

Tuesday, 17 March 2015

NodeMcu 20150317 is out

Just 16 hours ago, what appears to be a dev-version of nodemcu has been released.
Again for me it was a bit hard to find, so here is the link:

The filesize of the bin files has gone up again, but there is now also an integer binary that saves the memory otherwise needed for float operations.

With the integer binary this obviously results in an error:

 > print (0.5 + 0.5)  
 stdin:1: malformed number near '0.5'  

While that works:
 > print (5 + 5)  

Unfortunately my LUA-DNS server doesn't run on any of these two either.

Although the filename implies it is version 20150317, it comes up as 20150315:

 >  ü!   ¤§1ä)]ô   
 NodeMCU 0.9.5 build 20150315 powered by Lua 5.1.4  
 lua: cannot open init.lua  

Wednesday, 4 March 2015

UDP server problem with NodeMCU build 0.95 / nodemcu_20150213.bin

For an upcoming project I need to run a DNS server on the ESP8266 module (ESP-01). All this server has to do is reply to any DNS query with the modules' IP address.
Basically that is what some captive portals do.

I developed that script on nodemcu_20150212.bin without any significant trouble and it ran ok there.

To make use of the node.compile() option, I upgraded to the 20150213.bin but the MCU crashed and rebooted when trying to send back the DNS reply.

The LUA script looks like this:

 encodedns (query, transaction_id)  
 function decodedns(pl)  
      --do some magic  
 function encodedns(query, transaction_id)  
      --do some more magic  

The svr:send failed and crashed the mcu. It totally lacks all input sanitation and can easily be derailed, but that is another story.

Looking at the changes from 20150212 to 20150213, the only suspicious change was this:

  @@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.  
 -#define LUAL_BUFFERSIZE          BUFSIZ  
 +#define LUAL_BUFFERSIZE          (BUFSIZ*4)  
  /* }================================================================== */  

I changed that back to the original buffer size and sure enough my script was fine again.

Sunday, 1 March 2015

esp8266 lua firmware NODEMCU with node.compile() option

This post may soon be obsolete, so take it with a grain of salt.

I just couldn't get NodeMCUs node.compile() feature to work. I thought I had the latest firmware on the module, because that was what I got as "latest" from github.

The latest firmware (at the time of writing) can be found here:

NodeMCU Firmware Download

 NodeMCU 0.9.5 build 20150213 powered by Lua 5.1.4  
 lua: cannot open init.lua  
 Hard Restart Sonntag, 1. März 2015 23:38:42  
 for k,v in pairs(file.list()) do l = string.format("%-15s",k) print(l.."  "..v.." bytes") end  
 httpserver.lua  3750 bytes  
 dnsserver2.lua  3554 bytes  
 > node.compile('dnsserver2.lua')  
 > for k,v in pairs(file.list()) do l = string.format("%-15s",k) print(l.."  "..v.." bytes") end  
 dnsserver2.lua  3554 bytes  
 httpserver.lua  3750 bytes   2488 bytes  

Looking good!