sparkfun_qwiicas3935

CircuitPython driver library for the Sparkfun AS3935 Lightning Detector

  • Author(s): Gaston Williams

  • Based on the Arduino library for the Qwiic AS3935 Lightning Detector Written by Elias Santistevan @ SparkFun Electronics in January, 2019

  • I2C Register read functions based on code written by Phil Fenstermacher on December, 2014 as part of the RPi_AS3935 python library.

Implementation Notes

Hardware:

  • This is library is for the SparkFun Qwiic AS3935 Lightning Detector.

  • SparkFun sells these at its website: www.sparkfun.com

  • Do you like this library? Help support SparkFun. Buy a board! https://www.sparkfun.com/products/15276

Software and Dependencies:

sparkfun_qwiicas3935.DEFAULT_I2C_ADDR = 3

Default I2C address for AS3935

class sparkfun_qwiicas3935.Sparkfun_QwiicAS3935(debug=False)

Abstract base class for Sparkfun AS3935 Lightning Detector. Use the appropriate driver subclass Sprarkfun_QwiicAS3935_I2C() for I2C or Sparkfun_QwiicAS3935_SPI() for SPI.

ANTENNA_FREQ = 3

Display the antenna oscillator frequency on the INT line.

DISTURBER = 4

Interrupt register value for a disturber detected interrupt.

INDOOR = 18

AS3235 AFE setting for indoor use.

LIGHTNING = 8

Interrupt register value for a lightning detected interrupt.

NOISE = 1

Interrupt register value for a noise too high interrupt.

OUTDOOR = 14

AS3235 AFE setting for outdoor use.

calibrate()

Send command to calibrate the oscillators.

clear_statistics()

Clear the number of lightning strikes that has been read in the last 15 minutes.

property connected

Verify the AS3935 is connected to the bus.

display_oscillator(state, osc)

This will send the frequency of the oscillators to the IRQ pin. State is True/False for on/off Use value osc = ANTENNA_FREQ (3) to display the Antenna frequency for tuning. Oscilator value must be between 1 and 3. Other oscilator frequenciess are available as well: osc = 1, TRCO - Timer RCO Oscillators 1.1MHz osc = 2, SRCO - System RCO at 32.768kHz osc = 3, LCO - Frequency of the Antenna

property distance_to_storm

Returns the distance to the front of the storm and not the distance to a particular lightning strike.

property division_ratio

This function returns the current division ratio of the resonance frequency. The antenna resonance frequency should be within 3.5 percent of 500kHz, and so when modifying the resonance frequency with the internal capacitors (tuneCap()) it’s important to keep in mind that the displayed frequency on the IRQ pin is divided by this number.

property indoor_outdoor

This funciton changes toggles the chip’s analog front end settings for Indoors or Outdoors operation.

property lightning_energy

This returns a 20 bit value that represents the energy of the lightning strike. According to the datasheet this is only a pure value that doesn’t have any physical meaning.

property lightning_threshold

This function will return the number of lightning strikes must strike within a 15 minute window before it triggers an event on the IRQ pin. Default is 1.

property mask_disturber

This setting will return whether or not disturbers trigger the IRQ pin.

property noise_level

This function will return the value of noise level threshold. The default is 2.

power_down()

This breakout board consumes 1-2uA while powered down. If the board is powered down, then the TRCO must be recalibrated by calling the wake_up() function. Note that SPI and I2C remain active when the chip is powered down.

read_interrupt_register()

When there is an event that exceeds the watchdog threshold, the interrupt register is written with the type of event. There are two event detected interrupt values, DISTURBER (disturber detected) or LIGHTNING (lightning detected). A third interrupt value NOISE (noise too high) indicates that the noise level has been exceeded and will persist until the noise has ended. Interrupts are active HIGH. There is a one second window of time to read the interrupt register after lightning is detected, and 1.5 seconds after disturber.

reset()

Reset all the device registers to initial power-on default values

property spike_rejection

Return the value of the spike rejection register. This value helps to differentiate between events and acutal lightning, by analyzing the shape of the spike during chip’s signal validation routine. Increasing this value increases robustness at the cost of sensitivity to distant events.

property tune_cap

This setting will return the capacitance of the internal capacitor. It will return a value from 0 to 120pF, in 8pF steps.

wake_up()

The following function wakes the Lightning Detector after a power down. The timer RC oscillator (TRCO) needs to be recalibrated after power down. This function sends a command to the CALIB_RCO register, waits a bit and then checks that it has been successfully calibrated. Note that SPI and I2C remain active during power down.

property watchdog_threshold

This function returns the threshold for events that trigger the IRQ Pin.

class sparkfun_qwiicas3935.Sparkfun_QwiicAS3935_I2C(i2c, address=3, debug=False)

Driver subclass for Sparkfun AS3935 Lightning Detector over I2C

class sparkfun_qwiicas3935.Sparkfun_QwiicAS3935_SPI(spi, cs, debug=False)

Driver subclass for Sparkfun AS3935 Lightning Detector over SPI