I’m following the hookup guide for the AS3935 provided on the SparkFun website. Upon compiling I’m getting some errors that I am thinking may be more about the ESP32 than the library, but I thought that I would check.
First error:
SparkFun_AS3935 lightning(AS3935_ADDR);
Error:
“WeatherStation_FeatherHUZZAH:40:38: error: invalid conversion from ‘int’ to ‘i2cAddress {aka SF_AS3935_I2C_ADDRESS}’ [-fpermissive]”
I’ve tried replacing it with the explicit 0x03 with no luck.
Possibly, but I’m not aware of any plans to do that at this time. You might try filing an issue in the Github repository. The team that wrote the firmware will see that.
Every time I try to use the lightning detector, all I get is the message, “Lightning Detector did not start up, freezing!” I have tried several different microcontrollers, jumper wires, breadboards, and tried cutting the I2C pull-up jumpers. Perhaps I received a defective unit?
I have an AS3935 Lightning Detector board (SPX-15057) connected to the BlackBoard C (SPX-15098) but it doesn’t go past the “Lightning Detector did not start up, freezing!” prompt. I have the same Blackboard talking to a QWIIC OpenLog and that communication seems to be fine so I don’t think the issue is either the Blackboard C or the QWIIC cable.
I even modified the specific section from:
if( !lightning.begin() ) { // Initialize the sensor.
//if( !lightning.beginSPI(9, 2000000){ // Uncomment for SPI.
Serial.println ("Lightning Detector did not start up, freezing!");
while(1);
}
else
Serial.println("Schmow-ZoW, Lightning Detector Ready!");
to:
while( !lightning.begin() ) { // Initialize the sensor.
Serial.println ("Lightning Detector did not start up, freezing!");
delay(1000);
}
Serial.println("Schmow-ZoW, Lightning Detector Ready!");
I’m having the same issue. I just received the Qwiic AS3935 Franklin Lightning Detector direc from Sparkfun, and am using a DEV-12757 (Batch #58508) RedBoard with a Sparkfun i2c shield connected to the Qwiic AS3935 along with a separate jumper between pin 4 of the RedBoard and the INT signal of the AS3935 board. I’m running Arduino IDE 1.8.9, building example “BasicLightning” without build errors Any suggestions?
That error is showing up usually because of a connection issue that is preventing the Arduino from initializing the sensor. You can check to see if your microcontroller is seeing the device on the I2C bus by running the [I2C Scanner example from Arduino. If the Lightning Detector is present on the bus, you should see its address (0x03) printed in your serial monitor.
Please try that code to confirm the board is showing up on the bus. Blazer5154, if you disabled the pull-up jumpers, you will want to re-solder those jumper pads back together. If you do not see the Lightning Detector show up on the bus, please take a few photos of your boards and circuit and attach them to your replies.](Arduino Playground - I2cScanner)
I had the exact same issue the first time I tried the board but once I ran the I2C Scanner sketch (attached) and the sketch discovered a device at address 0x03, everything worked after that.
Try running the I2C_Scanner.ino sketch and see if it finds a device at 0x03. If it doesn’t reply with photos of the top and bottom of your board and a photo showing how you have the board connected to your Arduino. If the I2C scanner does find a device at 0x03, then try the first example in our library and see if it works then.
I have no idea why it took running the I2C scanner first, but it seems to work.
I tried the I2C scanner and the device shows up at 0x03; I was unable to re-solder the I2C jumpers though, the pads lifted off the board as soon as I applied solder. Device still shows up in I2C scan though. If you still need photos, let me know and I’ll send as soon as I can.
Interesting side-note; if I un-comment the SPI lines in the program the program indicates that the sensor is ready despite being only connected to the I2C pins.
I tried the “I2C Scanner” sketch (from both the SFE GitHub and ArduinoCC) and got the device’s I2C recognized. Result follows:
I2C Scanner
Scanning…
I2C device found at address 0x03 !
done
I then tried the AS3935 SFE sketch again with the same results. See below:
AS3935 Franklin Lightning Detector
Lightning Detector did not start up, freezing!
The AS3935 code is as follows:
/*
A basic lightning detector Arduino example sketch.
By: Elias Santistevan
SparkFun Electronics
Date: January, 2019
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
This example listens for lightning events, which are internally determined by
the IC to be real or false events.
Hardware:
This is SparkFun's Qwiic Lightning Detector and so is compatible with the Qwiic
system. You can attach a Qwiic cable or solder to the I-squared-C pins.
You'll also need a wire attached to the interrupt.
*/
#include <SPI.h>
#include <Wire.h>
#include "SparkFun_AS3935.h"
// 0x03 is default, but the address can also be 0x02, 0x01, or 0x00
// 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
// If you using SPI, instantiate class without address:
//SparkFun_AS3935 lightning;
// If you're using I-squared-C then keep the following line. Address is set to
// default.
SparkFun_AS3935 lightning(AS3935_ADDR);
// Interrupt pin for lightning detection
const int lightningInt = 4;
int noiseFloor = 2;
// This variable holds the number representing the lightning or non-lightning
// event issued by the lightning detector.
int intVal = 0;
void setup()
{
// When lightning is detected the interrupt pin goes HIGH.
pinMode(lightningInt, INPUT);
Serial.begin(115200);
Serial.println("AS3935 Franklin Lightning Detector");
//SPI.begin()
Wire.begin(); // Begin Wire before lightning sensor.
if( !lightning.begin() ) { // Initialize the sensor.
//if( !lightning.beginSPI(9, 2000000){ // Uncomment for SPI.
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, if you plan on using this outdoors
// uncomment the following line:
//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.");
//reduceNoise(); //See note below above reduceNoise function.
}
else if(intVal == DISTURBER_INT){
Serial.println("Disturber.");
}
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); //Let's not be too crazy.
}
// This function helps to adjust the sensor to your environment. More
// environmental noise leads to more false positives. If you see lots of noise
// events, try increasing the noise threshold with this function. I put the
// function call under the if statement checking for noise. The datsheet
// warns that smartphone and smart watch displays, DC-DC converters, and/or
// anything that operates in 500 kHz range are noise sources to be avoided.
void reduceNoise(){
++noiseFloor; // Manufacturer's default is 2 with a max of 7.
if(noiseFloor > 7){
Serial.println("Noise floor is at max!");
return;
}
Serial.println("Increasing the event threshold.");
lightning.setNoiseLevel(noiseFloor);
}
Interesting. I am not entirely sure what is going on here as I cannot replicate this error when testing five boards pulled from our stock. One weird thing TS-Chris found with his Lightning Sensor is for whatever reason, after running the I2C scan and then re-uploading the basic example, that fixed the start-up issue.
For the problem with the boards you guys have here, does the “Lightning Detector did not start up, freezing!” error persist even after resetting/power-cycling the circuit or re-uploading the examples? Similarly, does the error show up on all three examples?
One other suggestion that might help is to adjust [the delay on this line of the .cpp file for the Arduino library to increase that delay to, say, 5 or 6ms. The timing should be correct per the datasheet but it might help here to give the AS3935 more time to start up before the code freezes.
Sorry about the ‘attached’ code. Looks like I forgot to attach it! (You did locate the correct sketch though.)
Hmmm, you have everything connected correctly and the board is responding the way it should in the I2C scanner sketch. We’re starting to think there is a timing issue causing the board to not be detected by our sample code. I’d like to get your board back to run some tests on. Did you order this directly from SparkFun or from another vendor?
I also ran “i2c_scanner” and it showed presence of a device at an address of 0x03. Running “i2c_scanner” did not fix the problem. I’ve tried all three examples using i2c and all exhibit the startup issue. I also tried changing the “delay(4)” to “delay(6)” in the library for the AS3935 and that made no difference.
I have not tried SPI.
By the way, while looking at the library code, I found the following code:
Hmm, you may be correct here regarding the setting function. I will look into that and forward that information on to the engineer. As for your specific board, I would like to have it sent back to SparkFun for testing to see if we can identify the issue here.
Assuming you purchased the board directly from SparkFun, please fill out the form on [this page and in the “Why do you want an RMA?” box, enter a brief description of the issue and link this thread and we will follow-up with further instructions.](Return Policy - SparkFun Electronics)