I am not sure if I am doing something wrong nor right with respect to Power Manger settings. I am trying to increase the min. power source voltage so my 12 v (350ma) solar panel will charge the battery and not go into the low voltage state (flashing red on the chrg light). So my questions that I could figure out on my own are.
- Does the "SystemPowerConfiguration conf" go into void setup () or void start up ()?
- Do you need to call "PMIC power(true);" in void loop ()?
- Is there are way to verify the setting with a location call back. (I tried putting PMIC power(true) in the call back and it unit stopped working)?
I am also using Vin on the main board and not one of the expansion boards.
Thank you in advance.
Here is the code below.
#include "Particle.h"
#include "Arduino.h"
#include "edge.h"
#include "SparkFun_ADS1015_Arduino_Library.h"
SYSTEM_THREAD(ENABLED);\
SYSTEM_MODE(SEMI_AUTOMATIC);
#if EDGE_PRODUCT_NEEDED
PRODUCT_ID(EDGE_PRODUCT_ID);
#endif // EDGE_PRODUCT_NEEDED
PRODUCT_VERSION(EDGE_PRODUCT_VERSION);
STARTUP(
Edge::startup();
);
SerialLogHandler logHandler(115200, LOG_LEVEL_TRACE, {
{ "app.gps.nmea", LOG_LEVEL_INFO },
{ "app.gps.ubx", LOG_LEVEL_INFO },
{ "ncp.at", LOG_LEVEL_INFO },
{ "net.ppp.client", LOG_LEVEL_INFO },
});
char buf[256];
ADS1015 adcSensor;
void myLocationGenerationCallback(JSONWriter &writer, LocationPoint &point, const void *context);
void setup()
{
SystemPowerConfiguration conf;
conf.powerSourceMaxCurrent(900)
.powerSourceMinVoltage(4300)
.batteryChargeCurrent(850)
.batteryChargeVoltage(4210);
int res = System.setPowerConfiguration(conf);
Log.info("setPowerConfiguration=%d", res);
//System.setPowerConfiguration(SystemPowerConfiguration());
Serial.begin(9600);
Edge::instance().init();
TrackerLocation::instance().regLocGenCallback(myLocationGenerationCallback);
if (adcSensor.begin() == true)
{
Log.error("ADC Successfully Started");
Particle.publish("Log", "ADC Successfully Started");
}
else
{
Log.error("ADC Failed");
Particle.publish("Log", "Failed");
}
}
void loop()
{
Edge::instance().loop();
//PMIC power(true);
// Log.info("Current PMIC settings:");
//Log.info("VIN Vmin: %u", power.getInputVoltageLimit());
//Log.info("VIN Imax: %u", power.getInputCurrentLimit());
//Log.info("Ichg: %u", power.getChargeCurrentValue());
// Log.info("Iterm: %u", power.getChargeVoltageValue());
//delay (11000);
// Testing the ADC module
//short adc0, adc1, adc2, adc3;
//adc0 = adcSensor.getSingleEnded(0);
//adc1 = adcSensor.getSingleEnded(1);
//adc2 = adcSensor.getSingleEnded(2);
//adc3 = adcSensor.getSingleEnded(3);
//Serial.print("AIN0: "); Serial.print(adc0);
//Serial.print("AIN1: "); Serial.print(adc1);
//Serial.print("AIN2: "); Serial.print(adc2);
//Serial.print("AIN3: "); Serial.print(adc3);
//delay (2000);
}
void myLocationGenerationCallback(JSONWriter &writer, LocationPoint &point, const void *context)
{
int PB1 = adcSensor.getSingleEnded(0);
int PB2 = adcSensor.getSingleEnded(1);
int PB3 = adcSensor.getSingleEnded(2);
String Bearing1;
String Bearing2;
String Bearing3;
writer.name("Bearings").beginObject();
writer.name("PB1").value(PB1);
writer.name("PB2").value(PB2);
writer.name("PB3").value(PB3);
writer.endObject();
if (PB1 > 1200 && PB1 <3200)
{
Bearing1 = "Running";
}
else
{
Bearing1 = "Failed";
}
if (PB2 > 1200 && PB2 <3200)
{
Bearing2 = "Running";
}
else
{
Bearing2 = "Failed";
}
if (PB3 > 1200 && PB3 <3200)
{
Bearing3 = "Running";
}
else
{
Bearing3 = "Failed";
}
Particle.publish("Bearing 1=", Bearing1, PRIVATE | WITH_ACK);
Particle.publish("Bearing 2=", Bearing2, PRIVATE | WITH_ACK);
Particle.publish("Bearing 3=", Bearing3, PRIVATE | WITH_ACK);
}