-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example sketch to readout the battery stats
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
avr/libraries/LottieLemon/examples/Robot_Motor_Battery_Test/Robot_Motor_Battery_Test.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |