Coder Social home page Coder Social logo

sparkfun_as3935_lightning_detector_arduino_library's Introduction

SparkFun AS3935 Lightning Detector Arduino Library

SparkFun AS3935 Lightning Detector

SparkFun AS3935 Lightning Detector (SEN-15441)

Repository Contents

  • / examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
  • /src - Source files for the library (.cpp, .h).

Documentation

Products that use this Library

License Information

This product is open source!

Please review the LICENSE.md file for license information.

Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release under the same license.

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_as3935_lightning_detector_arduino_library's People

Contributors

bboyho avatar cmfrancis avatar edspark avatar fourstix avatar mday64 avatar per1234 avatar santised avatar sfe-sparkfro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sparkfun_as3935_lightning_detector_arduino_library's Issues

SPI Code is off by 1 bit

The documentation shows that bits 5:1 is used for indoor and outdoor and should be 10010 and 01110. This combined with the other bits would now be 100100 (0x24) and 011100 (0x1C). Bit zero is missing from all the SPI reads.

For example, if you power down the unit by writing a 1 to bit zero in register zero the unit powers down and if you read it back it should read back that bit zero is now a 1 but it doesn't.

I proved this by reading back 9 bits instead of just 8 and did get the zero bit to show up as a 1.

This is another case of what?

For the most part I guess everything should work but some values are going to be wrong because the zero bit is not read. For example the distance values.

Mike

Isn't ZERO a valid setting?

Subject of the issue

Looking at the datasheets, shouldn't the valid settings include ZERO, e.g., noisefloor?

Steps to reproduce
setNoiseLevel(0);

Expected behavior
Valid setting

Actual behavior
Argument ignored.

void SparkFun_AS3935::setNoiseLevel( uint8_t _floor )
{
  if( (_floor < 1) || (_floor > 7) )
    return; 
  
  _writeRegister(THRESHOLD, NOISE_FLOOR_MASK, _floor, 4); 
}

shouldn't this be?:

void SparkFun_AS3935::setNoiseLevel( uint8_t _floor )
{
  if( (_floor < 0) || (_floor > 7) )
    return; 
  
  _writeRegister(THRESHOLD, NOISE_FLOOR_MASK, _floor, 4); 
}

Quoting datasheet:

Table 16. Settings for the Noise Floor Threshold
Continuous Input Noise Level
[μVrms] (outdoor)
Continuous Input Noise Level
[μVrms] (indoor) REG0x01[6] REG0x01[5] REG0x01[4]
390 28 0 0 0
630 45 0 0 1
860 62 0 1 0
1100 78 0 1 1
1140 95 1 0 0
1570 112 1 0 1
1800 130 1 1 0
2000 146 1 1 1

Wake up does not write to register 0x08 bit 5 1, wait 2ms then write 0 after calibration

Hi,

  1. I noticed that the wakeUp() routine does not write to register 0x09 bit 5 after the Calibration command, like the datasheet on page 23, Section 8.11 says it should.

Here's the text from the datasheet.

If the AS3935 is set in power-down mode, the TRCO needs to be recalibrated using the following procedure:

  1. Send Direct command CALIB_RCO
  2. Modify REG0x08[5] = 1
  3. Wait 2ms
  4. Modify REG0x08[5] = 0

I added the reg 0x08 bit 5 write 1, wait 2ms, write 0 logic to my python port of your Arduino code and it seems to work fine. I also compared with similar code in the pcfens/RPi_AS3539 python project calibration routine and I noticed that code has the bit 5, write 1, wait 2ms, write 0 logic. I have tested my python code with both SPI and I2C. I wonder if this should be added to the Arduino code as well, so I opened this issue to let you know.

I also have a couple more questions.

  1. I can't find CALIB_SRCO register 0x3B documented anywhere in the datasheet. However I do get a value that indicates true after calibration, so I went ahead and kept the check in the ported code. It seems to work fine, and I'm guessing you have documentation, and that's why the code checks this byte. Is that correct?

  2. The pcfens/RPi_AS3539 code has a calibrate() and reset() routines. That seemed like a good idea to make these available for tuning, so I added these to the ported python code. You might want to add them to the Arduino code, as they are trivial and reuse code you already have.

