Hello,
This is the several components within my project.
Arduino UNO SMD3
Arduino UNO Click Shield
Thunder click device AS3935 on slot 2 (CS/D9 & D3/INT)
IDE 1.6.5
Adafruit SD DATALOGGER (CS D10)
I'm trying to build a Thunder Lightning detector with recording.
I would like some help to gather the both SPI's components: AS3935 & SD_card.
There is clearly a conflict between the two components.
THE AS3935 used SPI-mode1 and the data sheet declare an Active Low Cheap select. Obviously when CS is HIGH more than one device can communicate on MISO....
I tried to switch the both CS of SD-Card and AS3935 to organise the recording on interrupt but... without success...
I added the sketch but without SD-card management because I think I'm a real bad coder...
Thanks in advance.
#include <SPI.h>
#include <AS3935.h>
void printAS3935Registers();
byte SPItransfer(byte sendByte);
void AS3935Irq();
volatile int AS3935IrqTriggered;
#define IRQpin 3 // Interrupt1
#define CSpin 9
AS3935 AS3935(SPItransfer,CSpin,IRQpin);
void setup() //------------------------------------------------------------------------------------------------------------------------
{
Serial.begin(9600);
SPI.begin(); SPI.setDataMode(SPI_MODE1); SPI.setClockDivider(SPI_CLOCK_DIV16); SPI.setBitOrder(MSBFIRST);
AS3935.reset();
outputCalibrationValues(); recalibrate();
AS3935.setIndoors();
AS3935.setNoiseFloor(1);
AS3935.setSpikeRejection(2);
AS3935.setWatchdogThreshold(2);
outputCalibrationValues(); recalibrate();
//AS3935.disableDisturbers();
printAS3935Registers();
AS3935IrqTriggered = 0;
attachInterrupt(1,AS3935Irq,RISING);
}
void loop() //------------------------------------------------------------------------------------------------------------------------
{
if(AS3935IrqTriggered)
{
AS3935IrqTriggered = 0;
int irqSource = AS3935.interruptSource();
if (irqSource & 0b0001) {Serial.println("Noise level too high, try adjusting noise floor");}
if (irqSource & 0b0100) {Serial.println("Disturber detected");}
if (irqSource & 0b1000)
{
int strokeDistance = AS3935.lightningDistanceKm();
if (strokeDistance == 1) {Serial.println("Storm overhead, watch out!");}
if (strokeDistance == 63) {Serial.println("Out of range lightning detected.");}
if (strokeDistance < 63 && strokeDistance > 1) {Serial.print("Lightning detected "); Serial.print(strokeDistance,DEC); Serial.println(" km away."); }
}
}
}
//------------------------------------------------------------------------------------------------------------------------
byte SPItransfer(byte sendByte) { return SPI.transfer(sendByte);}
//------------------------------------------------------------------------------------------------------------------------
void AS3935Irq() { AS3935IrqTriggered = 1;}
AS3935_example_Rebuild.ino (2.01 KB)
PrintRegister.ino (541 Bytes)
OutputCalibrationValues.ino (419 Bytes)
Recalibrate.ino (185 Bytes)