.NetMF Gadgeteer AMS AS3935 Lightning Detector Module

My Gadgeteer AMS AS3935 Lightning Detector modules using SPI interface with a MikroElectronika Thunder Click board and an Embedded Adventures MOD-1016 board running an I2C interface.

MikroElektronika Thunder Click http://www.mikroe.com/click/thunder/

Embedded Adventures MOD-1016 Embedded Adventures - Products - MOD-1016 AS3935 Lightning and Storm Sensor Module

GHI Electronics BreadBoard X1 Module https://www.ghielectronics.com/catalog/product/454

Source Code

MikroElectronika Thunder Click https://github.com/ZingPow/Breakout_Boards/tree/master/mikroElektronika/LightningDetectorSPI

Embedded Adventures MOD-1016 https://github.com/ZingPow/Breakout_Boards/tree/master/Embedded%20Adventures/LightningDetectorI2C

Demo App https://github.com/ZingPow/Breakout_Boards/tree/master/Demo%20Apps/AS3935Demo

Comments, suggestions?


Nice job! Is this the same chip @ Architect used on his (yet to be released) Bolt module?

It is the same chip. :slight_smile:

@ Duke Nukem - Did you test it with I2C?

@ Architect - Tested with both SPI and I2C (ie the Embedded Adventure MOD-1016 uses the I2C interface). I’m thinking my I2C version code should work with your Bolt module as well (might have to tweak the pin assignments if they are different).


This is what I like with NETMF : portability. I will be able to use your driver with the example code provided in the MBN driver without changes except those related to Gadgeteer.

Your example code :

public partial class Program
        private readonly LightningDetectorSPI lightningDetectorSpi = new LightningDetectorSPI(9);
        // This method is run when the mainboard is powered up or reset.   
        private void ProgramStarted()
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            lightningDetectorSpi.NoiseDetected += lightningDetectorSpi_NoiseDetected;
            lightningDetectorSpi.DisturbanceDetected += lightningDetectorSpi_DisturbanceDetected;
            lightningDetectorSpi.LightningDetected += lightningDetectorSpi_LightningDetected;

        private void lightningDetectorSpi_LightningDetected(LightningDetectorSPI sender,
            LightningDetectorSPI.LightningEventArgs e)
            Debug.Print("Lightning Detected " + e.Distance + " km away with energy " + e.Energy);

        private void lightningDetectorSpi_DisturbanceDetected(LightningDetectorSPI sender)
            Debug.Print("Disturbance  Detected");

        private void lightningDetectorSpi_NoiseDetected(LightningDetectorSPI sender)
            Debug.Print("Noise Detected");

MBN example code :

public class Program
        static ThunderClick _thunder;

        public static void Main()
            // Create the instance
            _thunder = new ThunderClick(Hardware.SocketOne);

            // Subscribe to events
            _thunder.LightningDetected += TH_LightningDetected;
            _thunder.DisturbanceDetected += TH_DisturbanceDetected;
            _thunder.NoiseDetected += TH_NoiseDetected;

            // Some information
            Debug.Print("Continuous input noise level " + _thunder.ContinuousInputNoiseLevel + " µV rms");

            // Start interrupt scanning


        static void TH_NoiseDetected(object sender, EventArgs e)
            Debug.Print("Noise detected");

        static void TH_DisturbanceDetected(object sender, EventArgs e)
            Debug.Print("Disturbance detected");

        static void TH_LightningDetected(object sender, ThunderClick.LightningEventArgs e)
            Debug.Print("Lightning detected at " + e.Distance + " km, energy : " + e.Energy);

@ Bec a Fuel - Like I said makes it easy to share code, enjoy ‘and when you speak of me, speak well’ (quote from one of my favorite movies).

1 Like

I ported the I2C version to pure NETMF and it works well but I have noticed that once the storm is close or overhead, the detection kind of stops and I only see a few every so often. Once it gets far away again, the outputs start coming again.

Anyone else seen this?

1 Like

That must have been an easy port. I think the way the detection works would limit its ability to detect directly overhead lightning, but I’ll have to wait six months here before I can test that out, unless someone wants to fly me somewhere warmer then it is here.

Will your driver work against @ Architect’s Bolt module?

@ Brett - I believe that @ Architect’s Bolt module uses the I2C interface so my I2C version should work or will work with very few changes.

1 Like

I would have been a great beta tester right now.

The freakiest thunderstorm/hailstorm is hitting my house right now.

We are being buried by ICE, and it is summer… one minute Im sitting by the fan trying to stay cool, and the next minute, ice is flowing down the street

(the pic shows the first wave of ice, during a break… now it is pounding us again)

I’ve changed the detection count to 5 and this seems to provide better response to detecting the edge of the approaching storm. It’s rainy season here so I should be able to get some good testing over the coming week or so. Should be something later today.