pcfens / RaspberryPi-AS3935

A basic library for working with the AS3935 that's connected to the Raspberry Pi.
Other
52 stars 24 forks source link

Possible Calibration Issue? #3

Closed lkomage closed 11 years ago

lkomage commented 11 years ago

Just got the mod-1016 AS3935 module from Embedded Adventures. Found your code through Google (Thanks!), followed your readme, and was successfully running your code. Then I started looking through your AS3935 routines, and noticed something that doesn't agree with the documentation I got from Embedded Adventures. Here's what they say about calibration: "These are the steps you need to take to start using the MOD-1016. Your MOD-1016 comes pre-calibrated–meaning you don’t need to worry about measuring frequencies and checking results. Wait a few milliseconds for the system to stabilise. Set the tune capacitor to the value indicated on the packaging, by setting the TUNE_CAP bits of register 8. Wait 2 milliseconds. Calibrate RCO by: Sending a calibrate RCO direct command (set memory location 0x3d to the value 0x96). Set Register 0x08, bit 5 to 1. Wait 2 milliseconds. Set Register 0x08, bit 5 to 0."

This is almost what you do, but you don't seed the TUNE_CAP bits with the value on the packaging, and the calibrate RCO direct command should be location 0x3D. I've modified your code to follow their instructions, and it still appears to work, although I've had no storms come through lately to verify this!

Was there some reason you're doing calibration differently, or should I shoot you a copy of my changes as a fix? Thanks again for providing an easy way to get this lightning module working with the Raspberry Pi! I look forward to adding lightning detection to my home weather station!

pcfens commented 11 years ago

This was indeed a mistake. I'm kind of surprised nobody has caught it yet.

I've pushed a proposed bugfix to the dev branch. Could you test it out and let me know if that fixes the issue?

The included demo code won't take full advantage of this since it doesn't use the new second argument to the calibrate method right now. If the bugfix works then I'll update the demo code and merge everything to master.

lkomage commented 11 years ago

Guess lightning sensors has a limited audience thus far. I'll admit that my original plan was to peruse the Embedded Adventures docs and the AS3935 docs, and sit down and write my own code. But something made me see if I would be re-inventing the wheel, so I googled and your library popped right up.

This is finally making me learn how to use git; I need to catch up with the times from cvs and subversion. I tested your fix, adjusting lightning.py to reflect the tune value of my board, and everything works as good as it did before. Still no storms here to test further with, but I do know it is aware of noise and disturbers, reacting appropriately.

Your fix was pretty much what I did, with the only exception being I made sure there wasn't any pre-existing value in TUNE_CAP before or-ing in my value -- don't know if that's paranoia or thoroughness on my part.

In any case, looks like the bugfix works! And thanks again!

pcfens commented 11 years ago

How about the latest patch? I like the idea of making sure it's blank first better than what I came up with.

lkomage commented 11 years ago

Won't be able to run it till tomorrow evening, got to rest up for my day job, heh-heh. But I did look at the change online and it looks like what I did, so it should be fine.

lkomage commented 11 years ago

Ok, checked out the latest dev code, and it looks and works fine to me. Now all I need is a storm wander by to really test this thing out!