I want to be able to read the voltage of both the battery pack and the 5V being delivered to the Raspberry PI.
In Nybble.ino at about line 432 is the following code. Nybble reads Analogue port A0 (BATT) and if it is less than 3V, Nybble will meow.
void loop() {
float voltage = analogRead(BATT);
if (voltage <
#ifdef NyBoard_V0_1
650
#else
300
#endif
) { //give the cat a break when voltage drops after sprint
//adjust the thresholds according to your batteries' voltage
//if set too high, Nybble will keep crying.
//If too low, Nybble may faint due to temporary voltage drop
PTL(voltage);//relative voltage
meow();
}
In my Nybble, with a fresh set of batteries (8.1V) analogRead(BATT) returns about 5.6V. Is this the potentiometer setting value or is it the 5V VCC rail into the Arduino and Raspberry PI?
Can I get A0 to read the actual Battery voltage or is it limited to the arduino VCC voltage. In an other way I'm asking what is the voltage divider into A0?. If there is no divider and I am limited to VCC, should I use Analogue port A1 with a suitable voltage divider and connect this to the A1 pinout on Nybble.
Best regards
D L
Hi @Rongzhong Li,
any plans to add the voltage status command into OpenCat.ino?
Will this also work with the new Bittle Battery?
Out of pure interest I grabbed the standard Firmata sketch https://github.com/firmata/arduino/blob/master/examples/StandardFirmata/StandardFirmata.ino and compiled it to get an indication of how big it was.
Sketch uses 12492 bytes (40%) of program storage space. Maximum is 30720 bytes. Global variables use 1053 bytes (51%) of dynamic memory, leaving 995 bytes for local variables. Maximum is 2048 bytes.
My Nybble.ino (v0.2 plus the extra lines to implement voltage) uses the following:
Sketch uses 30396 bytes (98%) of program storage space. Maximum is 30720 bytes. Global variables use 1195 bytes (58%) of dynamic memory, leaving 853 bytes for local variables. Maximum is 2048 bytes.
Need a bigger boat!
D L
so many updates to catch up. I'm so sad that one of my packages from the US was lost and thus all my other tools and materials are held in the customs.
Thanks Rongzhong,
I set the low voltage 'meow' warning to 6.5v, (2 * 3.2v min Li Ion level) by changing the 300 to 450
I have also created a new command to read the voltage dirrectly from the Nybble_v0.2 board.
in Nybble.ino at line561 after the
case 'a': {
PTLF("abort calibration");
for (byte i = 0; i < DOF; i++) {
servoCalibs[i] = servoCalib( i);
}
break;
}
I inserted:
case 'v': { float voltage = analogRead(BATT); Serial.println(voltage/1024 * 5 * 3); break; }
Additionally,
So I could get access to the voltage while Nybble is operating, I updated the Flask API code https://github.com/leukipp/OpenCatWeb with the two following updates:
Update 1: in app.py after line 154, @app.route('/api/status/j/')
def api_status_j():
return jsonify({'status': {'j': serial.write(SerialCommand('j'))}})
I inserted:
@app.route('/api/status/v/') def api_status_v(): return jsonify({'status': {'v': serial.write(SerialCommand('v'))}})
Update 2: in bus.py after line 33,
if '\t' in line:
print(line)
return line.split('\t')
I inserted:
if '.' in line: print(line) return line
Works like a treat. Meows when the voltage is getting low, and I can use the web API to measure the voltage usage as Nybble bounds around.
D L
A0 on Arduino can only accept 5V as max input. The output value should be 1024. There is a voltage divider for A0 so that it can be attached to the battery. So the readings (650 or 300) are relative, not absolute voltages. On V0_2, the reading is about 1/3 of the battery voltage. So 300/1024x5x3=4.5V. That’s lowVoltageThreshold/maxOutput x maxInput x dividerFacotor. It means that when the battery’s voltage is lower than 4.5V, the low voltage warning will be triggered.