AS3935 details

After a very frustrating weekend, I am pretty confident I have the worst of the integration problems behind me. The Embedded Adventures board is a very nice board but did take the choice of SPI or I2C out of my hands. It was designed to be I2C only. Not a problem. The Arduino does I2C.

So I hooked up the break out board to my Arduino UNO and started to write some basic “Wire Library” code. How hard could this be? Well after the first day, I would say pretty hard. Turns out the AS3935 has some pretty stringent demands for reading and writing registers. Mostly, when turning around the bus, you must use a “Repeated Start” and not a more normal Stop and Start sequence. After I figured that out, I was able to realize that the Wire library does support that, but not in so many words. After Day one, I at least was getting some ACKs from the device address part of the bus transfer.

After day two, I was able to read and write most registers except register 0x00. This one kept giving me a NAK when I sent over the device address for the read after I had sent over the register address in the write part of the transaction. Much aggravation because sometimes it would work and other times not.

In the mean time, I have exchanged numerous emails with the Embedded Adventures people in the UK. They must never sleep and take days off over there because I was getting very fast turn arounds on the questions I was asking. The upshot is that they had issues as well with register 0x00. So with that in mind, I did a careful survey of the issue and discovered what must be an “undocumented feature”. Reading register 0x00 will always NAK you till such time as you read a different register. After that you can read and write any and all legal registers. I have sent out yet another email to the AMS people in Austria asking them about this issue and any other errata they might like to share.

At the end of day three with the low level communication finished, I was able to get the unit to self calibrate and to sit in listen mode. Further more, I was able to get it to respond with “disturber (not lightning)” reports when I generated sparks in the area. Without the awfully expensive lightning simulator from AMS, I will now have to sit around and wait for a storm. That might be many months from now.

But now with this off my plate (its been a running project for more than two years) I can get back to the AVC. Just so happens that I got two thermo electric coolers in the mail over the weekend just waiting to try to temperature stabilize the IMU and to characterize it for hard and soft magnetic properties.

This entry was posted in Arduino, AS3935, AVC, Components, Lightning detector, Pololu 9DOF IMU, Processors, Projects. Bookmark the permalink.

