Skip to content

Commit 370e4c0

Browse files
authored
Merge pull request #4 from sparkfun/release_candidate
v1.0.4
2 parents 2636b0f + 3ea1b9e commit 370e4c0

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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, false); // 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);
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+
delay(250);
57+
}

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.3
2+
version=1.0.4
33
author=SparkFun Electronics
44
maintainer=SparkFun Electronics
55
sentence=Library for the Allegro MicroSystems ACS37800 power monitor IC

src/SparkFun_ACS37800_Arduino_Library.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ ACS37800ERR ACS37800::readRMS(float *vRMS, float *iRMS)
578578
_debugPort->print(F("readRMS: amps (A, before correction) is "));
579579
_debugPort->println(amps);
580580
}
581-
amps /= 27500.0; //Convert from codes to the fraction of ADC Full Scale (15-bit)
581+
amps /= 55000.0; //Convert from codes to the fraction of ADC Full Scale (16-bit)
582582
amps *= _currentSensingRange; //Convert to Amps
583583
if (_printDebug == true)
584584
{

0 commit comments

Comments
 (0)