Skip to content

Commit 79adb22

Browse files
authored
Merge pull request #7 from sparkfun/release_candidate
v1.0.5
2 parents 370e4c0 + 581b3f6 commit 79adb22

File tree

7 files changed

+284
-21
lines changed

7 files changed

+284
-21
lines changed

examples/Example1_ReadVoltageCurrentPower/Example1_ReadVoltageCurrentPower.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void setup()
4343

4444
void loop()
4545
{
46-
float volts;
47-
float amps;
48-
float watts;
46+
float volts = 0.0;
47+
float amps = 0.0;
48+
float watts = 0.0;
4949

5050
mySensor.readInstantaneous(&volts, &amps, &watts); // Read the instantaneous voltage, current and power
5151
Serial.print(F("Volts: "));

examples/Example4_ReadVoltageCurrentRMS/Example4_ReadVoltageCurrentRMS.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ void setup()
3535
// CONFIGURING THE DEVICE FOR AC APPLICATIONS : DYNAMIC CALCULATION OF N
3636
// Set bypass_n_en = 0 (default). This setting enables the device to
3737
// dynamically calculate N based off the voltage zero crossings.
38-
mySensor.setBypassNenable(false, false); // Disable bypass_n in shadow memory and eeprom
38+
mySensor.setBypassNenable(false, true); // Disable bypass_n in shadow memory and eeprom
3939

4040
// We need to connect the LO pin to the 'low' side of the AC source.
4141
// So we need to set the divider resistance to 4M Ohms (instead of 2M).
42-
mySensor.setDividerRes(4000000);
42+
mySensor.setDividerRes(4000000); // Comment this line if you are using GND to measure the 'low' side of the AC voltage
4343
}
4444

4545
void loop()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
Library for the Allegro MicroSystems ACS37800 power monitor IC
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: December 4th, 2021
6+
License: please see LICENSE.md for details
7+
8+
Feel like supporting our work? Buy a board from SparkFun!
9+
https://www.sparkfun.com/products/17873
10+
*/
11+
12+
#include "SparkFun_ACS37800_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_ACS37800
13+
#include <Wire.h>
14+
15+
ACS37800 mySensor; //Create an object of the ACS37800 class
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println(F("ACS37800 Example"));
21+
22+
Wire.begin();
23+
24+
//mySensor.enableDebugging(); // Uncomment this line to print useful debug messages to Serial
25+
26+
//Initialize sensor using default I2C address
27+
if (mySensor.begin() == false)
28+
{
29+
Serial.print(F("ACS37800 not detected. Check connections and I2C address. Freezing..."));
30+
while (1)
31+
; // Do nothing more
32+
}
33+
34+
// From the ACS37800 datasheet:
35+
// CONFIGURING THE DEVICE FOR AC APPLICATIONS : DYNAMIC CALCULATION OF N
36+
// Set bypass_n_en = 0 (default). This setting enables the device to
37+
// dynamically calculate N based off the voltage zero crossings.
38+
mySensor.setBypassNenable(false, true); // Disable bypass_n in shadow memory and eeprom
39+
40+
// We need to connect the LO pin to the 'low' side of the AC source.
41+
// So we need to set the divider resistance to 4M Ohms (instead of 2M).
42+
mySensor.setDividerRes(4000000); // Comment this line if you are using GND to measure the 'low' side of the AC voltage
43+
}
44+
45+
void loop()
46+
{
47+
float volts = 0.0;
48+
float amps = 0.0;
49+
50+
mySensor.readRMS(&volts, &amps); // Read the RMS voltage and current
51+
Serial.print(F("Volts: "));
52+
Serial.print(volts, 2);
53+
Serial.print(F(" Amps: "));
54+
Serial.println(amps, 2);
55+
56+
float pactive = 0.0;
57+
float preactive = 0.0;
58+
59+
mySensor.readPowerActiveReactive(&pactive, &preactive); // Read the active and reactive power
60+
Serial.print(F("Power: Active (W): "));
61+
Serial.print(pactive, 2);
62+
Serial.print(F(" Reactive (VAR): "));
63+
Serial.println(preactive, 2);
64+
65+
float papparent = 0.0;
66+
float pfactor = 0.0;
67+
bool posangle = 0;
68+
bool pospf = 0;
69+
70+
mySensor.readPowerFactor(&papparent, &pfactor, &posangle, &pospf); // Read the apparent power and the power factor
71+
Serial.print(F("Power: Apparent (VA): "));
72+
Serial.print(papparent, 2);
73+
Serial.print(F(" Power Factor: "));
74+
Serial.print(pfactor, 2);
75+
if (posangle)
76+
Serial.print(F(" Lagging"));
77+
else
78+
Serial.print(F(" Leading"));
79+
if (pospf)
80+
Serial.println(F(" Consumed"));
81+
else
82+
Serial.println(F(" Generated"));
83+
84+
delay(250);
85+
}

keywords.txt

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ setBypassNenable KEYWORD2
4040
getBypassNenable KEYWORD2
4141
getCurrentCoarseGain KEYWORD2
4242
readRMS KEYWORD2
43+
readPowerActiveReactive KEYWORD2
44+
readPowerFactor KEYWORD2
4345
readInstantaneous KEYWORD2
4446
readErrorFlags KEYWORD2
4547
setSenseRes KEYWORD2

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun ACS37800 Power Monitor Arduino Library
2-
version=1.0.4
2+
version=1.0.5
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC

0 commit comments

Comments
 (0)