Greetings,
I just got my photons and i was trying to use some of the examples from the IDE but it seems that i cannot make them to work.
To be short,
I wanted to read the battery status and voltage from the power shield and to put it on the cloud but no luck.
In the sample i have :
#include "PowerShield/PowerShield.h"
PowerShield batteryMonitor;
void setup() {
}
void loop() {
Wire.begin();
batteryMonitor.reset();
batteryMonitor.quickStart();
delay(1000);
float cellVoltage = batteryMonitor.getVCell();
float stateOfCharge = batteryMonitor.getSoC();
Spark.publish("voltage", String(cellVoltage), 60, PRIVATE);
delay(100);
Spark.publish("soc", String(stateOfCharge), 60, PRIVATE);
delay(100);
//System.sleep(SLEEP_MODE_DEEP, 600);
}
I tried to change Spark with Particle but still no result.
If i use this code :
#include "PowerShield/PowerShield.h"
PowerShield batteryMonitor;
void setup() {
Serial.begin(9600);
// This essentially starts the I2C bus
batteryMonitor.begin();
// This sets up the fuel gauge
batteryMonitor.quickStart();
// Wait for it to settle down
delay(500);
}
void loop() {
// Read the volatge of the LiPo
float cellVoltage = batteryMonitor.getVCell();
// Read the State of Charge of the LiPo
float stateOfCharge = batteryMonitor.getSoC();
// Send the Voltage and SoC readings over serial
Serial.print("Battery Voltage : ");
Serial.print(cellVoltage);
Serial.print(" ");
Serial.print("Charging state : ");
Serial.print(stateOfCharge);
Serial.println("");
delay(3000);
}
i can read over serial the values, but if i try to adapt that into variable part does not work.
Here is one of the multiple versions and still no luck
#include "PowerShield/PowerShield.h"
PowerShield batteryMonitor;
char returnString[63];
String someString;
char *BVoltage = "test";
int Voltage = 0;
int SOC = 0;
int rssi = 0;
void setup() {
if (Particle.variable("Voltage", BVoltage, STRING)==false);
memset(returnString, 0, 63);
//Particle.variable("test", returnString, STRING);
}
void loop() {
Wire.begin();
batteryMonitor.reset();
batteryMonitor.quickStart();
delay(100);
float cellVoltage = batteryMonitor.getVCell();
float stateOfCharge = batteryMonitor.getSoC();
someString = String(cellVoltage);
strcpy(returnString, someString.c_str());
delay(100);
Voltage = batteryMonitor.getVCell();
SOC = stateOfCharge;
rssi = WiFi.RSSI();
//BVoltage = String(cellVoltage);
Particle.variable("vbat", &Voltage, INT);
Particle.variable("SOC", &SOC, INT);
Particle.variable("RSSI", &rssi, INT);
delay(100);
Particle.variable("test", returnString, STRING);
//System.sleep(SLEEP_MODE_DEEP, 20);
}
If i use variable it seems that no matter what i use i get always 0 and if i make that conversion from INT or float to string i get 0.00000.
Any ideas are more than welcomed.
Thanks