64 Responses to AS3935 details

  1. John says:

    AS3935

    Hey Skye,
    i am working on the AS3935 as a final year project and im using the 18f448 and I2C. I have no problem reading and writing to the registers but i am getting a problem reading back from the AS3935 on the IRQ pin to display the frequency of the antenna. I have a signal GEN set up sending a low amplitude with a 500kHz frequency into the AS3935 but when reading this on the IRQ pin im getting a load of rubbish.
    I was just wondering also what is the baud rate for the AS3935 i was thinking that could be my problem either.
    Any help would be great after getting bogged down in this the last few days.
    Cheers John

    • Skye Sweeney says:

      John,
      Glad someone else is using this chip! What may I ask is the goal of your project?

      Not sure sending in a signal into the AS is going to work. The antenna is an R-C-L circuit that is excited by what I would image is a multivibrator/oscillator inside the chip. Driving a signal into the chip is opposite from what the chip is trying to do and send a signal out. I would not be at all surprised that it is confused! Have you tried an antenna circuit like the one in the reference design?

      As for the bit rate, I am not sure at this moment. I am using whatever the Arduino support for it’s fastest speed. Will get back on that when I can take a measurement. But that is an interesting idea that I might be driving the clock too fast. Of course if the chip was designed right (not sure it was!) it would implement clock stretching and the speed issue would be moot.

      Have you not experienced a problem trying to read register 0 before any other register and gotten a transfer failure? If not, that would point a finger more in my direction than at the chip. Of course there still is NO excuse for the idiocy of having to wait 2ms after the interrupt before you can read the interrupt status register.

  2. John says:

    Hey Skye,
    Thanks for getting back to me.
    The goal of my project is to just build a circuit using the AS3935 and getting it communicating with the 18f448 and displaying the info on a LCD and maybe a contractor or something to simulate shutting down a power supply and having a back up or something along those lines .
    I done a nice bit of research on the NET the last day or two and i think one of my biggest problems is that i wasn’t using the right inductor for the antenna. When i set the LCO in register 8 (bit 7) i should get the resonance frequency out on the IRQ pin but i just cant seem to get it out for some reason would not having the right inductor make that much of a difference or what type did you use?. I have one ordered on line and should get it in the next few days so hopefully that sorts my problem otherwise i must have a problem in my c code.

    I purchased a made board from Embedded Adventures. It had the proper L and C values on it already.

    • Skye Sweeney says:

      The inductor, and capacitors on the antenna circuit are likely to need fairly close values. It forms an oscillation circuit. It gets adjusted by the capacitor values in Reg8. But if you change the values of the external L or C too much, I suspect the oscillator will not oscillate. Think about the motion you need to get the water in your bathtub to slosh. Now that same motion in the ocean (different LC values) is not going to do very much at all!

  3. Angelo Matta says:

    Hello Skye,

    I’m working on a project with the AS3935 with a plate that I purchased in tautic.com,i use the arduino mega2560 and i use the library available, but is responding me with much noise and response:

    Tuning out of range, check your wiring, and make sure your sensor physics laws have not changed!
    Noise floor is: 2
    Spike rejection is: 2
    Watchdog threshold is: 2
    Noise level too high, try adjusting noise floor
    Noise level too high, try adjusting noise floor
    Noise level too high, try adjusting noise floor
    Noise level too high, try adjusting noise floor

    You have some other progam, which tested in arduino and it worked?
    Angelo Matta

    • Skye Sweeney says:

      The Tautic break out board is SPI based. The one I use is I2C. The code I have would be of little use to you.

      The advice I would give you is to make sure that you have tuned the antenna properly. You need to set the bit in register 8 to send what should be a 500kHz square wave to the interrupt pin. You then need to measure this frequency and adjust the tuning bits in register 8 to find the best value to get as close to 500kHz as possible.

      Once this is done, you should start to see interrupts occurring every second or two, but the reason would a “disturber” not a strike. Disturbers are other source of magnetic noise like relays, switches, motors, that may be within range of the sensor. In my lab, every time the furnace turns on, I get an interrupt. Each time the scope switches modes and the relays inside switch, I get an interrupt.

      Now if you are getting many more interrupts, than either the antenna gain is too high or the noise floor is too low. This you will need to play around with till you get it right.

    • I too, have AS3935/Arduino setup. I see similar when starting up, so I added a second reset/calibrate and adjusted the noise floor to 3. The second calibrate has never failed. Here in Florida, we have lots of lightning, and I get lightning detection to about 30km. So, I know its working, though, I am still tuning and adjusting. (The tiny antenna does show directional properties.)

      The delay()’s here may not be needed, but I use it for my testing.

      if(!AS3935.calibrate())
      {
      Serial.println(“Tuning out of range, retrying…”);
      delay(1000);
      AS3935.reset();
      delay(1000);
      if(!AS3935.calibrate())
      {
      Serial.println(“Rats, Still out of range…”);
      delay(1000);
      }
      else
      {
      Serial.println(“Success tuning”);
      delay(1000);
      }
      }
      Serial.println(“Continuing setup…”);

  4. Angelo Matta says:

    Hello Skye,
    thanks for the reply, tell me where you he bought the plate with i2c output? You can send me the arduino program to I2c?

    thank you,
    Angelo

  5. I’ve also got the tautic board and it does occasionally see a lightning hit (it’s storming right now thats why i’m playing with it) but not reliably and I also get the noise floor is too high warning with every startup regardless of the setting of the noise floor. I gather since there are 3 bits in it’s register that you can set it from 0 to 7? the library has a calibrate function that tries to tune it to 31250Hz, but you mention 500kHz? That tautic board can do I2C so we could alter it to use your library I think. But I really dont get a good picture of how to properly use the chip from it’s data sheet.

    • Skye Sweeney says:

      The frequency of the antenna needs to be 500kHz. You can arrange the output to be sent out the interrupt pin so your micro can measure the rate and then tune to capacitor bank till you get the best value. The confusion is that there is a register on the AS3935 that will divide down the antenna frequency before it goes to the interrupt pin. The 31250Hz is 500kHz after a divide by 16.

      I will try to post my current code tonight for those that are interested.

  6. Angelo Matta says:

    Hello Skye,

    I tested the code I2C in arduino and worked with the boarding TAUTIC, seeing the instructions and it worked ….

    Angelo

  7. Angelo Matta says:

    I did not quite understand the code that you posted, but joined parts of codes, the board of tautic, I followed the manufacturer’s recommendations chip as3935 and did the following:
    MISO ==> GND
    CS ==> GND
    SI ==> 3.3V
    SCLK ==> 10K PULL UP ==> A5 ARDUINO
    MOSI ==> A4 ARDUINO
    IRQ ==> D2 ARDUINO

    for initial testing I used the Arduino Duemilanove and the Arduino UNO also tested.

    if you want I can send email, the final program …

    Angelo

    • Skye Sweeney says:

      Not sure I understand your post. You seem to have wired the Tautic for I2C and loaded the code I posted. Did it work? If not, what problems are you having? If it did work, but you make changes, I would like to have the changes for possible improvement to my code. You could send them to “Skye at fll-freak dot com”.

  8. DaveH says:

    I have been trying for 10 days to get either version of code to work. I have wired it both ways an I have a Arduino 2009 with embedded solutions breakout. The other code compiles and uploads but is giving the exact errors above. I would much rather get striker to work but I can’t get past a compile error. Very frustrating to me.
    It gives me a not declared error ever time it sees, “as3935_err”
    I am not a true software guy but have been doing this enough to get most sketches to run after a tweak. Not this time. I like this code due to the lights and whistles. Did I set up something wrong? Is there a certain way I should set up the library to use the spi, mytypes etc. I am stumped but is this a faux path on my part.

    • Skye Sweeney says:

      DaveH,
      I am not sure what two versions of the code you are talking about. I assume one version is the Striker code I put on GitHub. Is this the one giving you the problems with as3935_err? I would be happy to help you get going, but I need to know what your starting point is.

      The Arduino IDE is a bit fussy. You need to put all the project files into one directory that has the same name as the principle INO file name. When you bring up the IDE and open the principle INO file, it should scan the directory and add tabs for all the other files.

      You should go to https://github.com/SkyeSweeney/Striker and click on the “Zip”. Save the Striker-master.zip file and then decompress to get the Striker-master directory. Now the Striker-master directory has a directory of the same name inside it. The inside directory should be renamed to Striker and moved into your Arduino Projects directory. Now open the IDO and open the Striker.ino file. This should compile. If not, please capture the errors from the compiler and post them for me to look at.

      • DaveH says:

        Thank you for response. in fact it is the github zip. i tried again following instructions carefully and i get the same error.

        I took off the over head for this post my comments are noted with a ** First the # include statements then the first of many errors is noted by me.
        *********************************************************************/
        #include ** lights up brown
        #include “MyTypes.h” ** lights up all blue”
        #include “as3935.h” ** same blue”
        #include “I2C.h” ** same blue”
        #include “I2cMaster.h” ** same blue”

        /* Helpful conversions */
        #define SEC_TO_MS (1000L)
        #define MIN_TO_MS (1000L*60L)
        #define HR_TO_MS (1000L*60L*60L)

        /* Pins used for I2C */
        #define SDA_PIN A4
        #define SCL_PIN A5

        #define STRIKE_PIN 4 /* Pin used for strike generator */
        #define ALARM_PIN 5 /* Pin used for an audio alarm */
        #define LED_PIN 6 /* Pin used for an LED alarm */
        #define SILENCE_PIN 7 /* Pin used for an alarm silence alarm */

        /* Delay needed from INT to reading ISR */
        #define ISR_DELAY (3)

        /**********************************************************************
        *
        * Global data
        *
        *********************************************************************/
        volatile INT32U counter = 0; /* ISR counter */
        volatile INT8U isrFlag = 0; /* Normal ISR flag */
        volatile INT32U bitCnt = 0; /* BIT ISR counter */
        INT32U calTime = 0; /* Time to do the next calibration */
        INT32U bitTime = 0; /* Time to do the next BIT */
        INT32U ledTime = 0; /* Time to turn off the LED */
        INT32U alarmTime = 0; /* Time to turn off the alarm */
        INT32U silenceTime = 0; /* Time to turn off the alarm */
        bool silence = false;

        SoftI2cMaster si2c(SDA_PIN, SCL_PIN); /* Bit-Bang I2C */

        INT16 determineDistance(INT8U val);

        /**********************************************************************
        *
        * Setup routine
        *
        *********************************************************************/
        void setup(void) {
        REG_u reg;
        INT8U err;
        INT32U now;
        INT8U thres;
        INT8U val;

        /* Open serial port */
        Serial.begin(115200);

        /* Indicate we started */
        Serial.println(“Striker starting”);

        /* Configure lightning simulator control pin */
        pinMode(STRIKE_PIN, OUTPUT);
        digitalWrite(STRIKE_PIN, LOW);

        /* Configure audio alarm pin */
        pinMode(ALARM_PIN, OUTPUT);
        digitalWrite(ALARM_PIN, LOW);

        /* Configure LED alarm pin */
        pinMode(LED_PIN, OUTPUT);
        digitalWrite(LED_PIN, LOW);

        /* Configure alarm silence switch input pin */
        pinMode(SILENCE_PIN, INPUT);
        digitalWrite(SILENCE_PIN, HIGH); /* enable pullup */

        /* Attach the normal ISR */
        attachInterrupt(0, normalIsr, RISING);

        /* Set unit into operation mode */
        as3935_err(as3935_set_powerdown(0), “pwron”); ** first error here**

        i left off the code from here down but it errors on every occurrence of “as3935_err (xxxxxxxxxxxxxx);

        i could not copy and paste but it is like this:
        Striker.ino: In function ‘void setup();
        Striker:163 error: ‘as3935_err’ was not declared in this scope.
        it does this for line 163, 214,218,280,379,400,466,578 and 591.
        in my sketchbook directory i put an unzipped renamed Striker directory. it loads great but wont compile. i think the clue is it id not loading the .h library file as i noted they are a wrong color.
        thanks again,
        Dave

        • DaveH says:

          I got it to compile after much doing the same thing over and over.
          no further help on this compile issue is anticipated.
          thanks so much again and again.
          you have a favorite fan.
          Dave

  9. DaveH says:

    there seems to be another error but i’ll work it. will not tune, result = 1250 and every register dump is = FF
    i have 5 v, gnd, irq to D2, SDA to 4 w 2.2k to 5 volt, and SCL to 5 with 2.2 k to 5 v.
    CS and MISO left open.
    d

  10. DaveH says:

    i need to check addressing, they have 2 versions and the are 00 or 03 depending on rev level.
    i’ll let you know.
    d

  11. DaveH says:

    verified I have the original version 1. As a side note version 2 claims to fix the register 0 problem bug.
    d

  12. DaveH says:

    making me craAZY.
    i ran a I2C address scanner and located the as3935 at address 0x03.
    that said i located a spot in your library, as3935.h that sets the address to 0x00. i changed that to 0x03 and still get the above read on serial monitor. curiously i pulled the pins A4 ans A5 and restarted striker. same readout. it is as if i am missing a minor detail in the addressing. my board is definitely address 0x03.
    did i miss your scheme for setting the base address for the board?
    d

    • Skye Sweeney says:

      I2C has an address scheme where the lowest bit is reserved for a read/write bit. So an address of 3 (0011b) needs to be shifted up a bit to make room for the read/write bit. The address defined in the as3935.h file is an “8 bit address” and should be entered as (0x03<<1) or 0x0E. I hope this helps.

  13. Gina says:

    Hey Skye,
    it seems you know lots about the chip AS3935.
    Maybe you have an idea to a tiny problem in the context of my chip.
    Till now there´s no problem to write or read the register of the chip, antenna tuning and clock generation works fine. The rest of the registers stay on default values.
    My problem is that the value of the REG0x03[3:0] is nearly always 0001 (which stands for noise level too high).
    Occasionally this value is zero, but the register of the distance estimation is always 0x3F, althougt there are values in “Energy of the Single Lightning” REG0x04 | 05 and so on..(I´m glad to have an lightning emulator to test lightnings 😉 )

    So I´m wondering if the problem is because I forgot to set any important value at any register -any software problem- or could it be possible that my board is wrong connected (I did it by myself so it´s really possible..) or the LC resonator is not correct, althougt the antenna tuning works fine -hardware problem-?

    Thanks in advanced, it´s great that you share your experience with others!
    (Sorry about my bad english)

    Cheers Gina

    • Skye Sweeney says:

      Gina,

      Now that I can reliably talk to the chip, I am finding that during storms I never get strike alarms just disturbers and noise. I have a series of technical questions I sent to AMS that I have not received answers on yet. I think I will learn what I could do to make my system more sensitive and possibly yours less. This will likely be to change the front end gain and the threshold register values. But how I am not sure.

      Stay tuned and I will be sure to post my findings.

      Your english is much better than my German!

      • Gina says:

        It seems that the problem was a hardware mistake. I tested to change something at the antenna.
        Right now the chip is telling me that there are lightnings all around me. I´m not sure about that result but I´m glad that there is more than “lightning out of range”.
        This should be solved by modifying some registers.

        I wish you continuing success with the chip.

        Gina

  14. Angelo Matta says:

    Hello Skye,

    I’m sorry to have absent for a while, but it was for health reasons. Returning to the subject AS3935, the prototype is working since I rode the SPI mode and I2C. The dificíl was wait for lightning. I sent an email to AMS talking about the lightning emulator and the answer came with a NDA, schematics and code (hex) of project using PIC24FJ16GA002, did the assembly and recorded in the arquivo.hex in PIC24FJ and was very good … I can now emulate a lightning 5km, 10km, even a disturbance or an “Storm overhead”, ie giving to emulate and adjust the AS3935 using LCD NOKIA 5100.

    Angelo Matta

    • Skye Sweeney says:

      I too got a copy of the lightning emulator and code. I have had little luck in getting it to work. The circuit does not seem oscillate as it should, but I used different FETs for the transistors. I have had two real storms go by, and had little luck in reporting strikes that shook the house. Talking with AMS gave me some ideas as to what I should try to change for the next storm.

  15. Angelo Matta says:

    Skye,

    I used the FET BSS84, BSS138, as AS1504 and AS1101 and rode the circuit on a separate board, now I’m trying to capture the data sent to the AS1504 to emulate this in arduino.
    The sensor is functioning without problems and managed to capture the atmospheric disturbances and lightning.

    Angelo

    • Skye Sweeney says:

      Angelo,
      Thanks for telling me your substitutions. I will place some on order to see if that works for me. I am not interested in using the emulator as a way to verify the unit works against real lightning, but as a way to perform self testing every few hours once the system is deployed.

  16. John says:

    Hi Skye

    I was just wondering how can i display the Resonance frequency and the clock freq as a digital number on the LCD or is it possible i am getting random results when i try to print them out

    John

    • Skye Sweeney says:

      John,
      The basic process is to disconnect your normal interrupt service routine (ISR) and register a special one for the capturing of frequencies. This new ISR should simply increment a counter and nothing more. Once you swap to the new ISR set the register to output the frequency you want to measure on the interrupt pin. Now in as few lines of code as possible, zero the counter and start a timer to wait for a fixed amount of time. Or you can use a delay with the associated lack of precision. The longer the delay the better your accuracy, but the bigger (1 byte, 2 bytes, 4 bytes) the counter will have to be. At the end of the timer/delay disable interrupts and read the counter. Now you can do the math to get the frequency from the delay time and the count.
      When done, you need to restore the original ISR, turn of the output frequency, and re-enable the interrupts.

  17. Sven h. says:

    Just for understanding…
    If it tells i have a difference of 8 – this means
    8*16*100=12,8khz?
    That´s not good – right?
    I use a selfmade board.
    Should i use different capacitors on my RCL?

    • Skye Sweeney says:

      What is “it” in “If it tells i have…”? The software I have posted or something else?

      If “it” is my software, than the error of 8 is an error of just 8*16 Hertz and that would be well within the tolerance allowed by the part.

  18. Sven h. says:

    Ah, OK – thank you.
    Then this should be not the problem…
    I have tried different software, and i can´t get it to work.
    The chip can be calibrated – but that´s it.It is not receiving anything, no lightnings no disturbers – nothing.
    I tried to connect the breakout-board to my raspberry in hope that it will work better with it, but same problem here.
    If it would be a problem of my wirings or the chip itselves, calibration would fail.
    So I²C or interrupt can´t be the problem – it seems these connections are working just fine.
    It´s a little bit frustrating, because i have no clue what´s the matter with this device.
    What else can i try?

    • Skye Sweeney says:

      On my Embedded Adventures board, I get disturbers and but even during a strong storm I only get a few strike detections.

      If you can calibrate, then the I2C and the interrupt lines must be connected properly. It would also seem to indicate that antenna circuit is working. After than I am not sure what your problem might be.

      I am beginning to suspect that the AS3935 is not a ‘real’ product. The address 0 register 0 bug and the absolutely idiotic interrupt delay needed indicate this product was hurried to market before it was fully tested. It may have other issues that are causing your problems.

  19. Claudio says:

    I bought 2 Embedded Adventures’s modules, the first seem more sensitive than the second, the first module calls a lot of interrupt for noise and disturber, the second module in case of lighting returns only disturber (it detects 1 lighting every 10).
    I am using the same code (https://github.com/raivisr/AS3935-Arduino-Library) and the same settings. May AS3935 chips are so different?

    Another question: the library https://github.com/SkyeSweeney/Striker define the value ISR_DELAY (I think because “This is because the Interrupt Service Register is not available till 2 ms AFTER the interrupt occurs!). Where is this value used?
    Also AS3935-Arduino-Library seem don’t wait 2ms before read interrupt type.

    • Skye Sweeney says:

      Well I will be a monkey’s uncle.
      You found a problem with my code. The ISR is suppoed to set a flag that the main program polls. When it goes high, it is supposed to wait for the 2ms time before reading the register. Somehow that line of code was deleted.

      I will try to fix this soon and update the github repository. I also have other changes including support for SPI.

  20. Cedric Mally says:

    Hi Skye,
    i want to thank you for the nice script you wrote. It works nice for me now with tautonic board on i2c. The device suprisingly does what it was made for it detects thunderstorms or electrical discharges nearby in the atmosphere. Or in another words whenever it detects strikes a thunderstorm was nearby. And it does not detect all the strikes like predicted in the manual.
    Is it usefull or reliable i would not bet on it :). But it is cool sensor nice to have if you have thunderstorms. The only missing part is the test antenna. But im not sure if i have the space in the case. I still need to put an sd drive and a rtc into the case.

    Best regards.
    Cedric

    • Skye Sweeney says:

      Glad I was able to help. Was the useful script the Python code or the Arduino C code?

      I am still waiting for a thunderstorm to compare the Tautic and Embedded Adventures break out boards. I do not expect to see much difference, but during a storm, I can have them mounted at different orientations to see if the antennas are directionaly sensitive.

      My goal was to have the sensor system initiate a power down of my rather extensive computer network when a thundertorm was in the vicinity. At this point, I am not sure I can trust the sensor to do that for me. So I may be back to my old design using a 50 turn coil antenna on a 1 foot diameter wood hoop. With a scope I was able to detect strikes 50 or more miles away. The problem with that system was that it also alerted each time my furnace, refrigerator, or other high current devices would kick on. But if I couple that with a rain detector, and an optical flash detector, I might have a system I could trust.

  21. Juan Carlos says:

    Hi Skye

    I work in the south of Spain in a network about an automatic system for hydrologic information ( http://www.redhidrosurmedioambiente.es/webgis2/portada_1.html ) and I´m testing two tautic devices and both works “fine”. The problem I have is to set them avoiding false strikes from fluoresecent tubes lightnings into my laboratory or power relays switching in our field stations. It´s very difficult (or imposible) to balance them setting all the parameters for that whithout leave deaf the device. I have been under communication with AMS (Roberto Scotti) and in Spain SAGITRON and nobody gives me a solution, only test and test. So, my conclusion is that if you use this device in standalone mode how I need, I must control the system environment at the strike moment before decide if that strike is true or false. I hope you understand me (sorry for my bad english). I think than you said before AMS has launched this device in the market too quickly, they should have tested this amazing and cheap device more.

    Thanks and best regards

    Juan Carlos

    • Skye Sweeney says:

      Juan,

      I have started to have better luck with the Tautic device. Not sure why it was not working before, but now it seems to work ok.

      To reduce false alarms you could try a few things.
      1) Have a rain sensor. Most storms will have rain before lightning.
      2) Add a Field Mill voltage gradient sensor. Lightning only occurs when the gradient gets to a certain point.
      3) Look for the flashes with an array of optical sensor located at a high point. A high pass filter will reduce the false alarms from other changing light sources.
      4) Tie in with your local weather radar and using image processing look for the red “heavy rain areas”.

      -Skye

  22. Juan Carlos says:

    Skye,

    Thanks for your quick reply and directives to reduce false strikes.
    In our hidrological network we use several strategical ESIDs (Electrical
    Storm Identification Device) covering the complete area, when one of them
    detects a storm depending the distance the station where is installed the
    ESID disconnects automatically the station of the mains while it´s notified
    to the network and disconnects the other stations around the detector one , so,
    we avoid a lot of overvoltages and protect part of the network against the mains
    under storm. Then, I prefer to do all actions with a false strike (I can ensure
    you than our very expensive ESIDs detects sometimes false strikes too although
    they filter them better than the AS3935) avoiding possible fatal damages in our
    equipment.
    The AS3935 works very fine like you can see in their videos in field, far away
    from hard electromagnetic sources. My project works like I explain below:

    It starts configuring (via I2c) the AS3935 antenna (I Know the capacitor number because I have tested the chip before with an oscilloscope) in outdoor mode, RCO
    recalibrating ,noise floor ,etc… till the system is stabilized and in listening
    mode, then, if it detects a disturber it waits two seconds and if the disturber
    continues it adds 1 to the the watchdog threshold value filtering on this way by
    software the continuous disturbers. I have shown this to AMS an they told me that this procedure is good. I should like to know your opinion and the community and
    share experiences. Next month begins the storm time in my work area and I´ll install
    one device in a station, so I will share here data and experiences. If you know another websites about AS3935 discussions and learn more about this chip , please tell me.

    Thanks and Best regards

    Juan Carlos

    Best regards

    • Skye Sweeney says:

      Juan,

      Sorry to not get back to you sooner, I was on vacation.

      I think your method of automatically adjusting the threshold is a good one. I would also suggest that perhaps every few hours to decrement the value by one. I could see a case where you had a local short duration noise source that would drive the threshold up. Without something to pull it back down, you might leave it too high once the noise source went away. I like your idea enough, that I think I will implement in my own software.

      -Skye

      • Juan Carlos says:

        Skye,

        Thanks for your comment and don´t worry , like you can see I have been on vacation too after and I have remembered now our posts checking them. What you says about to reduce the watchdog threshold is good for me too and I´m thinking to implement code for that function after view results on the device I have testing in a repeater station near our headquarters. My particular war are the false strikes caused by power relays…etc how you know well.

        I´ll talk you something more after obtain new results. I will not hesitate to share them with you.

        Best regards.

        Juan Carlos

  23. Oleg says:

    Hello Skye,

    I am working with the AS3935 on a self-designed board for round about 2 months.
    A little bit to background of my board: I am using an PIC18F25K80 and communicate by I2C with AS3935. The supply voltage of the microcontroller and the AS3935 are 5V, so i have to turn on the AS3935-intern voltage regulator.
    Because in my city are mainly storms in summer, i have bought AMS’s lightning emulator and demokit for using as a reference during validation of my board.
    I am testing my board for 2/3 weeks.
    The test-results are as follows: AMS’s demokit is working fine and detects almost all disturbance simulated by the lightning emulator right.
    Much to my regret my board isn´t working -> simulated “Noise Level too high” and “disturber” are detected right. But simulated “lightnings” are always detected as “disturber”.
    In the EEVBlog you have mentioned “The chip does have some design flaws that can be worked around.”
    The behaviour using I2C at address 0 is known to me and worked arround by using the address ADD0=ADD1=1 (Vdd). Testing this I have found another issue: If the voltage regulator is turned on, ADD0 and ADD1 must not be connected to Vdd (as described in the data sheet). If the voltage regulator is turned on and one of the address pins is set to the positive voltage supply (Vdd), the chip-intern voltage regulator will not be able to regulate the voltage. In my case the output regulated voltage was 4,3V instead of 3V as described in data sheet. I have contacted the AMS support with it and they confirmed this issue. They recommended to me to set the ADD0 and ADD1 pins to the voltage regulated supply (VREG). After connecting the address pins to VREG the regulated voltage became 3V =).

    However, my board is still detecting all simulated “lightnings” as “disturber”.
    For that reason I would like to ask you which further issues/design flaws of the chip you have found and how they can be worked arround.

    Thank you in advance and stormy greetings from Eastern Frisia (Germany).
    Oleg

    PS: Yesterday the powerful storm “Xaver” has lashed Germany with hurricane-force winds and has left a wake of devastation =(

    • Skye Sweeney says:

      Other than the address 0 issue and the silly 2 ms wait after interrupt before reading the interrupt source register, I know of no other problems. You now have documented a third. Last I looked, AMS had still not posted an errata sheet for the chip on their website.

      I have struggles with this chip as well. I have found that you can get some resonable performance once all the gains and thresholds are set properly. I did this mostly by trial and error. I also beleive that the inductor antenna is orientation sensitive. Trying different positions may get you better results.

      Sorry that I am not more helpful.

  24. Chuck Bennett says:

    Hi, I have just a quick question about the board. Your code mentions the “strike generator” being driven by pin 4 but I’m not clear what you are using.

    I have everything running, all looks good (rev. 2) board, but I just can’t get it to toss an interrupt by flipping lights, using a pizeo BBQ lighter etc..

    When the BIT test runs it says it failed and of course I don’t have a noise generator hooked to PIN 4, so I’m wondering what you used to test that it is actually detecting something.

    Thanks so much for the example code. I had been beating my head against the wall using Wiring before I found your code and understood why mine was never going to work.

    Best, Chuck

    BIT + reg dump
    BIT failed
    Reg 0x0 = 24
    Reg 0x1 = 21
    Reg 0x2 = C0
    Reg 0x3 = 0
    Reg 0x4 = 0
    Reg 0x5 = 0
    Reg 0x6 = 0
    Reg 0x7 = 3F
    Reg 0x8 = 4

    • Skye Sweeney says:

      I had managed to get my hands on the schematics for the lightning simulator that AMS sells (at a ridiculous price). It is basically and RCL circuit that outputs pulses in the right frequency, number, and amplitude. This ‘signature’ is what the detector chip is looking for. A pizeo spark generator is not going to fit the profile.

      With all that said, I was never able to get the simulator to work. In my code, pin 4 does nothing at all. Ever BIT cycle, it gives me an error as well. Getting back to that simulator circuit is on my todo list, but as it would happen, fairly low on that list.

      • Juan Carlos says:

        Hi Skye,

        At first, sorry for long time no reply…, I´ve eventually installed one of my detectors in a station located near Tarifa (Cádiz) with the number two (Sierra Luna) if you check it in our website network map: http://www.redhidrosurmedioambiente.es/webgis2/portada_1.htm

        It seems working ok, it detected two strikes under 17 km evaluated as near strikes and at the same time another sensor (an american industrial one “ESID”) located in the station number six (Los Reales) in Estepona separated around 40 Km detected two strikes too evaluated as over 17 Km (far) during last storm in that area, so I think that those strikes are good.

        I finally set the sensor with the minimum possible parameters to keep it the most awake possible and the DISTURBERS IRQ disabled (I prefer a false strike at times instead of keeping the equipment unprotected). So far this year I haven´t obtained false strikes (let you imagine this sensor with several repeater and military stations around it ) as I told you few replies above I had in my laboratory at times.

        I´ve made another one to install in the station number 32 (Repetidor de la Encantada) . This station is another UHF and VHF radio repeater located next to a mains high voltage transformer in order to have under control and protect the water reservoirs stations around it and its behavior so close to the mains line.

        I won´t hesitate sharing what´s new about them as soon as I’m getting new data. I bought two AS3935 units at Embedded Adventures and they seem completely deaf (I can read, write and calibrate them but nothing´s detected, no strikes and no disturbers), I´d like to know if someone of this blog has had the same problem, however I bought another two as3935 at http://www.playingwithfusion.com and they work ok like from Tautic.

        I hope you understood me (my english even needs a lot of impovement).

        Regards…

        Juan Carlos

  25. GF says:

    I have just started using the code. I got it running. Looks like it connects and reads the registers. However each run provides only the following output and then sits there doing nothing. Any pointers to progress a bit farther ?

    Striker starting
    Tune: 0 = 17
    Tune: 1 = 12
    Tune: 2 = 9
    Tune: 3 = 4
    Tune: 4 = 0
    Tune: 5 = 4
    Tune: 6 = 8
    Tune: 7 = 12
    Tune: 8 = 16
    Tune: 9 = 20
    Tune: 10 = 24
    Tune: 11 = 28
    Tune: 12 = 31
    Tune: 13 = 36
    Tune: 14 = 39
    Tune: 15 = 43
    Best tune value: 4
    Reg 0x0 = 24
    Reg 0x1 = 22
    Reg 0x2 = C2
    Reg 0x3 = 20
    Reg 0x4 = 0
    Reg 0x5 = 0
    Reg 0x6 = 0
    Reg 0x7 = 3F
    Reg 0x8 = 4
    ISR: Noisy
    Reg 0x0 = 24
    Reg 0x1 = 22
    Reg 0x2 = C2
    Reg 0x3 = 20
    Reg 0x4 = 0
    Reg 0x5 = 0
    Reg 0x6 = 0
    Reg 0x7 = 3F
    Reg 0x8 = 4
    BIT failed
    Reg 0x0 = 24
    Reg 0x1 = 22
    Reg 0x2 = C2
    Reg 0x3 = 20
    Reg 0x4 = 0
    Reg 0x5 = 0
    Reg 0x6 = 0
    Reg 0x7 = 3F
    Reg 0x8 = 4
    ISR: Noisy

  26. Pingback: AS3935 Lightning Detector | The Grumpy Engineer

  27. krunal SHah says:

    Hi

    I have developed my own board using AS3935 as attached , My device address is set as “0” and i am getting Noise & disturbance interrupt but not the lightning Interrupt. I am trying to generate Lightning using GAS lighter. Can you please help me to get where i am wrong and why i am not able to get interrupt.

    Thanks
    Krunal Shah

    • Skye Sweeney says:

      From What I understand, the chip will not see the spark from a gas lighter as lightning. True lightning has a signature that is not matched by the gas spark. AS does sell a lightning simulator at a ridiculous price. It generates a waveform of impulses that does match real lightning.

      I am not surprised you are only seeing disturbances. I had to test over many months waiting for real storms to pass by. They would often come by late at night forcing me to get up at weird hours to get another 10 minutes of data.

      • Krunal Shah says:

        Dear Skye,

        Thank you so much for reply Can you please spare some time and look into my code, schematic and the Layout to see what is wrong with the code/design.We bought Emulator board and Development board from AMS , that combination works well. Now when i tried to use the same emulator board with our designed board it is detecting everything as Noise as i have masked disturbance & if detects as Lightning just once and same distance is always same there, but lightning comes once in blue moon :-(… We have seen the code which comes with Development Board and it has Register 0x33, which is antenna shorting function (These is not detailed in datasheet or anywhere else), when we do that we are able to detect lightning but every time same distance is there. We asked AMS for the help but their reply is they do not recommendate to use register 0x33. We are doing these since long but no success at all…. If you can share your email id on which i can share the documents and if you can review the same and let me know what is wrong that will be great help..

        • Skye Sweeney says:

          I am not an RF electrical engineer, but I suspect that the antenna circuit on your receiver/detector board is probably not correct.

          It has been 3 years since I worked on this project. The only thing I can remember about the chip was its stupid way the interrupt pin worked. You could NOT read the interrupt status register as soon as you got the interrupt. You had to wait a long time (20ms?) before the register would get populated. Perhaps you are reading it too soon?

          • Krunal Shah says:

            Dear Skye

            We are waiting for 2ms before reading interrupt status register. But the issue is we are not getting interrupt on IRQ pin, we have check the same on the Oscilloscope that AMS is not generating IRQ high for the interrupt.

            I am pasting some code here, if you can look and help us that will be great as AMS is not giving support on software or hardware side they just says read datasheet and app not etc.,

            void InitSensor()
            {
            reset();
            __delay_us(2000);
            registerWrite(AS3935_MISC,0x01); // Antenna Short Logic As per your Code

            setWatchdogThreshold(2);
            setSpikeRejection(2);
            setNoiseFloor(4);

            enableDisturbers();
            setIndoors();
            //setOutdoors();
            //disableDisturbers();
            outputCalibrationValues();
            __delay_us(2000);

            for(i=0;i<0x32;i++)
            {
            ReadSensorRegister(LIGHTNING_SENSOR_ADDRESS, i, &LightningRegValue[i], 1);
            }
            }

            void SensorIntHandler()
            {
            if(EXTI_GetITStatus(LIGHTNING_INT_EXTI_LINE) != RESET)
            {
            __delay_us(2000);
            ReadSensorRegister(LIGHTNING_SENSOR_ADDRESS, 0x03, &IntRegValue, 1);

            if((IntRegValue & 0x01) == 0x01)
            {
            lightningDistance =0;
            NoiseIntReceived++;
            }
            else if((IntRegValue & 0x04) == 0x04)
            {
            lightningDistance = lightningDistanceKm();
            clearStatistics();
            DistIntReceived++;
            }
            else if((IntRegValue & 0x08) == 0x08)
            {
            lightningDistance = lightningDistanceKm();
            clearStatistics();
            LightIntReceived++;
            }
            //registerWrite(AS3935_MISC,0x01); Antenna Short Logic As per your Code, We have to enable it to get Lightning Interrupt Every Time

            /* Clear the EXTI line pending bit */
            EXTI_ClearITPendingBit(LIGHTNING_INT_EXTI_LINE);
            }
            }

          • Skye Sweeney says:

            For some reason I can’t seem to reply to the post where you posted your code. Perhaps you will find this anyway.

            First, I would order this board and see if you can get it to work with your code. This is what I used had had reasonable results with.
            http://www.embeddedadventures.com/as3935_lightning_sensor_module_mod-1016.html

            Next I looked at your code very quickly and the one thing I saw that is rather terrifying is your 2ms delay inside the ISR. Unless this is the only interrupt in your entire system, putting a delay in an ISR prevents other ISRs from happening. In my line of work, this is a capital error. My solution was to set a flag in the ISR and then poll it in the main thread. You could also be fancier and set a timer in the ISR to generate a second ISR in 2 ms. In that ISR, you could read the proper registers and act accordingly.

  28. Krunal Shah says:

    Dear Skye,

    Also when e readout the register of Development board of AS3935, we found that register 0x32 value is 1, while we tried to read the same register in out board and in Development board with our code it shows 0. Is there any effect of these register on the performance of the AS3935?

    • Skye Sweeney says:

      It has been several years since I looked at anything to do with the lightning detector. I soon as I got my board up and running, we stopped getting thunderstorms. you could look at my code to see how I set up the registers. Other than that, I would be of little help.

  29. Vladimir says:

    some hints about noise levels – seems like when the board is placed too close to e.g. my laptop, it generates quite some noise, i put it ~60cm from the laptop, and now indoor setting and noise level 1 is pretty silent

Comments are closed.