Skip to content

v1.0.5 #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ void setup()

void loop()
{
float volts;
float amps;
float watts;
float volts = 0.0;
float amps = 0.0;
float watts = 0.0;

mySensor.readInstantaneous(&volts, &amps, &watts); // Read the instantaneous voltage, current and power
Serial.print(F("Volts: "));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ void setup()
// 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
mySensor.setBypassNenable(false, true); // 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);
mySensor.setDividerRes(4000000); // Comment this line if you are using GND to measure the 'low' side of the AC voltage
}

void loop()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
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 <Wire.h>

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, true); // 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); // Comment this line if you are using GND to measure the 'low' side of the AC voltage
}

void loop()
{
float volts = 0.0;
float amps = 0.0;

mySensor.readRMS(&volts, &amps); // Read the RMS voltage and current
Serial.print(F("Volts: "));
Serial.print(volts, 2);
Serial.print(F(" Amps: "));
Serial.println(amps, 2);

float pactive = 0.0;
float preactive = 0.0;

mySensor.readPowerActiveReactive(&pactive, &preactive); // Read the active and reactive power
Serial.print(F("Power: Active (W): "));
Serial.print(pactive, 2);
Serial.print(F(" Reactive (VAR): "));
Serial.println(preactive, 2);

float papparent = 0.0;
float pfactor = 0.0;
bool posangle = 0;
bool pospf = 0;

mySensor.readPowerFactor(&papparent, &pfactor, &posangle, &pospf); // Read the apparent power and the power factor
Serial.print(F("Power: Apparent (VA): "));
Serial.print(papparent, 2);
Serial.print(F(" Power Factor: "));
Serial.print(pfactor, 2);
if (posangle)
Serial.print(F(" Lagging"));
else
Serial.print(F(" Leading"));
if (pospf)
Serial.println(F(" Consumed"));
else
Serial.println(F(" Generated"));

delay(250);
}
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ setBypassNenable KEYWORD2
getBypassNenable KEYWORD2
getCurrentCoarseGain KEYWORD2
readRMS KEYWORD2
readPowerActiveReactive KEYWORD2
readPowerFactor KEYWORD2
readInstantaneous KEYWORD2
readErrorFlags KEYWORD2
setSenseRes KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun ACS37800 Power Monitor Arduino Library
version=1.0.4
version=1.0.5
author=SparkFun Electronics
maintainer=SparkFun Electronics
sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC
Expand Down
Loading