If you'd like to take a look a the CircuitPython port, it's available at
fourstix/Sparkfun_CircuitPython_QwiicAS3935
Your comments and suggestions are welcome. I hope to release it to the CircuitPython community bundle soon.

SPI port speed increases after lightning.beginSPI

Using an ATmega328P, internal 1 MHZ osc., the SPI bus works fine with all other components
like LCD-displays etc. up to the moment where the statement
lightning.beginSPI(spiCS, 2000000)
seems to mess up the speed of the SPI port, checked that with an oscilloscope. Much too fast now, i.e. for the LCD-display, only garbled characters.
After having a look at the source file of this lib, I found this routine:

bool SparkFun_AS3935::beginSPI(uint8_t user_CSPin, uint32_t spiPortSpeed, SPIClass &spiPort) 
{
  // Startup time requires 2ms for the LCO and 2ms more for the RC oscillators
  // which occurs only after the LCO settles. See "Timing" under "Electrical
  // Characteristics" in the datasheet.  
  delay(4);
  // I'll be using this as my indicator that SPI is to be used and not I2C.   
  _i2cPort = NULL; 
  _spiPort = &spiPort; 
  _spiPortSpeed = spiPortSpeed; // Make sure it's not 500kHz or it will cause feedback with antenna.
  _cs = user_CSPin;
  pinMode(_cs, OUTPUT); 
  digitalWrite(_cs, HIGH);// Deselect the Lightning Detector. 
  _spiPort->begin(); // Set up the SPI pins. 

  // Bit order is different for ESP32
#ifdef ESP32 
    SPI.setBitOrder(SPI_MSBFIRST);
#else
    SPI.setBitOrder(MSBFIRST);
#endif
  return true; 

So, what is "spiPortSpeed" ? 2000000 (like in the expample) meaning 2000000 Hz -> 2MHz ?!
What are valid values for this parameter ?
And the third parameter of the function call "SPIClass &spiPort" is never mentioned in the examples nor explained.
Trying to slow the SPI down again with
SPI.setClockDivider(SPI_CLOCK_DIV64);
(or values of 8, 16, 32, ... 128) doesn't seem to have any effect now. Works fine before
lightning.beginSPI(spiCS, 2000000) is issued.

Any idea how not to mess up the SPIport (speed) or how to set it correctly in this lib ?

Regards, Greece2

How to modify this library to work with particle argon (or photon)

Subject of the issue

Library doesn't compile on Particle Argon

Expected behavior

If I include the .cpp and .h files and try to compile on an argon, I would like for it to compile so I can use this library

Actual behavior

Throws a tonne of errors, starting with:
n file included from ../platform/MCU/nRF52840/inc/hw_config.h:11:0,
from ../hal/inc/usb_hal.h:43,
from ../wiring/inc/spark_wiring_usbserial.h:32,
from ./inc/application.h:51,
from ./inc/Particle.h:5,
from ./inc/Arduino.h:11,
from ./inc/Wire.h:1,
from lib/SparkFun_AS3935_Lightning_Detector_Arduino_Library/src/SparkFun_AS3935_Lightning_Detector_Arduino_Library.h:4,
from lib/SparkFun_AS3935_Lightning_Detector_Arduino_Library/src/SparkFun_AS3935_Lightning_Detector_Arduino_Library.cpp:12:
../platform/MCU/nRF52840/inc/hw_system_flags.h:32:33: error: expected identifier before numeric constant
#define RESET 0
^
lib/SparkFun_AS3935_Lightning_Detector_Arduino_Library/src/SparkFun_AS3935_Lightning_Detector_Arduino_Library.h:27:3: note: in expansion of macro 'RESET'
RESET = 0x3C,
^
../platform/MCU/nRF52840/inc/hw_system_flags.h:32:33: error: expected '}' before numeric constant
#define RESET 0

Error when compiling with 1.4.7

Subject of the issue

I get the following error when compiling with the 1.4.7 with platformio. This does not happen in 1.4.6

Steps to reproduce

Adding the dependency to platformio.ini

lib_deps = 
    https://github.com/sparkfun/SparkFun_AS3935_Lightning_Detector_Arduino_Library.git#v1.4.7

Expected behavior

The code should compile.

Actual behavior

The build fails with the following error.

.pio/libdeps/esp32doit-devkit-v1/SparkFun AS3935 Lightning Detector Arduino Library/src/SparkFun_AS3935.cpp: In member function 'void SparkFun_AS3935::setIndoorOutdoor(uint8_t)':
.pio/libdeps/esp32doit-devkit-v1/SparkFun AS3935 Lightning Detector Arduino Library/src/SparkFun_AS3935.cpp:96:8: error: expected '(' before '!' token
     if !(((_setting == INDOOR) xnor (_setting == OUTDOOR)))
        ^
        (

malformed if() clauses

In the library code, there are some instances of IF statements at the beginnings of methods to check for legal values. For example, checking if parameter "a" is one of the legal values 1 or 2:

if ((a!=1) | ( a!=2)) return;

Those IF statements can never be true because of the bitwise OR operator. As a result, those methods always silently return without doing anything.

Compile Error: SPI.setBitOrder(MSBFIRST)

Subject of the issue

Working with example code Example1_BasicLightening_SPI get following error on compile:

/Users/bobbysmith/Dropbox/Arduino/libraries/SparkFun_AS3935_Lightning_Detector_Arduino_Library/src/SparkFun_AS3935.cpp: In member function 'bool SparkFun_AS3935::beginSPI(uint8_t, uint32_t, arduino::SPIClass&)':
/Users/bobbysmith/Dropbox/Arduino/libraries/SparkFun_AS3935_Lightning_Detector_Arduino_Library/src/SparkFun_AS3935.cpp:58:9: error: 'class arduino::MbedSPI' has no member named 'setBitOrder'
     SPI.setBitOrder(MSBFIRST);
         ^~~~~~~~~~~
exit status 1
Error compiling for board Arduino Nano 33 BLE.

Your workbench

Arduino Nano BLE: nRF52840 from Nordic Semiconductors, a 32-bit ARM® Cortex™-M4 CPU running at 64 MHz

Works perfectly using SAMD based boards

I think this needs the same updates Adafruit has completed in their Adafruit_usIO library to account for how the nRF52840 handles SPI.

  • What version of hardware or breakout board are you using?

V2 of the Sparkfun board purchased less than 1 month ago

  • How is the breakout board wired to your microcontroller?

standard HW SPI - CS on D10 and INT on D6

Disturbers not being masked

Subject of the issue

Getting lots of disturbers on the serial output. Even with mask disturbers being true. Using code revision 1e1a717
Haven't detected any lightning events even with a storm passing by. Wondering if something isn't configured correctly.

Your workbench

  • What development board or microcontroller are you using?
    Arduino Nano
  • What version of hardware or breakout board are you using?
    Sparkfun AS3935 SEN-15441
  • How is the breakout board wired to your microcontroller?
    SPI
  • How is everything being powered?
    PC USB
  • Are there any additional details that may help us help you?

Steps to reproduce

Tell us how to reproduce this issue. Please post stripped down example code demonstrating your issue.
Using "Example2_More_Lightning_Features_SPI

lightning.maskDisturber(true);

Expected behavior

Not see Disturber events on the serial output

Actual behavior

AS3935 Franklin Lightning Detector
Schmow-ZoW, Lightning Detector Ready!

Are disturbers being masked: YES
Are we set for indoor or outdoor: Indoor.
Noise Level is set at: 3
Watchdog Threshold is set to: 2
Spike Rejection is set to: 2
The number of strikes before interrupt is triggerd: 1
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.
Disturber.

Lightning Energy Function Errors

Looks like bits are not being shifted correctly to get the correct value. Check that the variable is not being over shifted and that the mask is masking the correct amount of bits.

Missing license file

I would like to use or if needed, provide a Particle library for this chip using SPI. Right now, you are missing a license file, and I can't exactly glean which license I could use which means I can't create a Particle library. Can you please update the repository with a correct license? Alternatively, can you please provide an official searchable Particle library for use with their build tools? Thank you.

maskDisturber function didn't set bit

Subject of the issue

The disturber masking bit is not set, no matter if i set the value true or false. After i commented out the if statement lines in the file "SparkFun_AS3935.cpp".

if ((_state == true) xor (_state == false))

// REG0x03, bit [5], manufacturere default: 0.
// This setting will change whether or not disturbers trigger the IRQ Pin.
void SparkFun_AS3935::maskDisturber(bool _state)
{
// if ((_state == true) xor (_state == false))
// return;

_writeRegister(INT_MASK_ANT, DISTURB_MASK, _state, 5);

}

After that the bit got set correct.

Your workbench

  • What development board or microcontroller are you using?
    ATSAMD21G18 based MCU

  • How is the breakout board wired to your microcontroller?
    AS3935 is connected via I2C.

  • How is everything being powered?
    doesn't matter

Esp32 compiling error

Hi, I am running version 1.3.3 of this library, but it is still not compiling and is coming up with the following error.

I am having this issue on an esp32, no modifications to the example script except the interrupt pin number.

Arduino: 1.8.9 (Windows 10), Board: "Adafruit ESP32 Feather, 80MHz, 921600, None"

Example2_More_Lightning_Features_I2C:33:38: error: invalid conversion from 'int' to 'SF_AS3935_I2C_ADDRESS' [-fpermissive]

SparkFun_AS3935 lightning(AS3935_ADDR);

                                  ^

In file included from C:\Users\x\Documents\Arduino\libraries\SparkFun_AS3935_Lightning_Detector_Arduino_Library\examples\Example2_More_Lightning_Features_I2C\Example2_More_Lightning_Features_I2C.ino:19:0:

C:\Users\x\Documents\Arduino\libraries\SparkFun_AS3935_Lightning_Detector_Arduino_Library\src/SparkFun_AS3935.h:77:5: note: initializing argument 1 of 'SparkFun_AS3935::SparkFun_AS3935(SF_AS3935_I2C_ADDRESS)'

 SparkFun_AS3935(enum SF_AS3935_I2C_ADDRESS address);

 ^

exit status 1
invalid conversion from 'int' to 'SF_AS3935_I2C_ADDRESS' [-fpermissive]

SPARKFUN LIGHTNING DETECTOR - AS3935 - RADIO INTERFERENCE FROM ESP32 SPI BUS - HOW TO OVERCOME?

Subject of the issue

I am running a SparkFun Lightning Detector - AS393527 SEN-15441, connected to a SparkFun Thing Plus - ESP32 WROOM (USB-C) WRL-20168. All activity on the SPI bus (VSPI or HSPI) MOSI pin causes the AS3935 to generate disturbers and/or false lighting strikes - which exactly coincide with the activity on the SPI MOSI pin.

How can I overcome the SPI-caused interference? Note that I have tried methodically adjusting all parameters on the AS3935. Makes no difference.

Your workbench

  • What development board or microcontroller are you using? SparkFun Thing Plus - ESP32 WROOM (USB-C) WRL-20168
  • What version of hardware or breakout board are you using? Unknown
  • How is the breakout board wired to your microcontroller? Breadboard & short jumpers
  • How is everything being powered? Either 5VDC regulated supply or 1 cell LiPo (makes no difference)
  • Are there any additional details that may help us help you? Please see below...

I am running a SparkFun Lightning Detector - AS393527 SEN-15441, connected to a SparkFun Thing Plus - ESP32 WROOM (USB-C) WRL-20168. The SPI bus (VSPI) is connected to and successfully talking with the AS3935 board. VSPI is also connected to and talking with the ESP32 on-board SD card (so I can datalog lightning strikes). I set up WiFi to set the time (NTP). Data is logged with Unix time stamps. I also connected the VSPI bus to a small TFT display. All features work as intended, except that I have proven (through process of elimination) that whenever the ESP32 sends data out the VSPI MOSI pin for the SD-Card or the TFT display it results in many disturbers and/or false lighting strikes. If I remove the SD-card and TFT code I get zero distrubers or false strikes. I changed VSPI bus speed in case it was a harmonic sending noise up the line or via RFI. I tried moving the TFT onto the HSPI bus but it made no difference. I attempted to move the AS3935 onto the HSPI bus (so does not share with SD card SPI) but could find find in the SparkFun_AS3935_Lightning_Detector_Arduino_Library how to redesignate SPI Pins.

Steps to reproduce

When any activity occurs on the ESP32 SPI bus pins, the AS3935 reliably gives false disturbers and/or false lightning strikes at the exact time there is activity on the SPI MOSI pin.

Expected behavior

The AS3935 should not give false distrubers or strikes, given that it is being operated away from common sources of RFI

Actual behavior

The AS3935 gives false disturbers and/or false lightning strikes rendering it useless

Full code can be found on https://forum.sparkfun.com/viewtopic.php?f=74&t=61502&p=249026#p249026
(Issue #248948). The code is almost 1000 lines so too long to paste here - but I do not think the coding will change the SPI RFI problem? Header information below...

// Nick Milton
String VersionNo = "46a";
String VersionDate = "28/04/2024";
// Version 28 is 1st version close to production ready
// Version 30 notifies user if ESP32 goes into WiFi AP rather than STA mode
// Version 31 - housekeeping on timers
// Version 37 added fn UpdateAllTimes() and call every 1 second (rather than only when AS3935 has an event)
// Version 41 testing live input from webpage to change AS3935 settings live . See https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/
// Version 41a the code added in 40 WORKS. Use 40 as the starting point and build itterations as letters until I get it integrated into my project
// V41b - adding 7 parameters for webupdate > modify A3935 settings after boot
// V41c - add IP address to startup screen. This version I have got working an ESP32 webpage to update AS3935 parameters remotely (but does not retain to NV memory or SD card file)
// V42 - play with alternative approach that uses physical buttons/switches NOT WiFi to adjust settings - so I can shut down WiFi after successful NTP time sync (adding state machine to see if this helpd do this)
// V43 - simplify ie get rid of live input from webpage. Set up simple input from local buttons. Aim - no WiFi once NTP timesync acchieved
// V43 - rebuild & simplify ie get rid of live parameter input from webpage. Set up simple input from local buttons to adjusr AS3935 params. Disable WiFi once NTP timesync acchieved to see if decreases false alerts
// Notes - when I put a 1 metre extension cable onto the AS3935 board it stopped the SPI working for SD Card and for the LCD screen - but the AS3935 SPI kept working. I think the wire is too long to work properly on shared SPPI bus
// Results - 1m cable does not decrease false alerts but does bugger SPI bus. Consdier no-WiFi version on the ESP32 and add an RTC?
// When I load a version of this code with no WiFi or LCD it seems to have far fewer false alarms even though I disabled WiFi (or did I?) in this version once clock is set
// V43b reinstated normal WiFi & NTP code so does not stop it running, but in this version DISABLED all LCD code in case it is this causing RFI.
// Result - get almost no false alerts or distrubers! So something to do with LCD SEEMS to be the culprit! Unplugging LCD from 3V3 pin does not make false alerts go away when running V44 of the code (which has LCD enabled)

// V44 WiFi enabled (cuts off after NTP sync success), LCD enabled, SD card enabled. Suffers huge number of false alerts

// V45 Move the LCD onto the second SPI ESP32 bus in case having AS3935, SD Card & LCD all on same bus is causing the false alerts
// RESULT - NO DIFFERENCE. STILL GET CTS distrubers and ALERTS - so it seems that the LCD code is cauing grief

// Finding 1 - if LCD code is removed then I get no false alerts even if LCD still connected & WiFI and SD card up and running
// Finding 2 - if LCD code remains in place and LCD power connected OR disconnected I still get false alerts
// Finding 3 - R45 code. If LCD is moved to it's own SPI bus then (with LCD code still in place and LCD connected or with all LCD wiring completely removed from the ESP32) I STILL GET many false alerts

// ***Fluke Finding - Running R45 code I noticed the EDP32 RGB LED (which I told to flash blue when AS3935 interrupts) flashes at exactly the SAME time as GPIO13 (on-board LED) which just happends to be the SPI bus#2 MOSI output.
// In other words whenever the ESP32 sends data down the MOSI line to the LCD (whether LCD connected or not) it causes huge number of false distrubers & strikes!

// SUMMARY - the LCD code generates MOSI data for the LCD which somehow is causing the false alerts even if on it's own SPI bus. Is this perhaps a harmonic of the AS3935 Rx? SPI_FREQUENCY was set to 40,000,000 for the LCD. If I set to 1,000,000 still get FTI
// FINDING 4 - Seems I need to either find a new TFT library (unliley will change anything) or a new non-graphic display (perhaps I2C LCD) which just sends the characters down the line not high-speed data

// V46 Base on V45, with
// (1) all TFT LCD libraries/code/calls commented out (to be replaced by LCD I2C display in time).
// (2) LiPo code added back in
// (3) SD card code retained
// (4) WiFi and NTP sync code retained and NOT stopped after 1st successful NTP time sync
// (5) Added RBG flashes to show when SD card write occurs
// (6) Added ORANGE to RGB status LED
// (7) Added 13 second log events to see if the SD card activity (on SPI) causes false triggers. IT DOES! Try putting the AS3935 onto the HSPI SPI bus so does not share with the SD card. See line 537

// ***New Finding - now that the TFT display and code are gone I can see that whenever the ESP32 accesses the SDCard over SPI bus it triggers disturbers & some false lignting events

//V46a disable all SD card writes (comment out the contents of the datalog fn) to see if get nil false alerts or disturbers
// Result - works perfectly ie no disturbers or noise or false alerts. So the ESP32 SPI bus seems to send noise up the line or impose leaky RFI all over the AS3935.

/*
Description_______________

~ SparkFun_AS3935 lightning detector + SparkFun ESP32 Thing Plus C + 1.69inch LCD Module.
~ Based in part on code by Elias Santistevan SparkFun Electronics July 2019 & code examples in the libraries below
~ need to tidy up whole progam now and to add a state machine to handle loss of Wifi or NTP sync Add h/w interrupts & routines to check WiFi and NTP still connected/working

Key features
~ Franklin AS3935 board talks to ESP32 over SPI
~ ESP32 onboard RGB LED in use as a basic status indicator
~ ESP32 onboard SD card used to log event data + timestamps as Epoch. Each time ESP32 restarts creates new file names 'datalog_' + UnixTime + '.txt'
~ WiFi manager AP and STA mode support - WiFiManager sets up STA mode via temp AP mode
~if I restart ESP32 after flush (and I do not enter new credentials, or if I enter invalid credentials for my WiFi network) then on reboot it will enter AP mode.
~if there is no WiFi network to join I want it to then allow AP mode to timeout and have it continue to boot ESP32 with no network connected - rather than have cts cycle to AP mode
~ NTP time sync then WiFi shutoff (to prevent RFI)
~ Monitoring of MAX17048 LiPo fuel gauge stats

Wiring
SPI for reference..
SPI Bus 1 (VSPI) and 2 (HSPI)
SPI MOSI MISO SCLK CS
VSPI GPIO 23 GPIO 19 GPIO 18 GPIO 5
HSPI GPIO 13 GPIO 12 GPIO 14 GPIO 15

SPI bus 1 (VSPI) used for SD card & AS3935
Sparkfun AS3935 pins USE Sparkfun ESP32 Thing Plus C pins
MOSI SPI ESP>Lignthing GPIO23 (MOSI aka VSPID aka PICO)
MISO SPI ESP<Lignthing GPIO19 (MISO aka VSPIQ aka POCI)
SCK SPI Master clock > Lignthing GPIO18 (SCK)
CS SPI Master > select slave GPIO25
INTERUPT Inst DO Lightning > ESP32 GPIO32
3V3 Power from ESP23 > Lightning 3V3
GND Power and signal ground GND

SPI bus 1 (HVSPI) if used for AS3935. Not sure if it can be. SEE BELOW OPTION
1.69' LCD Display wiring (ST7789V2, Display IPS, 240 X 280)
Display USE WIRE COLOUR ESP32 REMARK
VCC 3.3V purple 3.3V Supply to the LCD
GND GND white GND Common
DIN MOSI green GPIO23 Shared with AS3935 & also with the SD card. Should I use the 2nd SPI bus instead? How to define?
MISO GPIO19* Not used by LCD but is set by SPI bus
CLK SCLK orange GPIO18 SPI clock
CS yellow GPIO15 Slave select. Set low to select
DC blue GPIO33 Data/command control pin. Set 0 to write command. Set 1 to write data
RST brown GPIO27 pull low to reset when powered LCD on
BL grey GPIO26 LCD backlight control.

SPI bus 2 (HSPI) used if used for LCD * AS3935
1.69' LCD Display wiring (ST7789V2, Display IPS, 240 X 280)
Display USE WIRE COLOUR ESP32 REMARK
VCC 3.3V purple 3.3V Supply to the LCD
GND GND white GND Common
DIN MOSI green GPIO13 use the 2nd SPI bus instead
MISO GPIO12* Not used by LCD but is set by SPI bus
CLK SCLK orange GPIO14 SPI clock
CS yellow GPIO15 Slave select. Set low to select
DC blue GPIO33 Data/command control pin. Set 0 to write command. Set 1 to write data
RST brown GPIO27 pull low to reset when powered LCD on
BL grey GPIO26 LCD backlight control.

// MyDisplay text arrangement
Row Use
1 LIGHTNING
2 not used
3 Time in red of strike
4 Range in red of strike
5 Time of day in white
6 Disturber in blue or Noise in yellow
7 Time of disturber (in blue) or noise (in yellow)
Text 2 font spaced 20 pixes apart (y). Get around N characters/line
Text 4 font spaced 30 pixes apart (y). Get around N characters/line

ESP32 ob-board LED
~ PowerLED red
~ GPIO13 LED blue - shows WiFiManager reset button state
~ LiPo charge LED yellow
~ WS2812 RGB LED for which colours have following meanings:
GREEN - AS3935 connected
RED - lightning detected - flash during operation
YELLOW - radio noise
BLUE - radio distruber
WHITE - SD card file create or file append
PURPLE - NTP time sync success
ORANGE - NTP time sync fail

Buttons & switches:
GPIO13 MOM push button > reset WiFiMAnager STA credentails
GPIO16 BUTTON - LONG (1 Sec) push toggle from RUN <> CONFIG mode. SHORT push SCROLL through all config items in a loop
GPIO21 & GPIO22 UP/DOWN SWITCH - press up to increase menu item value, or down to decrease value

Problem with tuneCap() and readTuneCap()

I found an issue with tuneCap() and the mask used to set the AS3935 bits in register 0x08. If I edit Example 3 and change the code to set tuneCap to a value of 2 (for 16pf). When the code reads the value back with readTuneCape() it reports 88pf instead of 16. I traced the issue back to an incorrect value of the CAP_MASK in Sparkfun_AS3935.h. The value should be 0x0F, not 0xF0 to match the register map in the data sheet. Also I found a small error, in the readTuneCap() where the value read was anded with Not value of the mask, instead of the value of the mask. I will create a pull request with my changes. I have fixed these two error in my fork and tested them, and the code now works as expected.

Error Compiling: 'SPISettings()' was not declared in this scope

Complier can't find the function "SPISettings(_spiPortSpeed, MSBFIRST, SPI_MODE1)" in line 468: _spiPort->beginTransaction(SPISettings(_spiPortSpeed, MSBFIRST, SPI_MODE1));
Same issue on line 491.

I searched to code and example, couldn't find the function. Is it in one of the libraries?

OUTDOOR setting not working with ESP32-S3 and SPIClass

I'm using a Heltec Stick Lite ESP32-S3 LoRa module and I can set and check all of the settings apart from the INDOOR/OUTDOOR setting. I need to use the HSPI class as the LoRa module uses the SPI class. I've tried different baud rates with no success. The other settings can be changed and read back successfully. I've used the same sensor with a plain ESP32 on the default SPI port and everything worked properly including INDOOR/OUTDOOR.

Any ideas or help appreciated, thank you.

Your workbench

  • What development board or microcontroller are you using? Heltec Stick Lite ESP32-S3
  • What version of hardware or breakout board are you using? Thunder Click V1.01
  • How is the breakout board wired to your microcontroller? Soldered screw terminals and ribbon cable
  • How is everything being powered? USB port from PC for now
  • Are there any additional details that may help us help you? Arduino IDE 1.8.19, ESP32S3 Dev Module, ESP32 Core V2.0.14, Debug level Verbose

Steps to reproduce

This is the More Lightning Settings SPI example with HSPI added.

#include <SPI.h>
#include "SparkFun_AS3935.h"

#define INDOOR 0x12 
#define OUTDOOR 0xE
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
#define NOISE_INT 0x01

SparkFun_AS3935 lightning;

const int lightningInt = 4;  
int spiCS = 7;
#define MISO  19
#define MOSI  21
#define SCK 17

SPIClass * hspi = NULL;
 
byte noiseFloor = 2;
byte watchDogVal = 2;
byte spike = 2;
byte lightningThresh = 1; 

byte 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");

  hspi = new SPIClass(HSPI);
  hspi->begin(SCK, MISO, MOSI, spiCS);
  pinMode(spiCS, OUTPUT);

  if( !lightning.beginSPI(spiCS, 1000000, *hspi) ) { 
    Serial.println ("Lightning Detector did not start up, freezing!"); 
    while(1); 
  }
  else
    Serial.println("Schmow-ZoW, Lightning Detector Ready!\n");

  // "Disturbers" are events that are false lightning events. If you find
  // yourself seeing a lot of disturbers you can have the chip not report those
  // events on the interrupt lines. 

  lightning.maskDisturber(true); 

  int maskVal = lightning.readMaskDisturber();
  Serial.print("Are disturbers being masked: "); 
  if (maskVal == 1)
    Serial.println("YES"); 
  else if (maskVal == 0)
    Serial.println("NO"); 

  // The lightning detector defaults to an indoor setting (less
  // gain/sensitivity), if you plan on using this outdoors 
  // uncomment the following line:

  lightning.setIndoorOutdoor(OUTDOOR); 

  int enviVal = lightning.readIndoorOutdoor();
  Serial.print("Are we set for indoor or outdoor: ");  
  if( enviVal == INDOOR )
    Serial.println("Indoor.");  
  else if( enviVal == OUTDOOR )
    Serial.println("Outdoor.");  
  else 
    Serial.println(enviVal, BIN); 

  // Noise floor setting from 1-7, one being the lowest. Default setting is
  // two. If you need to check the setting, the corresponding function for
  // reading the function follows.    

  lightning.setNoiseLevel(noiseFloor);  

  int noiseVal = lightning.readNoiseLevel();
  Serial.print("Noise Level is set at: ");
  Serial.println(noiseVal);

  // Watchdog threshold setting can be from 1-10, one being the lowest. Default setting is
  // two. If you need to check the setting, the corresponding function for
  // reading the function follows.    

  lightning.watchdogThreshold(watchDogVal); 

  int watchVal = lightning.readWatchdogThreshold();
  Serial.print("Watchdog Threshold is set to: ");
  Serial.println(watchVal);

  // Spike Rejection setting from 1-11, one being the lowest. Default setting is
  // two. If you need to check the setting, the corresponding function for
  // reading the function follows.    
  // The shape of the spike is analyzed during the chip's
  // validation routine. You can round this spike at the cost of sensitivity to
  // distant events. 

  lightning.spikeRejection(spike); 

  int spikeVal = lightning.readSpikeRejection();
  Serial.print("Spike Rejection is set to: ");
  Serial.println(spikeVal);


  // This setting will change when the lightning detector issues an interrupt.
  // For example you will only get an interrupt after five lightning strikes
  // instead of one. Default is one, and it takes settings of 1, 5, 9 and 16.   
  // Followed by its corresponding read function. Default is zero. 

  lightning.lightningThreshold(lightningThresh); 

  uint8_t lightVal = lightning.readLightningThreshold();
  Serial.print("The number of strikes before interrupt is triggerd: "); 
  Serial.println(lightVal); 

  // When the distance to the storm is estimated, it takes into account other
  // lightning that was sensed in the past 15 minutes. If you want to reset
  // time, then you can call this function. 

  //lightning.clearStatistics(); 

  // The power down function has a BIG "gotcha". When you wake up the board
  // after power down, the internal oscillators will be recalibrated. They are
  // recalibrated according to the resonance frequency of the antenna - which
  // should be around 500kHz. It's highly recommended that you calibrate your
  // antenna before using these two functions, or you run the risk of schewing
  // the timing of the chip. 

  //lightning.powerDown(); 
  //delay(1000);
  //if( lightning.wakeUp() ) 
   // Serial.println("Successfully woken up!");  
  //else 
    //Serial.println("Error recalibrating internal osciallator on wake up."); 
  
  // Set too many features? Reset them all with the following function.
  // lightning.resetSettings();

}

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."); 
    }
    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 previously seen events. 
      byte distance = lightning.distanceToStorm(); 
      Serial.print("Approximately: "); 
      Serial.print(distance); 
      Serial.println("km away!"); 

      // "Lightning Energy" and I do place into quotes intentionally, is a pure
      // number that does not have any physical meaning. 
      long lightEnergy = lightning.lightningEnergy(); 
      Serial.print("Lightning Energy: "); 
      Serial.println(lightEnergy); 

    }
  }
}

Expected behavior

The INDOOR/OUTDOOR setting should change to OUTDOOR

Actual behavior

The INDOOR/OUTDOOR setting remains on INDOOR

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.