diff --git a/examples/Example4_ReadVoltageCurrentRMS/Example4_ReadVoltageCurrentRMS.ino b/examples/Example4_ReadVoltageCurrentRMS/Example4_ReadVoltageCurrentRMS.ino new file mode 100644 index 0000000..70c3a64 --- /dev/null +++ b/examples/Example4_ReadVoltageCurrentRMS/Example4_ReadVoltageCurrentRMS.ino @@ -0,0 +1,57 @@ +/* + Library for the Allegro MicroSystems ACS37800 power monitor IC + By: Paul Clark + SparkFun Electronics + Date: December 4th, 2021 + License: please see LICENSE.md for details + + Feel like supporting our work? Buy a board from SparkFun! + https://www.sparkfun.com/products/17873 +*/ + +#include "SparkFun_ACS37800_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ACS37800 +#include + +ACS37800 mySensor; //Create an object of the ACS37800 class + +void setup() +{ + Serial.begin(115200); + Serial.println(F("ACS37800 Example")); + + Wire.begin(); + + //mySensor.enableDebugging(); // Uncomment this line to print useful debug messages to Serial + + //Initialize sensor using default I2C address + if (mySensor.begin() == false) + { + Serial.print(F("ACS37800 not detected. Check connections and I2C address. Freezing...")); + while (1) + ; // Do nothing more + } + + // From the ACS37800 datasheet: + // CONFIGURING THE DEVICE FOR AC APPLICATIONS : DYNAMIC CALCULATION OF N + // Set bypass_n_en = 0 (default). This setting enables the device to + // dynamically calculate N based off the voltage zero crossings. + mySensor.setBypassNenable(false, false); // Disable bypass_n in shadow memory and eeprom + + // We need to connect the LO pin to the 'low' side of the AC source. + // So we need to set the divider resistance to 4M Ohms (instead of 2M). + mySensor.setDividerRes(4000000); +} + +void loop() +{ + float volts = 0.0; + float amps = 0.0; + + mySensor.readRMS(&volts, &s); // Read the RMS voltage and current + Serial.print(F("Volts: ")); + Serial.print(volts, 2); + Serial.print(F(" Amps: ")); + Serial.println(amps, 2); + + delay(250); +} diff --git a/library.properties b/library.properties index fa79337..2aaff0f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun ACS37800 Power Monitor Arduino Library -version=1.0.3 +version=1.0.4 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC diff --git a/src/SparkFun_ACS37800_Arduino_Library.cpp b/src/SparkFun_ACS37800_Arduino_Library.cpp index 6a62066..3da46b4 100644 --- a/src/SparkFun_ACS37800_Arduino_Library.cpp +++ b/src/SparkFun_ACS37800_Arduino_Library.cpp @@ -578,7 +578,7 @@ ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS) _debugPort->print(F("readRMS: amps (A, before correction) is ")); _debugPort->println(amps); } - amps /= 27500.0; //Convert from codes to the fraction of ADC Full Scale (15-bit) + amps /= 55000.0; //Convert from codes to the fraction of ADC Full Scale (16-bit) amps *= _currentSensingRange; //Convert to Amps if (_printDebug == true) {