AS3935 Lightning Detector unable to initialize

As I mentioned before, I have tried multiple resets, different microcontrollers, new wires, different breadboards, etc. I also tried multiple times to run the I2C sketch and re-load the lightning detector sketches with no success. All three of the example sketches seem to exhibit the same error as well, but as I said all three seem to work with the SPI lines un-commented despite being only connected to the I2C pins. I even had one or two of the sketches “detect” lightning with this method, although no lightning or storms were reported in the area. I have tried increasing the delay in the library file to as much as 8, also with no success using the I2C options.

Hi languer.

Just fill out the form on the right hand side of [this page and I’ll get you taken care of. We will need your order number on the form and in the “why do you want a RMA?” section, just include the URL to this page and that will be sufficient.](Return Policy - SparkFun Electronics)

Hi again blazer5154,

That SPI error is something we will need to look into on our end but for your case, I think the best course of action here is to have the board sent back for testing to see if we can figure out what the problem is. Please fill out the form on [this page and in the “Why do you want an RMA?” box, enter a brief description and link to this thread and we will follow up with further instructions.](Return Policy - SparkFun Electronics)

I’ve just set up my AS3935 Lightning Detector for the first time, using the example code with the provided library, and it is returning a message in the serial monitor telling me that the lightning detector did not start up.

I have gone through Sparkfun’s troubleshooting guide, checked all my connections, tried a different board (both Unos), different I2C sensor to make sure the I2C on my boards are fine, different breadboard, reinstalled Arduino to it’s current 1.8.9, cycled through the different I2C addresses in the code, and don’t know what else to try.

Has anyone else had issues with this sensor out of the box, or with the included library?

Hi acampb,

This is a known issue that we are still trying to nail down what the root cause is. The boards I have pulled from our stock to test work just fine so we have not been able to replicate this error yet. In order to try and get more information and reproduce, we are currently having malfunctioning boards sent back to SparkFun for testing. If you purchased the AS3935 Lightning Detector directly from SparkFun, please fill out the form on [this page and in the “Why do you want an RMA?” box, just enter a brief description of the issue and link to this forum post and we will follow up with further instructions on the return process.](Return Policy - SparkFun Electronics)

Received two AS3935 LIGHTNING DETECTOR and when connected to a ARDUINO PRO MINI using i2C i get the error “Lightning Detector did not start up, freezing!”. The board is powered thru the USB connection on the ARDUINO, no external power to Arduino.

I ran i2C scanner and it recognizes the AS3935.

I get the same response from the two boards I received.

I then tried using a SPI connection, commenting out the i2C code and I do not get a error but I have no way to know if the board is working; How can I test the board with no lightning storms around???

Also; could you post the correct way to connect the board for SPI, the tutorial only addresses i2C.

Thanks

Bill

Hi Bill.

We’ve have several reports of folks with this same problem but we have not been able to reproduce it here.

Can you post some photos of the top and bottom of your board and a photo showing how you have the board connected to your Pro Mini?

Sadly, our guide only covers how to use the board in I2C (Qwiic) mode but I’ll put in a request for our tutorials team to add a section on SPI.

Hi Bill.

Give this a try and let me know if it resolves your trouble.

Connect the CS and MISO pins to ground like in this picture:


Let me know if the sensor initializes then.

Connecting MISO and CS to GND did not change anything.

I have the board connected for SPI and it seems to be working; at least its outoutting data to the serial monitor.; “NOISE”, “Disturber” nad “lightning strike detected Approximately XX km away”.

The data is random so it looks like its working.

Attached are pictures of the setup.

I am having the same initialization issue. I tried to hook up as SPI, but got no data output. I am anxiously awaiting the answer for I2C answer.

OK, we’re still looking into what could be causing the issues some customers are having and we will post an update when we have more information.

In the meantime, we did update the library and it would be a good idea to update the IDE with the latest version (v1.2.2) to see if that helps.

The latest version can be downloaded through the library manager, or you can manually download it [here.](GitHub - sparkfun/SparkFun_AS3935_Lightning_Detector_Arduino_Library)

I tried the new library and nothing changed.

I also tried to connect using jumpers instead of the QWIIK cable and again no changes.

SPI seems to be working but need a lightning storm to verify.

Bill

We are aware of the issues associated with the Lightning sensor failing to initialize. We are currently working with the development team associated with the product and are working on a fix.

