Skip to content
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

Zero Readings #17

Open
Oushi157 opened this issue Aug 3, 2019 · 4 comments
Open

Zero Readings #17

Oushi157 opened this issue Aug 3, 2019 · 4 comments

Comments

@Oushi157
Copy link

Oushi157 commented Aug 3, 2019

I am using the HLW8012 Energy meter module, and have used the HLW8012 Basic.ino from this library. However the readings are always zero for all measurements when the load (12W led bulb) is on. Could this be an issue with reading pulse from the module? Or if anyone has tried this code on the module before.
https://www.electrodragon.com/product/energy-meter-hlw8012-breakout-board/

@Urs-Eppenberger
Copy link

For tests I suggest to use an old light bulb which is a purely resistive load. Or a heater.
The zeroes you get might also be just the fact, that your led bulb only uses current of several mA.

@joshuaboniface
Copy link

Are you trying to use the Interrupt example? I'm finding that this just does not work, nor does calibration. If I use the non-interrupt example it works.

@joshuaboniface
Copy link

joshuaboniface commented Feb 19, 2021

I found that the cause, at least in my case, is that the Interrupt example has not been updated (I presume) for how the newer Arduinos work, and thus interrupts were never firing.

As per the Arduino documentation on the attachInterrupt function, when doing an attachInterrupt, the digital pin ID itself should not be set, as the example does:

  attachInterrupt(CF1_PIN, hlw8012_cf1_interrupt, CHANGE);
  attachInterrupt(CF_PIN, hlw8012_cf_interrupt, CHANGE);

Instead, the digitalPinToInterrupt function should be used to wrap the pin ID, in order to send the proper interrupt:

  attachInterrupt(digitalPinToInterrupt(CF1_PIN), hlw8012_cf1_interrupt, CHANGE);
  attachInterrupt(digitalPinToInterrupt(CF_PIN), hlw8012_cf_interrupt, CHANGE);

This appears to work for me.

Also note that, at least on the Arduino Uno, only digital pins 2 and 3 support interrupts; the full list can be found in the above documentation.

@xoseperez
Copy link
Owner

Thanks @joshuaboniface , I updated the examples with your code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants