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)
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 }
Generated on Fri Jul 29 2022 00:12:49 by 1.7.2