Solar Powered Spark Core


This is a photon advertized as 0.4.9. I tried deep sleep and no news from it since

// This #include statement was automatically added by the Particle IDE.
#include "AudioGetAverageLib/AudioGetAverageLib.h"

// AudioGetAverageLib for Spark
// Copyright (c) Davide Gironi, 2014 
// References:
// Released under GPLv3.
// Please refer to LICENSE file for licensing information.

//set the audio input ADC channel
//set the audio input board reference voltage
#define AUDIO_VOLTREF 0.0022
//set the audio input board reference dB value
#define AUDIO_DBREF 40

//set the reference ADC voltage
double analogVoltageRef = ANALOGVOLTAGEREF; //ADC reference voltage
double soundDbl;

char server[] = "";
TCPClient client;

//initialize audioGet library
AudioGetAverageLib audioGet(

void setup() {
    //startup serial
    Spark.publish("BC2 Booted!");
    Spark.variable("sound_dbl", &soundDbl, DOUBLE);
    client.connect(server, 8080);


void loop() {
    int audioRms = 0; //audio RMS value
    int audioSpl = 20; //audio Spl value
    int audioAdc = 0; //audio raw ADC
    //get raw ADC
    audioAdc = analogRead(AUDIO_INPUTCHANNEL);
    //get RMS value
	audioRms = audioGet.getRms();
	double voltageRms = AUDIO_VOLTREF;
	if(audioRms > 0) {
	    voltageRms = audioRms*analogVoltageRef/4096;
	    if(voltageRms < AUDIO_VOLTREF) { //prevent values less than AUDIO_DBREF
	        voltageRms = AUDIO_VOLTREF;
    //get Spl value
    soundDbl = (double)audioGet.getSpl(voltageRms, AUDIO_VOLTREF, AUDIO_DBREF);
    Spark.publish("librato_bc2_dbl", String((int)soundDbl));
    client.println("GET /json.htm?type=command&param=udevice&idx=424&svalue="+String((int)soundDbl)+" HTTP/1.0");
    client.println("Connection: close");
    client.print("Host: ");
    client.println("Accept: text/html, text/plain");
    System.sleep(SLEEP_MODE_DEEP, 60);
	//audioSpl = audioGet.getSpl(voltageRms, AUDIO_VOLTREF, AUDIO_DBREF);
    //output values
	//Serial.write(' ');

I’m not sure what’s wrong with your setup, but when I try your code (without a remote server and without analog input tho’ - and instead of a SparkFun LiPo Rider I’m using Particle Power Shield with a 4700mAh LiPo), my Photon comes back after exactly 60 seconds each time.

Can you just check if your selected target version in Particle Build really is 0.4.9?
Also just to make sure, put your device into DFU Mode and run particle update to be absolutely sure the system is definetly updated correctly.

What kind of battery are you using? Some power banks just switch off if there is too little current drawn for too long.
To test, try reducing the sleep time to 30sec (or 10sec) or use System.sleep(D7, FALLING, 60) to draw some current while sleeping.

1 Like

ok, updated of all photons (no core update anymore…)

Batteries are LiPo 4000mAh with protection, the one I’m familiar with. I have the power shield, but reading the forum I saw some had results with it. I’ve not seen if the Power Shield can handle a solar panel yet (the mustached one didn’t :wink:

I’m running your D7 Falling to see how it behaves. I’ll report back and will try other methods to see if it works. BTW code around is not functional, I am to find a real fft to make it a SPL.

Also try to comment your TCP/IP code as a test… Se if it works without it.


I’ve had some success with the battery shield (non-mustache version) and a 6W Adafruit solar panel. I’ve got the Photon in deep sleep mode (this makes a big difference for power consumption) for 15 minutes and then it awakes, connects to the wifi and then cloud and eventually publishes Voltage and State of Charge to Thingspeak, afterwhich it goes back to sleep.

I think I have a 5400 mAh battery connected to the battery shield, and it easily lasts through the night.

Initially I did this as a test however I enjoy seeing the data now that I’ve left it in the sun (inside behind a window which does reduce the solar power received). I would like to, in the future, get some other sensor data from it, as well as build / print a proper enclosure and have it outside in the full sun.

I’d be happy to share any code if anyone wants.

Yes I would be very please to test.

I’m a bit puzzled why you say it lasts through the night, it is better than that from your graph ?

I also have the power shield, but you say you have the 6W Adafruit which is given to 6V at 930 mA, do you use it in the “7-20V DC” input ?

at 120s, it worked till 22:35 yesterday, led was solid blue when I opened the box tonight, but it restarted, not short of battery…

the device is outside, is there a reproductibility I would test without making it to the outside to test deep sleep ?

@epierre I suppose you’re right, it does better than just last through the night; with an average charge around 87% it does pretty well and can be left without worry of the battery draining.

I also checked this morning and saw that I only have a 2500 mAh battery, and not the Adafruit solar panel, but another Chinese one which gives out similar values. I plug it straight into the 7-20V DC input and it does well in direct sun. I do notice that in the afternoon it battles with indirect sun (and the blue light is not on).

I’ve put up the code I used here, it’s pretty straight forward and obviously you need to have a Thingspeak account (you’ll need to replace the XXXXXXX’s with your own key) ready to publish the data to, if that’s where you want to go.

Here is my setup on the windowsill at home :

The black and white cables come from the solar panel above.

Let me know if there is anything else you need.

1 Like


I thought this might be interesting. This is a download of my published solar data for about 3-4 months of operation (pictures in post above). It shows :

  • daily small spikes for catching the morning sun
  • large drops in State of Charge from some coding errors (Photon hunting for wifi router and not connecting, not connecting to the cloud, etc. During these events it is in normal power mode but because it is using the radio so much it drains the battery quickly. I’ve since added in some loops to stop the searching after a certain amount of time).
  • generally pretty good State of Charge and Voltage readings over the long term. Certainly enough to consider adding additional sensors, functionality etc.
  • I initially started publishing data every couple of minutes but this took too much energy, and getting data points every 15 minutes is more than enough data points per day (could actually do with less).
  • it would be interesting to use this graph to show winter / summer transition, and perhaps also a UV index result from another sensor…


@neal_tommy Are you using shield from Particle or SparkFun ?
solar panels are in general good, so you are directly on the input for the solar panel.

right now I’ve been running a Photon on the Power shield and a 4000mAh, no solar panel. No Internet connection, just the powershield push to cloud and deep sleep that worked for one day.

I’ve now reintroduced the internet connection to see if that goes well for the next 24h.

thanks all for your help for I was really stuck on this subject and there are some situation I need a Photon !

[quote=“epierre, post:34, topic:3812”]
Are you using shield from Particle or SparkFun ?
[/quote] @epierre I am using the shield from Particle - works like a dream! Good luck wihth your projects and let us know how you get on.

@neal_tommy you use the SparkFunMAX17043/SparkFunMAX17043.h, is it working with both ?

I’ve now two photons in a box with a solar panel, one stii with adafruit, the other with particle shield. I have a 1W solar panel and each a 4000mAh LIPO (adafruit/china)

The Sparkfun code works 100% as the chip that drives the fuel gauge is the same on both the Sparkfun and Particle boards (MAX17043), so that saves a lot of work.

This is the Particle one :

And this one is from Sparkfun :

Super pictures!

1 Like

@neal_tommy but those code gives the same no ?

I’m learning ThinkSpeak as I try to understand your code, not that easy, maybe you should put XXX for channel too :wink: I’ve learned I must declare fields, yours start at 2 not one, must be legacy code :wink:

another question more general, why can’t I reflash the Particle that goes into sleep ? is there a simpler way that making it back to dfu with Tinker ? I also have a spark/flash/status going from started to failed, strange no ?

@epierre - Yes, you would need your own channel number too, from registering on the website. I did start at Field 2 for some strange reason (I think I had another variable in there which I didn’t need). Just make sure that the Fields on Thingspeak and in your code match up.

Not sure I understand the other questions of yours… reflashing to Tinker I normally do through the iPhone app although it is hardly needed as the Photon wakes up from sleep, performs a function and goes back to sleep. If I need to program it then I put it in Safe Mode (which means it is connected to the cloud but not running any code). Device Modes

[quote=“epierre, post:38, topic:3812”]
I also have a spark/flash/status going from started to failed, strange no ?
[/quote] Not sure what is going on here?

@neal_tommy even in safe mode it does not reprogram (or I don’t wait enough maybe…) so I reflash Tinker in dfu.

yes the flash status is puzzling to me, but it is flashed anyway.

ThingSpeak is interresting for its data analysis but is limited to 8 sadly… I’m trying to push some data to it:

On Xively there is less analysis possible but much more capacity and a real AIPI :wink:

This is a known issue that was already addressed in several threads and is on the ToDo list.
But despite the message the flash usually succeedes.

What does your LED show when in Safe Mode and during OTA flash?

1 Like

@ScruffR gee thanks !


The one with deep deep is still alive, the other stopped yesterday noon.

Both have same battery and solar panel. Will try same code on both.

ok so one stopped today, last value:
ps-soc 35.058594
ps-voltage 3.791250

I’m recharging it now.

I’ve discovered this post, very interesting for it is in the same target: Unexpected lockup of Photon with SparkFun PowerShield

1 Like