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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include <mbed.h>
00002 #include "OneWire_Methods.h"
00003 #include "ds2781.h"
00004 
00005 Serial pc(USBTX, USBRX);
00006 DigitalInOut   one_wire_pin(PC_12);
00007 int VoltageReading, CurrentReading;
00008 float Voltage, Current;
00009 
00010 int main() {
00011 
00012   while(1) {
00013       VoltageReading = ReadVoltage();
00014       Voltage = VoltageReading*0.00976; //Returns the voltage measured at the VIN input of the DS2781      *
00015  *                                      //in units of 9.76mV 
00016       CurrentReading = ReadCurrent();
00017       Current = CurrentReading/6400.0; //Returns the current measured through Rsns external to DS2781 in  *
00018  *                                     //units of 1.5625uV/Rsns. Positive current indicates discharge 
00019       pc.printf("\n\rVoltage = %0.3f, Current= %0.3f", Voltage, Current);
00020   }
00021 }