Seems to me that the code for getting the lighting energy value is in error.
First off the bottom 5 bits of MMSBYTE are masked with 0xF using the constant ENERGY_MASK, but should be 0x1F to get 5 bits.
Second these bits should only be shifted up 8 bits in the long variable _purelight the first time, not 16 as coded. They will eventually be shifted the correct 16 bits by the second 8 bit shift.
Hello!
I’m the engineer that wrote the library and at first glance I can confirm these issues with the library. I have not implemented a fix just yet but have filed an issue here on Github:
https://github.com/sparkfun/SparkFun_AS … /issues/14
I’ll respond here again when the issue is fixed in the next few days.
Thanks.
These are not errors, but suggestions:
-
The chip allows the AFE Gain to be set to values other than just INDOOR and OUTDOOR. At the moment I’m not sure of the valid upper range, but I notice you only allow the two values INDOOR and OUTDOOR. It might be useful to just take the value screening out of the setIndoorOutdoor function to allow more continuous settings.
-
This is probably a typo in the data sheet, but in the Interrupt Management section it says the chip might issue an interrupt with register =000 when the distance estimation changes. So in addition to noise, disturber, and lightning; there might be a fourth type interrupt. I’ve never actually seen it so far, but I have seen 0010 but don’t know what it indicates.
Thanks for the suggestions, I’ll add that into my list of things to take a look at. I’m a bit busy so I won’t get a chance to look at these anytime soon. If you’re feeling like it, a pull request would help me greatly. Otherwise the mistake in your original post has been corrected.
Thanks.
Just to follow up:
There is definitely a type 0 interrupt! It generally occurs after a storm has passed. It represents an update to the distance but not the result of a lightning strike.
The best way to handle adding more variable AFE gain would be to create a separate function and leave setIndoorOutdoor as is.