SparkFun AS3935 Lightning Detector Hookup Guide (v20)

Pages
Contributors: Elias The Sparkiest
Favorited Favorite 2

Example 2 - More Lightning Sensor Features SPI

In the following example we'll explore some of the other features available to you from the SparkFun Lightning Detector Arduino Library. This example actually functions exactly as the example above in that it monitors for a lightning event in the main loop; so we'll focus on the setup to see how it demonstrates different settings that you can set.

At the top we have a few more variable for a number of settings. The first two noiseFloor and watchDogVal holds the values for increasing the Lightning Detector's robustness against noise and false lightning events respectively. The following variable spike holds a value to further increase the robustness of the SparkFun Lightning Detector towards false events. Finally lightningThresh holds the value for the number of lightning events that need to occur before the SparkFun Lightning Detector alerts you.

language:c
// Values for modifying the IC's settings. All of these values are set to their
// default values. 
byte noiseFloor = 2;
byte watchDogVal = 2;
byte spike = 2;
byte lightningThresh = 1; 

The first function call lightning.maskDisturber(true) will stop the Lightning Detector from alerting you to any false events at all. We check that the setting was set correctly with lightning.readMaskDisturber()

language:c
lightning.maskDisturber(true); 

int maskVal = lightning.readMaskDisturber();
Serial.print("Are disturbers being masked: "); 
if (maskVal == 1)
    Serial.println("YES"); 
else if (maskVal == 0)
    Serial.println("NO"); 

The next two function calls increase the SparkFun Lightning Detector's robustness to noise with lightning.setNoiseLevel() and false lightning events with lightning.watchdogThreshold(). We give these function the values in the variables mentioned above: noiseFloor and watchDogVal. Just below each of these respective functions are functions that read back the settings we just set: lightning.readNoiseLevel() and lightning.readWatchdogThreshold().

language:c
lightning.setNoiseLevel(noiseFloor);  

int noiseVal = lightning.readNoiseLevel();
Serial.print("Noise Level is set at: ");
Serial.println(noiseVal);

// Watchdog threshold setting can be from 1-10, one being the lowest. Default setting is
// two. If you need to check the setting, the corresponding function for
// reading the function follows.    

lightning.watchdogThreshold(watchDogVal); 

int watchVal = lightning.readWatchdogThreshold();
Serial.print("Watchdog Threshold is set to: ");
Serial.println(watchVal);

The next setting is a bit light on details in the datasheet but helps to increase the SparkFun Lightning Detector's ability to reject false positives by reducing the spike that is analyzed by the validation routine within the Lightning Detector. This will make the lightning detector less sensitive.

language:c
// Spike Rejection setting from 1-11, one being the lowest. Default setting is
// two. If you need to check the setting, the corresponding function for
// reading the function follows.    
// The shape of the spike is analyzed during the chip's
// validation routine. You can round this spike at the cost of sensitivity to
// distant events. 

lightning.spikeRejection(spike); 

int spikeVal = lightning.readSpikeRejection();
Serial.print("Spike Rejection is set to: ");
Serial.println(spikeVal);

The lightning.lightningThreshold() function makes it possible to increase the number of lightning strikes that the lightning detector senses before it issues an interrupt. Possible settings are 1, 5, 9 , or 16 lightning strikes.

language:c
// This setting will change when the lightning detector issues an interrupt.
// For example you will only get an interrupt after five lightning strikes
// instead of one. Default is one, and it takes settings of 1, 5, 9 and 16.   
// Followed by its corresponding read function. Default is zero. 

lightning.lightningThreshold(lightningThresh); 

uint8_t lightVal = lightning.readLightningThreshold();
Serial.print("The number of strikes before interrupt is triggerd: "); 
Serial.println(lightVal); 

Did you set too many settings and just want to get it back to default settings? Then the function lightning.resetSettings() will do just that.

As mentioned above this example code does exactly the same as the first example above but offers more settings to tailor your SparkFun Lightning Detector to your project.