Example of using the DS271 battery monitor on the ESP motor driver board using PC_12 as the OneWire interface (Any other GPIO can be used)

Dependencies:   mbed

Committer:
EmbeddedSam
Date:
Mon Mar 04 14:48:45 2019 +0000
Revision:
0:de50f9a71c22
Initial Commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
EmbeddedSam 0:de50f9a71c22 1 #include <mbed.h>
EmbeddedSam 0:de50f9a71c22 2 #include "OneWire_Methods.h"
EmbeddedSam 0:de50f9a71c22 3 #include "ds2781.h"
EmbeddedSam 0:de50f9a71c22 4
EmbeddedSam 0:de50f9a71c22 5 Serial pc(USBTX, USBRX);
EmbeddedSam 0:de50f9a71c22 6 DigitalInOut one_wire_pin(PC_12);
EmbeddedSam 0:de50f9a71c22 7 int VoltageReading, CurrentReading;
EmbeddedSam 0:de50f9a71c22 8 float Voltage, Current;
EmbeddedSam 0:de50f9a71c22 9
EmbeddedSam 0:de50f9a71c22 10 int main() {
EmbeddedSam 0:de50f9a71c22 11
EmbeddedSam 0:de50f9a71c22 12 while(1) {
EmbeddedSam 0:de50f9a71c22 13 VoltageReading = ReadVoltage();
EmbeddedSam 0:de50f9a71c22 14 Voltage = VoltageReading*0.00976; //Returns the voltage measured at the VIN input of the DS2781 *
EmbeddedSam 0:de50f9a71c22 15 * //in units of 9.76mV
EmbeddedSam 0:de50f9a71c22 16 CurrentReading = ReadCurrent();
EmbeddedSam 0:de50f9a71c22 17 Current = CurrentReading/6400.0; //Returns the current measured through Rsns external to DS2781 in *
EmbeddedSam 0:de50f9a71c22 18 * //units of 1.5625uV/Rsns. Positive current indicates discharge
EmbeddedSam 0:de50f9a71c22 19 pc.printf("\n\rVoltage = %0.3f, Current= %0.3f", Voltage, Current);
EmbeddedSam 0:de50f9a71c22 20 }
EmbeddedSam 0:de50f9a71c22 21 }