Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the non-interrupt mode usage
- Loading branch information
Xose Pérez
committed
Nov 8, 2016
1 parent
2767eb1
commit 1dfa68b
Showing
6 changed files
with
130 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <Arduino.h> | ||
#include <LowPower.h> | ||
#include "HLW8012.h" | ||
|
||
#define SERIAL_BAUDRATE 115200 | ||
|
||
// GPIOs | ||
#define SEL_PIN 5 | ||
#define CF1_PIN 13 | ||
#define CF_PIN 14 | ||
|
||
// Set SEL_PIN to HIGH to sample current | ||
// This is the case for Itead's Sonoff POW, where a | ||
// the SEL_PIN drives a transistor that pulls down | ||
// the SEL pin in the HLW8012 when closed | ||
#define CURRENT_MODE HIGH | ||
|
||
// Maximum pulse width, a 2Hz pulse means a precission of ~24W | ||
#define MAX_PULSE_WIDTH 500000 | ||
|
||
HLW8012 hlw8012; | ||
|
||
void setup() { | ||
|
||
// Init serial port and clean garbage | ||
Serial.begin(SERIAL_BAUDRATE); | ||
Serial.println(); | ||
Serial.println(); | ||
|
||
// Initialize HLW8012 | ||
hlw8012.begin(CF_PIN, CF1_PIN, SEL_PIN, CURRENT_MODE, false, MAX_PULSE_WIDTH); | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
// Sleep for 20 seconds | ||
for (unsigned short i = 0; i < 5; i++ ) { | ||
LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); | ||
} | ||
|
||
unsigned long start = millis(); | ||
Serial.print("[HLW] Active Power (W) : "); Serial.println(hlw8012.getActivePower()); | ||
Serial.print("[HLW] Awake for (ms) : "); Serial.println(millis() - start); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters