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
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.
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:
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:
Update 2: in bus.py after line 33,
if '\t' in line:
print(line)
return line.split('\t')
I inserted:
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
Hi, I can get the voltage to display in Terminal under Arduino IDE, but I can't seem to get voltage display in OpenCatWeb. It just returned couple of lines. What did I
do wrong? Could you help?
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.
Hi RZ,
maybe you could add the Firmata library to Nybble.ino
https://www.arduino.cc/en/Reference/Firmata
With the firmata protocol we would have full access to all IO ports over serial communication.
So there wouldn't be any need for extending and parsing commands on both sides and there are ready to go client libraries for all programming languages:
https://github.com/firmata/protocol
Check it out, maybe it could be a fast and easy approach to extend functionality with very less effort.
Regards,
@leukipp Great tool. I'm curious how much space it would take on the Arduino and whether I'll need to upgrade the ATmega328P before replacing the current code with that library. I want to upgrade ATmega328P to some better chip anyway.
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.
My Nybble.ino (v0.2 plus the extra lines to implement voltage) uses the following:
Need a bigger boat!
D L