We are still not entirely sure what the issue is and some of the fixes that have been mention in the threads in this topic are not 100% guaranteed to work, however, we have had some success in-house with the following:

  • 1st, Try an I2C scan and make sure that the lightning sensor is responding with 0x03 indicating that the I2C connection is working.

  • Try pulling MISO and CS to ground. Do not use digital low for this and use the GND line on your controller instead. This may require soldering

  • Try the new [library we had put out and use the specific I2C example. You may also try the SPI example as that has been more consistent and functional as of now.
  • [/list]
  • If using a Qwiic connector system try confirming that the Qwiic cable is making a solid connection with the Qwiic connector on the controller board and lightning sensor
  • You may also try bypassing the Qwiic system altogether and going straight to I2C pins if you think the Qwiic system is suspect, however, if the Qwiic scan returns 0x03 than there is no issues with the Qwiic system.

    If you have tried all of the above and things are still not working, provide a photo of your setup and as much information as possible. We will review it and try to figure what what the next step is.](GitHub - sparkfun/SparkFun_AS3935_Lightning_Detector_Arduino_Library)

    I have already tried all the items in your post.

    Why is the INT output from the LIGHTNING a contant 3.3 v; I thought this only went high when there is lightning… I get the same reading on two different boards and PRO MINI’s and it is the same whether I have i2c or SPI connected.

    @TS-Chris and @TS-John,

    I sent my boards back to you for checking. One thing I noticed one my last tries before I sent them back is that I think the library from PWFusion_AS3935_I2C seemed to communicate with the device. It makes me think there is some timing issue with the I2C library being used. While monitoring with a USB logic analyzer, the SFE library would attempt the communication, would not receive an ACK, and it appeared to quit. The PWFusion library, on the other hand, would miss the first try but on the second try it would receive and ACK and keep moving forward.

    Really strange stuff going on!!!

    I started fresh today and redid the code for SPI using you latest example “Example1_BasicLightning_SPI” and added some of my own minor code revision, attached is sketch"Example1_BasicLightning_SPI_wjl". This is working and I am getting Disturber inputs when I click my BBQ fire starter close to the boards. WOW it looks like its really working. The INT output from the board is zero until I click the BBQ starter.

    /*
      --A basic lightning detector Arduino example sketch--
      Utilizing SPI, this example listens for lightning "events". The IC determines
      whether or not it's actual lightning, disturber, or noise. In the case
      your environment has a lot of noise 
      By: Elias Santistevan
      SparkFun Electronics
      Date: May, 2019
      License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
      Hardware: 
      This is SparkFun's Qwiic Lightning Detector and so is compatible with the Qwiic
      system. You can attach a Qwiic cable or solder to the I-squared-C pins.
      You'll also need a wire attached to the interrupt.  
    */
    
    #include <SPI.h>
    #include <Wire.h>
    #include "SparkFun_AS3935.h"
    
    #define INDOOR 0x12 
    #define OUTDOOR 0xE
    #define LIGHTNING_INT 0x08
    #define DISTURBER_INT 0x04
    #define NOISE_INT 0x01
    
    unsigned long Time;
    unsigned long Time_s;
    unsigned long Time_m;
    unsigned long Time_h;
    
    SparkFun_AS3935 lightning;
    
    // Interrupt pin for lightning detection 
    const int lightningInt = 4; 
    int noiseFloor = 2;
    int spiCS = 10; //SPI chip select pin
    
    // This variable holds the number representing the lightning or non-lightning
    // event issued by the lightning detector. 
    int intVal = 0;
    
    
    
    
    void setup()
    {
      // When lightning is detected the interrupt pin goes HIGH.
      pinMode(lightningInt, INPUT); 
    
      Serial.begin(115200); 
      Serial.println("AS3935 Franklin Lightning Detector"); 
    
      SPI.begin(); 
    
      if( !lightning.beginSPI(spiCS, 2000000) ){ 
        Serial.println ("Lightning Detector did not start up, freezing!"); 
        while(1); 
      }
      else
        Serial.println("Schmow-ZoW, Lightning Detector Ready!");
    
      // The lightning detector defaults to an indoor setting at 
      // the cost of less sensitivity, if you plan on using this outdoors 
      // uncomment the following line:
      lightning.setIndoorOutdoor(OUTDOOR); 
      Serial.println("STARTING");
    }
    
    
    
    
    
    void loop()
    {
       // Hardware has alerted us to an event, now we read the interrupt register
      if(digitalRead(lightningInt) == HIGH){
        intVal = lightning.readInterruptReg();
        if(intVal == NOISE_INT){
          Serial.println("Noise."); 
          //reduceNoise(); //See note below above reduceNoise function.
        }
        else if(intVal == DISTURBER_INT){
          Serial.println("Disturber."); 
        }
        else if(intVal == LIGHTNING_INT){
          Serial.println("Lightning Strike Detected!"); 
          // Lightning! Now how far away is it? Distance estimation takes into
          // account any previously seen events in the last 15 seconds. 
          byte distance = lightning.distanceToStorm();
          byte distance_km = lightning.distanceToStorm();     
          byte distance_mi = distance_km * .62;
          Serial.print("Approximately: "); 
          Serial.print(distance_mi); 
          Serial.println(" miles away!"); 
        }
      }
      delay(100); //Let's not be too crazy.
    }
    
    // This function helps to adjust the sensor to your environment. More
    // environmental noise leads to more false positives. If you see lots of noise
    // events, try increasing the noise threshold with this function. I put the
    // function call under the if statement checking for noise. The datsheet
    // warns that smartphone and smart watch displays, DC-DC converters, and/or
    // anything that operates in 500 kHz range are noise sources to be avoided. 
    void reduceNoise(){
      ++noiseFloor; // Manufacturer's default is 2 with a max of 7. 
      if(noiseFloor > 7){
        Serial.println("Noise floor is at max!"); 
        return;
      }
      Serial.println("Increasing the event threshold.");
      lightning.setNoiseLevel(noiseFloor);  
    }
    
    // This function is similar to the one above in that it will increase the
    // antenna's robustness against false positives. However, this function helps to
    // increase the robustness against "distrubers" and not "noise". If you have a
    // lot of disturbers trying increasing the threshold. The default value is 2 and
    // goes up to 10. You can remove the call to watchdogThreshold() from this
    // function; the function is a demonstrative tool.  
    void changeDisturberThresh(int threshVal){
        lightning.watchdogThreshold(threshVal);  
    }
    

    Now I try to use the example code “Example2_More_lightning_Features” and I configure for SPI; now INT out put is continuous at 3.3VDC. The setup code was exactly the same for both files. I had to copy the setup code from the working sketch and paste it to the Example2 file to get it to work; working sketch attached.

    /*
      A more in depth lightning detector Arduino example sketch. 
      This will guide you through some more of the library's functions that aid in
      reducing false events and noise. 
      By: Elias Santistevan
      SparkFun Electronics
      Date: January, 2019
      License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
      This example listens for lightning events, which are internally determined by
      the IC to be real or false events. 
      Hardware: 
      This is SparkFun's Qwiic Lightning Detector and so is compatible with the Qwiic
      system. You can attach a Qwiic cable or solder to the I-squared-C pins.
      You'll also need a wire attached to the interrupt.  
    */
    #include <SPI.h>
    #include <Wire.h>
    #include "SparkFun_AS3935.h"
    
    #define INDOOR 0x12 
    #define OUTDOOR 0xE
    #define LIGHTNING_INT 0x08
    #define DISTURBER_INT 0x04
    #define NOISE_INT 0x01
    
    unsigned long Time;
    unsigned long Time_s;
    unsigned long Time_m;
    unsigned long Time_h;
    
    SparkFun_AS3935 lightning;
    
    // Interrupt pin for lightning detection 
    const int lightningInt = 4; 
    int spiCS = 10; //SPI chip select pin
    // Values for modifying the IC's detection sensitivity. 
    int noiseFloor = 2;  //changed from byte to int
    int watchDogVal = 2; //changed from byte to int
    int spike = 2;       //changed from byte to int
    
    // This variable holds the number representing the lightning or non-lightning
    // event issued by the lightning detector. 
    int intVal = 0;    //changed from byte to int
    
    void setup()
    {
      // When lightning is detected the interrupt pin goes HIGH.
      pinMode(lightningInt, INPUT); 
    
      Serial.begin(115200); 
      Serial.println("AS3935 Franklin Lightning Detector"); 
    
      SPI.begin(); 
    
      if( !lightning.beginSPI(spiCS, 2000000) ){ 
        Serial.println ("Lightning Detector did not start up, freezing!"); 
        while(1); 
      }
      else
        Serial.println("Schmow-ZoW, Lightning Detector Ready!");
      // "Disturbers" are events that are false lightning events. If you find
      // yourself seeing a lot of disturbers you can have the chip not report those
      // events on the interrupt lines. 
      //lightning.maskDisturber(true); 
    
      // The lightning detector defaults to an indoor setting (less
      // gain/sensitivity), if you plan on using this outdoors 
      // uncomment the following line:
      //lightning.setIndoorOutdoor(OUTDOOR); 
      Serial.println("starting"); 
    }
    
    void loop()
    {
      if(digitalRead(lightningInt) == HIGH){
        // Hardware has alerted us to an event, now we read the interrupt register
        // to see exactly what it is. 
        intVal = lightning.readInterruptReg();
        if(intVal == NOISE_INT){
          Serial.println("Noise."); 
          // reduceNoise();  See note below above function definition.
        }
        else if(intVal == DISTURBER_INT){
          Serial.println("Disturber."); 
        }
        else if(intVal == LIGHTNING_INT){
          Serial.println("Lightning Strike Detected!"); 
          // Lightning! Now how far away is it? Distance estimation takes into
          // account previously seen events. 
          byte distance = lightning.distanceToStorm();
          byte distance_mi = distance * .62;       
          Serial.print("Approximately: "); 
          Serial.print(distance);
          Serial.print("Approximately: "); 
          Serial.print(distance_mi); 
          Serial.println(" miles away!"); 
          // "Lightning Energy" and I do place into quotes intentionally, is a pure
          // number that does not have any physical meaning. 
          //lightEnergy = mylight.lightningEnergy(); 
          //Serial.print("Lightning Energy: "); 
          //Serial.println(lightEnergy); 
    
        }
      }
      delay(100); //Let's not be too crazy.
    }
    
    // This function helps to adjust the sensor to your environment. More
    // environmental noise leads to more false positives. If you see lots of noise
    // events, try increasing the noise threshold with this function. I put the
    // function call under the if statement checking for noise. The datsheet
    // warns that smartphone and smart watch displays, DC-DC converters, and/or
    // anything that operates in 500 kHz range are noise sources to be avoided. 
    void reduceNoise()
    {
      ++noiseFloor; // Manufacturer's default is 2 with a max of 7. 
      if(noiseFloor > 7){
        Serial.println("Noise floor is at max!"); 
        return;
      }
      Serial.println("Increasing the event threshold.");
      lightning.setNoiseLevel(noiseFloor);  
    }
    
    // This function increases the threshold for events that are displayed on the
    // interrupt pin. Increase value means more powerful events will need to occur
    // to be cause the interrupt pin to go high. 
    void increaseWatchdog()
    {
      ++watchDogVal; // Starting at defult for demonstrative purposes and so we'll need to increase value before we write it. 
      if(watchDogVal > 7){
        Serial.println("Watchdog threshold is already at max."); 
        return; 
      }
      lightning.watchdogThreshold(watchDogVal); 
    }
    
    // This function like the watchdog above can help with to tune your detector to
    // more accurate readings. The shape of the pike is analyzed during the chip's
    // validation routine. You can round this spike at the cost of sensitivity to
    // distant events. 
    void dullTheSpike()
    {
      ++spike; 
      if(spike > 11) { 
        Serial.println("Spike reduction is at mask!"); 
        return; 
      }
      lightning.spikeRejection(spike); 
    }
    
    // The following two functions should be called as a pair. If you're powering
    // the IC down, then you should probably wake it up ;). The IC will consume
    // 1-2uA while powered down. 
    void powerICDown()
    {
      Serial.println("Powering down the IC for deep sleep."); 
      lightning.powerDown(); 
    }
    
    void wakeItUP()
    {
      Serial.println("Waking it up!"); 
      if( lightning.wakeUp() ) 
        Serial.println("Successfully woken up!");  
      else 
        Serial.println("Error recalibrating internal osciallator on wake up."); 
    }
    

    Does anyone have a good explanation of what is going on???

    I2C operation is still not working, still waiting for resolution from SPARKFUN.

    Bill

    I am having the same issues and thought I fried the board somehow. I bought another two and the first one is having the same problem–unable to init. I am seeing from these posts that these boards just don’t work. I will try to it again and see if I can make it work.

    I was going to use the board with ESP32 and I see that also did not work and I did not see in the posts that folks were making this work.

    MY board works with SPI but not with I2C using the SPARKFUN library.

    The board works fine with I2c using a library fro FUSION so I suspect tha there is a glitch in the SPARKFUN library.

    New library available on GITHUB, the library is dated May24.

    I tried it and it works fine on I2C

    Thankyou sparkfun for fixing the code; I guess the boards were OK all along.

    Just to closeout my original posts in this thread. After the last update to the AS3935 Sparkfun library, the breakout board is working just fine with the Qwiic system. Thanks to the staff for their awesome support (many thanks to Chris F). And using the Qwiic system with the Blackboard is very flexible because the SDA/SCL lines on the Blackboard support +5V systems, while the Qwiic on the Blackboard supports +3.3V systems. Waiting for a storm to roll by now.