AS3935 Lightning sensor library

Dependents:   zeus

Fork of AS3935 by valentin spanu

include the mbed library with this snippet

#include "mbed.h"
#include "AS3935.h"

 // frdm-kl25z sd card connections for spi1 
 // ------------------------------------------------
 // Header -- kl25z -- SD/MMC          
 // J2-20  -- PTE1  -- MOSI
 // J9-13  -- PTE4  -- CS
 // J2-14  -- GND   -- Vss (GND) 
 // J9-9   -- PTE2  -- SCK
 // J9-11  -- PTE3  -- MISO
 
AS3935 ld(PTE1, PTE3, PTE2, PTE4, "ld", 100000); // MOSI, MISO, SCK, CS, SPI bus freq (hz) 
InterruptIn IntLightning(PTA12); //IRQ AS3935
DigitalOut led1(LED_RED);
Serial pc(USBTX, USBRX);

void DetectLightning()
{
    char OriginInt;
     wait_ms(2); 
    OriginInt = ld.interruptSource();
    if (OriginInt == 1) { //
        pc.printf(" Noise level too high\r\n");
        }
    if (OriginInt == 4) { //
        pc.printf(" Disturber\r\n");
        }
    if (OriginInt == 8) { // detection
        // pc.printf(" Lightning detection\r\n");
        pc.printf(" Lightning detection, distance=%dkm\r\n", ld.lightningDistanceKm());
        ld.clearStats();

        }
}

 
int main() {
    pc.baud(9600);
    pc.printf("\r\nstart lightning detector\r\n");
    
    //initialisations
    ld.reset();
    ld.setTuneCap(5); // 500kHz
    ld.powerUp();
    ld.setIndoors();  
    ld.setMinimumLightnings(1);
    //ld.setSpikeRejection(2);
    ld.setNoiseFloor(2);
    ld.disableDisturbers();
    //ld.enableDisturbers();
    ld.setWatchdogThreshold(2);
    wait_ms(10);
    IntLightning.rise(&DetectLightning);
    int MinBlysk = ld.getMinimumLightnings();
    int Noise = ld.getNoiseFloor();
    int TuneCap = ld.getTuneCap();
    int SpikeRej = ld.getSpikeRejection();
    int WatchDog = ld.getWatchdogThreshold();
     
    pc.printf(" Min wylad: %i", MinBlysk);
    pc.printf("\r\n");
    pc.printf(" Noise: %i", Noise);
    pc.printf("\r\n");
    pc.printf(" Tune CAP: %i", TuneCap);
    pc.printf("\r\n");
    pc.printf(" Spike rej: %i", SpikeRej);
    pc.printf("\r\n");
    pc.printf(" Watchdog: %i", WatchDog);
    pc.printf("\r\n");
    while(1) {
        led1 = ! led1;
        wait(0.2);
     }
    
 
 }

Changes

RevisionDateWhoCommit message
15:afbf7ba667e7 2015-12-14 cmkachur Read energy registers per the data sheet. default tip
14:8e5f2cf08318 2015-09-22 cmkachur Add defines for events.
13:e180d3e79c58 2015-06-30 cmkachur Fix the define value for indoor mode to match the data sheet.
12:ac6ba62a31c6 2015-06-24 cmkachur Tune the antenna before calibrating the RCO per the data sheet. The calibrateRCO() method was modified to not overwrite the value of the tuning capacitor from the antenna tune method.
11:ee2e7a573227 2015-06-24 cmkachur Store all configuration register values and firmware version to config_data.csv file at startup. Delete obsolete code.
10:bf33e2946bab 2015-06-23 cmkachur Add method for reading energy of lightning strike. Add energy data to the log file. Remove call to powerUp() since this was only setting outdoor mode which was done elsewhere.
9:19a323b1c508 2015-06-18 cmkachur Update calibrate RCO method. Measure the TRC oscillator.
8:60e1b6b39e1c 2015-06-17 cmkachur Merge with tuneAntenna() method.
7:0d2586164d5b 2015-06-17 cmkachur Add tuneAntenna() method to the as3935 class.
6:c9b9e7d3bced 2015-06-16 ftagius add routine to get gain setting; change value for indoor setting
5:28311803e23d 2015-06-15 ftagius add init sequence obtained from acurite;
4:ab1f1b65468b 2015-06-15 ftagius Add functions from the as3935 demo source code
3:c536a9aa2a1c 2015-06-11 ftagius fix spi bus frequency init
2:3b3b435ca8d9 2015-06-11 ftagius code cleanup
1:f2d9ed33c276 2015-06-11 ftagius Convert AS3935 library to SPI
0:346c723cac97 2014-04-05 casper First release