Skip to content

Commit

Permalink
Added example sketch to readout the battery stats
Browse files Browse the repository at this point in the history
  • Loading branch information
j54n1n committed Mar 5, 2017
1 parent b513c9d commit d2db7f9
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Motor Core with battery stats readout.
This code for the Arduino Robot's motor board
is the stock firmware with added code printing
the battery status.
*/

#include <TwoWayIntegerEasyTransfer.h>
#include <LottieLemon.h>
#include <SoftwareSerial.h>

enum {
SW_RX = SDA,
SW_TX = SCL
};

SoftwareSerial swSerial{ SW_RX, SW_TX };

LottieLemon::MotorBoard motorBoard;

void setup() {
// start serial communication
swSerial.begin(19200);
// initialize the libraries
Serial1.begin(9600);
TwoWayIntegerEasyTransfer.begin(&Serial1);
TwoWayIntegerEasyTransfer.attach([]() { doSystemReset(); });
doSystemReset();
}

void loop() {
if (TwoWayIntegerEasyTransfer.hasReceivedData()) {
TwoWayIntegerEasyTransfer.processInput();
}
motorBoard.run();

measureBattery();
}

void doSystemReset() {
motorBoard.reset();
}

void measureBattery() {
static String bar; // string for storing the information
static unsigned long tStart = millis();
unsigned long tStop = millis();
if ((tStop - tStart) > 100) {
bar = String(""); // empty the string
// read the sensors and add them to the string
bar = bar + "Vbat=" + motorBoard.getBatteryTerminalVolts() + 'V' +
"\tIcharge=" + motorBoard.getBatteryChargeMilliamps() + "mA" +
"\tIdischarge=" + motorBoard.getBatteryDischargeMilliamps() + "mA";

swSerial.println(bar);
tStart = tStop;
}
}

0 comments on commit d2db7f9

Please sign in to comment.