AS3935 in same script as other SPI sensors

I am attempting to add an AS3935 lightning sensor to my weather station. I previously had issues in that I could not run a script for the lightning sensor and other SPI sensors (on an mcp3008 ADC) at the same time. I sorted that out by converting the code for the other sensors (photocell & wind direction) to use busio/digitalio/board, the same as the sparkfun_qwiicas3935 library.

I do however, have to have the code for the sensors in the same script so that they can share an SPI object.

The problem I’m having now is how to detect the interrupt from the AS3935 while at the same time polling the other sensors in a loop.

I have tried gpiozero.button().when_pressed() and gpiozero.DigitalInputDevice().when_activated() to run a function that logs the lightning data and that does appear to get triggered and but the data on the read_interrupt_register() is garbage (reports strikes when there is no lightning within 50 miles and at impossibly long distances).

I also tried a separate thread (threading.thread) for a loop for the AS3935 but that also has garbage on the registers.

I think the issue is that the MCP3008 and the AS3935 are sharing the SPI pins and so when the code for the lightning sensor is run when triggered, the data on the pins is no longer correct (or it was falsely triggered).

So, how should I manage this? I know that others have run the AS3935 sensor with their weather station and I know it must be an issue with other combinations of sensors.

The easiest thing would be to use one of our Weather Carrier boards https://www.sparkfun.com/products/13956 or https://www.sparkfun.com/products/16794 (this one requires a MicroMod processor, but has many more features)

Otherwise, I would suggest at least running through the example code for them https://github.com/sparkfun/MicroMod_We … B_Test.ino which might illustrate how they interrupts are used in that example (the example also uses i2c in its code, but the main thing is to inspect how the interrupts function and apply it to your scenario)