How to measure power / voltage from solar panel using Espruino

Posted on
Page
of 2
/ 2
Next
  • Is it possible to measure the output power / voltage from a solar panel with Espruino if connected to e.g. C0-C3 pins or other way?

  • You can, just make sure the you respect the 3.3V inputs. To be on a save side with measuring floating lines, you need to have Espruino's power supply galvanically separated - DC-DC isolated power converter, for example, something like http://www.ebay.com/itm/140702578979?_tr­ksid=p2055119.m1438.l2649&ssPageName=STR­K%3AMEBIDX%3AIT and data transmission wireless.

    The connected charge controller may though interfere with your measurements - assuming you have one in place.

    Something what you can for sure measure is what's going on at your battery... but even there, if the charge controller is on / charging, you do not get the actual voltage/charge condition. Since (cheap) charge controllers can not be influence from the outside, it will be a nice challenge. More expensive charge controllers have interfaces and they provide access to the measurements which they actually do for themselves to run proper charging cycles.

  • What kind of solar panel? A small one, or a large one that might power a house?

    And what are you powering - or do you just want to measure the power produced by it?

    Espruino can directly measure voltage with a pin marked as ADC (so C0-3 are fine) using analogRead(pinName) - as long as it is in the range 0v to 3.3v.

    Getting the current flowing out of the panel is more difficult, but the usual way to do that is to use a low-valued resistor, such that a small amount of voltage is lost inside it due to the current, and then you can measure that voltage and then work out the current.

    If you give us an idea what you want to do we could suggest a circuit... Probably the easiest circuit would be if you had a very small solar panel and you didn't want to power anything from it - then you'd just need one resistor.

    Having said that, solar panels are odd in that the power they produce depends on the current that you draw out of them - so for trying to find the maximum power you can get out of a solar panel for a certain amount of light (rather than just what it's producing right now) gets quite difficult!

    edit: as @allObjects says, if you have a 'charge contoller' for your solar panel then it will get the maximum power out of it - so then all you're worried about is measuring what comes out of the contoller.

  • Thank you for replies - I am amazed by the speed you answer my questions :)

    I have a small solar panel originally used to power 2x1,2 V / 1800 mAh batteries but never made it work so I took it apart to see if I can make it work with Espruino somehow. So actually I am just starting to learn all the terms to make my way around.

    Thanks again

  • Ok, cool. That's pretty easy then - I guess your best bet is to put a resistor right across it to give it something to put power into. Do you have a volt meter? If so you could experiment and pick some resistor value such that the voltage only got to the near maximum when you had the most light you ever thought you'd get.

    You connect panel negative to gnd, panel positive to C0, and put the resistor across gnd and C0.

    Then, working out the power is easy. You measure the voltage and know the resistance so current is I=V/R, and you multiply that by V again to get power, so it's power = V*V/R.

  • Thanks Gordon, actually I just bought a volt meter since I guess it is a necessity :) The voltmeter has some built in resistors right and is what your are referring to am I right?

    I will do what you suggest and experiment.

  • Well, the volt meter shouldn't provide any real resistance when measuring voltage - but to be honest, if you just wanted to test whether you get more power in one place than in another (rather than getting an 'absolute' measurement, measuring volts is almost certainly the easiest thing to do :)

  • I just tried this, without a resistor across actually and yet able to measure voltage. I am surprised how high the voltage readings are - bringing my 7 Watt lamp close to the solar panel read out a value around 3.1 V and value decreases as I bring the lamp further away naturally. Just fun :)

  • Hi

    I have connected the + from solar panel to Bat pin (lane connected to BAT pin in the power section referred on to this page http://www.espruino.com/EspruinoBoard) and - to GND but not seeing Espruino powered - what am I missing?

  • It might be that while the solar panel produces enough voltage, it doesn't produce enough current (and current*voltage=power). By default, Espruino doesn't go into ultra-low power mode either, so you might want to write some code like:

    setInterval(function() {
      digitalPulse(LED1, 1, 20);
    }, 5000);
    setDeepSleep(1);
    

    and then save it. That should blink the red LED every 5 seconds, while enabling deep sleep the rest of the time.

    You'll also probably need to add a capacitor (a supercapacitor would be awesome, but something greater than or equal to 200uF should be ok). This is so that when Espruino 'wakes up' and draws around 30mA of power for a brief instant, it can get that short burst out of the capacitor rather than the solar cell.

    Finally, when Espruino starts, it takes around 1 second to boot (it's waiting for a USB connection - I'm planning to change that soon though). During that time it's still drawing 30mA, which could also discharge the capacitor - so it's actually helpful to have the solar cell + capacitor plugged in, and to plug Espruino into USB for a few seconds initially to get it started, and finally to unplug USB (and then it should keep working).

  • Great, thanks Gordon

  • Sorry Gordon, so many questions...

    If I add (charged) batteries between the solar panel and the Espruino I believe I will obtain the same result as with capacitor in that the initial draw is taken from batteries. I plan to use the pins as written in #9 (the voltage will be below 3.6 for sure).

    But for an actual battery health check - to see if batteries are ok - how to achieve that? As I understand the NiMH batteries keeps voltage around 1.2 during lifetime and when discharged nothing - kind of on/off. So how to measure expected lifetime of batteries.

    I do not see it is possible to read analog from pin 'Bat' as this pin is not shown when examining the possibilities by just writing analogRead() - then how to?

    Thanks..

  • No problem! Yes, adding batteries instead of a capacitor is a great idea. There's actually an example of it here: http://www.espruino.com/Small+Solar+Powe­red

    The problem with your current setup is the voltage from the solar cell is a bit too low... I mean, you can charge 2xAA cells with it, but that's only really 2.4v which isn't really enough to run Espruino reliably. In the link above the solar cell gave out 4.5v or so (I think) under a bright light, which was enough to charge a Lithium Ion battery.

    But assuming you did find a cell that could give a voltage that could charge a battery that Espruino can run off, you've got this problem where Espruino runs off 3.3v (usually) and can only measure voltages between 0v and what voltage it runs off (3.3v), and the battery will have to be more than that.

    So to measure the voltage, you need a 'potential divider'. Just get two equal resistors of a relatively high resistance (around 100k ohms) and connect them together in the middle, then across the battery. Then connect the middle to 'C0'.

    It's a bit like connecting two elastic bands... the voltage of the middle will be halfway between the voltage of the two ends, so now all you have to do is to measure the voltage on C0 and multiply it by 2 to get the battery voltage.

  • About lifetimes: Google 'Nimh discharge curve' and look at the graphs.

    The voltage does tend to change as they discharge and charge, but only slightly (until they run out, then it drops off very quickly)... You can still use it to get a pretty good idea how much charge is left though.

    As far as I know different makes of batteries are all subtly different, so if you can't find a datasheet you can always experiment - running the battery down slowly and using Espruino to measure what happens to its voltage over time.

  • Do you have some sort of graphical representation of how to connect all the components? Or perhaps figure 1. on this page http://en.wikipedia.org/wiki/Voltage_div­ider is what you have in mind?

    Thanks...

  • Yes, Figure 1 is what you'll need, where Vin = the battery voltage, and Vout = pin C0.

  • Ok thanks but this setup should only be applied during measurement right? Otherwise the batteries will get depleted I imagine... could you use the pinMode to stop current from floating? I mean the 2 resistors will remain permanently in the setup so I from time to time can measure the health of the batteries.

    Thanks...

  • @Espruino_user_dk, if the values for Z1 and Z2 cannot made that high that for practical reasons the drain can be ignored, a dynamic measurement could help if the circuitry for that does drain less ant to the point of where the drain can be ignored... What about an 'overkill' with the theoretical circuitry below?

    The basic idea is to charge a very low leakage capacitor and then measure it's discharge (or charge behavior).

    With fast D1 and D2 and R3..R6 properly sized, the B2 and C0 processor pins are safe (on power on and beyond). With both pins open, (mainly) R4 and R5 will charge C1 to the point where Vb - Vt = VBatt. Now only the 'leakage of' C1 and T1 keep draining. (If no reasonable sizing for R1..R5 can be found to avoid T12 from switching on during C1 charging process, adding a D in between R3 and Vt point of C1 has to be added.)

    For measuring, Pin B2 is switched to on - B2.set() - which switches T1 on. T1 on pulls Vb to ground and pushes Vt to negative (-VBatt). R3, R5, and R6 (via D2 up to a certain point) will pull Vt up to about what R3 and R5 voltage divider on B2(High) defines, say (theoretical) Vm. In other words, C1 is discharged and re-charge in reverse polarity.

    The times for Vt to reach GND and then a particular percentage of (theoretical max) Vm correlate to VBatt (after being pushed to negative by pulling down Vb) correlate with VBatt. It would be quite interesting to see on an a scope what Vb, Vt, Vm, and Pin B2 do...

    Behavior of Vb and Vt (and Vm) after measuring should not pose any problems (C0 would go on open input and after that B2. Latter switches T1 off. Since Vb is negative vs Vb, C1 is discharged and then re-charged with re-reverse polarity... - worst case - Batt empty and low impedance (low inner R), another D between GND and Vt point of C is needed, but would have also have an effect on measurement).

    As said, this is all theoretical... and I have not much clue how to size the Rs and C, and figuring out the formula to map time to voltage is a totally different ball game. So I'm interested in anything that can say at first sight: It cannot work. ;-)


    1 Attachment

    • measureSolarBatVoltage.png
  • @allObjects that looks a bit heavy for what is required...

    @Espruino_user_dk the resistors will slowly run the battery down, yes - but not much. If you used 2x 100k resistors, it would draw 18uA (about the same as the Espruino when in sleep) so not that much at all.

    When measuring voltage, the STM32 chip tends to like having a 'low impedance', which means low resistance. You could actually use a small (around 100nF) capacitor to get that (and can then use even lower value resistors like 1M, which means that the discharge of the battery will be even lower). Circuit as attached.


    1 Attachment

    • Impedance_voltage_divider.svg.png
  • Do you mean 100uf or 100nf?

  • @mhoneywill thanks! Just updated to 100nF :)

  • I have started measurement with solarpanel and batteries attached so I can see how it behaves under various conditions.

    I have made logging for RAM and for SD card. For RAM everything is logged fine however, using SD card gives me some troubles. If connected writing to SD card is no problem however if entering the deep sleep mode, writing will fail and "ERROR: Unable to read file : DISK_ERR" will be reported. Is more power required for SD card operations? Below is what is measured in deep sleep mode, e.g. 2,93265214797:

    Sun Nov 2 2014 10:46:21 GMT+0000;2,93265214797
    Sun Nov 2 2014 10:46:31 GMT+0000;2,93090339892
    Sun Nov 2 2014 10:46:41 GMT+0000;2,92566964285
    Sun Nov 2 2014 10:46:51 GMT+0000;2,92566964285

    Thanks...

  • What are the two numbers 2,93265214797, or is it the actual voltage?

    The SD card will almost certainly draw more power than Espruino does when in deep sleep - and it'll also need 3.3v on the supply rail. What batteries are you running off? You'd really need either 3 AAs, or a Lithium ion battery.

    It's possible there's a problem logging to the SD when it's come back from deep sleep, but I'd be surprised - If that was an issue I'm sure it would have been found long ago.

  • I forgot to show the number with. so it would make sense for you, should have been 2.93265214797 which is the voltage measured when batteries (3 AAAs) is connected to GND and 3.3V pins. From what you are writing I think there is not enough voltage.

    The SD card has been formatted as FAT32 prior to use.

    Thanks

  • Ahh - I guess 3x slightly flat AAA batteries will come to 1v*3 = 3v. I guess you might have to use 4 in that case (if you're planning on powering the SD card off them).

    If you do that, don't connect to the '3.3v' pin though. It's best to connect to the JST battery power connector (if you can, otherwise use pins marked 'Bat' - but using those will cause 4.7v to be put across the batteries if USB is connected, which isn't good news).

    You'd need to do that so Espruino's voltage regulator can regulate it down to 3.3v.

    While Espruino can take 2v to 4v on the 3.3v line, 4x charged AAAs would be too high. I also have no idea about the flash, but I assume that it is very picky about voltages, so you'll need to make sure that runs from the regulated 3.3v.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to measure power / voltage from solar panel using Espruino

Posted by Avatar for Espruino_user_dk @Espruino_user_dk

Actions