Skip to content

Commit

Permalink
Update bbn_m5atomS3_lite_AS3935_lightning.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrouch authored Nov 14, 2024
1 parent 6a2d3d3 commit 26f4344
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

// 0x03 is default i2c address, but the address can also be 0x02, 0x01.
// Adjust the address jumpers on the underside of the product.
// C - SCL i2c clock
// D - SDL i2c data
#define AS3935_ADDR 0x03
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
Expand All @@ -12,21 +14,22 @@
SparkFun_AS3935 lightning(AS3935_ADDR);

// Interrupt pin for lightning detection
const int lightningInt = G7;
const int lightningInt = G8;

byte noiseFloor = 2;
byte watchDogVal = 2;
byte noiseFloor = 4;
byte watchDogVal = 3;
byte spike = 2;
byte lightningThresh = 1;
byte lightningThresh = 0;

void setup() {
auto cfg = M5.config();
AtomS3.begin(cfg);
Serial.begin(4800);

Wire.begin(G2 /* SDL */, G1 /* SCL */, 100000UL);

pinMode(lightningInt, INPUT); // When lightning is detected the interrupt pin goes HIGH.

Wire.begin();
if (!lightning.begin(Wire)) {
//Serial.println("Lightning Detector did not start!");
while (1);
Expand All @@ -36,11 +39,11 @@ void setup() {
lightning.setNoiseLevel(noiseFloor);
lightning.watchdogThreshold(watchDogVal);
lightning.spikeRejection(spike);
lightning.lightningThreshold(lightningThresh);
//lightning.lightningThreshold(lightningThresh);
lightning.setIndoorOutdoor(INDOOR);
//lightning.setIndoorOutdoor(OUTDOOR);
//Serial.println("Lightning Detector did start!");

Serial.println("Lightning Detector did start!");
}

void loop() {
Expand All @@ -50,12 +53,14 @@ void loop() {
uint8_t intVal = lightning.readInterruptReg();
if (intVal == NOISE_INT) {
// Noise
//Serial.println("Noise Detected!");
}
else if (intVal == DISTURBER_INT) {
// Disturber
//Serial.println("Disturber Detected!");
}
else if (intVal == LIGHTNING_INT) {
Serial.println("Lightning Strike Detected!");
//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.
gen_nmea0183_xdr("$BBXDR,D,%.0f,M,LIGHTNING_RANGE", (float)lightning.distanceToStorm() * 1000.0);
Expand Down

0 comments on commit 26f4344

Please sign in to comment.