-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create bbn_m5atomS3_lite_AS3935_lightning.ino
- Loading branch information
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
bbn_m5atomS3_lite_AS3935_lightning/bbn_m5atomS3_lite_AS3935_lightning.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <M5AtomS3.h> | ||
#include <SparkFun_AS3935.h> | ||
#include "NmeaXDR.h" | ||
|
||
// 0x03 is default i2c address, but the address can also be 0x02, 0x01. | ||
// Adjust the address jumpers on the underside of the product. | ||
#define AS3935_ADDR 0x03 | ||
#define INDOOR 0x12 | ||
#define OUTDOOR 0xE | ||
#define LIGHTNING_INT 0x08 | ||
#define DISTURBER_INT 0x04 | ||
#define NOISE_INT 0x01 | ||
|
||
SparkFun_AS3935 lightning(AS3935_ADDR); | ||
|
||
// Interrupt pin for lightning detection | ||
const int lightningInt = G7; | ||
|
||
// This variable holds the number representing the lightning or non-lightning | ||
// event issued by the lightning detector. | ||
int intVal = 0; | ||
int noise = 2; // Value between 1-7 | ||
int disturber = 2; // Value between 1-10 | ||
|
||
void setup() { | ||
auto cfg = M5.config(); | ||
AtomS3.begin(cfg); | ||
Serial.begin(4800); | ||
|
||
// When lightning is detected the interrupt pin goes HIGH. | ||
pinMode(lightningInt, INPUT); | ||
|
||
Serial.println("AS3935 Franklin Lightning Detector"); | ||
|
||
Wire.begin(); // Begin Wire before lightning sensor. | ||
|
||
if ( !lightning.begin() ) { // Initialize the sensor. | ||
Serial.println ("Lightning Detector did not start up, freezing!"); | ||
while (1); | ||
} | ||
else { | ||
Serial.println("Schmow-ZoW, Lightning Detector Ready!"); | ||
} | ||
|
||
// The lightning detector defaults to an indoor setting at | ||
// the cost of less sensitivity | ||
lightning.setIndoorOutdoor(INDOOR); | ||
//lightning.setIndoorOutdoor(OUTDOOR); | ||
} | ||
|
||
void loop() { | ||
if (digitalRead(lightningInt) == HIGH) { | ||
// Hardware has alerted us to an event, now we read the interrupt register | ||
// to see exactly what it is. | ||
intVal = lightning.readInterruptReg(); | ||
if (intVal == NOISE_INT) { | ||
Serial.println("Noise."); | ||
// Too much noise? Uncomment the code below, a higher number means better noise rejection. | ||
//lightning.setNoiseLevel(setNoiseLevel); | ||
} | ||
else if (intVal == DISTURBER_INT) { | ||
Serial.println("Disturber."); | ||
// Too many disturbers? Uncomment the code below, a higher number means better disturber rejection. | ||
//lightning.watchdogThreshold(threshVal); | ||
} | ||
else if (intVal == LIGHTNING_INT) { | ||
Serial.println("Lightning Strike Detected!"); | ||
// Lightning! Now how far away is it? Distance estimation takes into | ||
// account any previously seen events in the last 15 seconds. | ||
byte distance = lightning.distanceToStorm(); | ||
Serial.print("Approximately: "); | ||
Serial.print(distance); | ||
Serial.println("km away!"); | ||
} | ||
} | ||
delay(100); | ||
} |