Spark Core Battery Percentage Checking

Hi guyz !

I’m just wondering if we had any solution for percentage checking the battery which the spark core is connecting to ?
I see we can do this with Arduino but don’t know how about spark core.

Can you tell us how is it done with the Arduino? The spark core and the Arduino are similar in many respects so the arduino solution may transition to the spark core quite simply.

hi mdma !

I’m just a beginner with Spark Core.

Today, I just tried to put this code ( for Arduino ) in Spark IDE ( changed something in code to adapt to Spark IDE ) :

But got these errors :


Vcc.cpp: In member function 'float Vcc::Read_Volts()':
Vcc.cpp:45:7: error: 'ADMUX' was not declared in this scope
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:38:30: error: 'REFS0' was not declared in this scope
#define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
^
Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:38:35: error: '_BV' was not declared in this scope
#define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
^
Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:38:43: error: 'MUX3' was not declared in this scope
#define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
^
Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:38:55: error: 'MUX2' was not declared in this scope
#define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
^
Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:38:67: error: 'MUX1' was not declared in this scope
#define ADMUX_VCCWRT1V1 (_BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1))
^
Vcc.cpp:45:16: note: in expansion of macro 'ADMUX_VCCWRT1V1'
if (ADMUX != ADMUX_VCCWRT1V1)
^
Vcc.cpp:51:26: error: 'delayMicroseconds' was not declared in this scope
delayMicroseconds(350); 
^
Vcc.cpp:55:3: error: 'ADCSRA' was not declared in this scope
ADCSRA |= _BV(ADSC);
^
Vcc.cpp:55:17: error: 'ADSC' was not declared in this scope
ADCSRA |= _BV(ADSC);
^
Vcc.cpp:55:21: error: '_BV' was not declared in this scope
ADCSRA |= _BV(ADSC);
^
Vcc.cpp:56:32: error: 'bit_is_set' was not declared in this scope
while (bit_is_set(ADCSRA,ADSC)) {};
^
Vcc.cpp:61:28: error: 'ADC' was not declared in this scope
float vcc = 1.1*1023.0 / ADC;
^
Vcc.cpp: In member function 'float Vcc::Read_Perc(float, float, bool)':
Vcc.cpp:75:38: error: 'constrain' was not declared in this scope
perc = constrain(perc, 0.0, 100.0);
^
make: *** [Vcc.o] Error 1

After that, I visited many topics about battery checking issues and got these topics :

So now I have no idea how checking battery in spark core without using another board to measure.

1 Like

@hansthinhle, this was previously addressed in this thread of topics:

:slight_smile:

1 Like

The spark is arduino-like - it supports a large portion of the Wiring API, so porting high-level code is very straightforward. However, the code you're looking it as low-level code that uses specific features of the arduino chip. The spark isn't an arduino but an entirely different processor, and has its own set of low-level features.

The first thread you linked to provides some hints on how to obtain a bandgap reference.