ESPHome with AS3935 Franklin Lightning Sensor - try increasing the spike rejection value!

I recently ran across this interesting little sensor and it really made me curious. Not sure if you guys have seen this extremely thorough analysis of the AS3935 sensor here. It looks like it’s a pain to set up, because it needs to be at least 10m from any RF noise source like computers and is very picky about noise on the power supply. But from the guys results, it actually looks like it’s rather precise once set up correctly ! Now he does play around with all kind of internal settings, some of them poorly documented. Not sure how much of that is exposed by esphome.

I’m tempted to try this thing out lol.

That sounds like a communication issue more than anything else. Have you done any more tests since or did the thing end up in your trash ?

I have one that is out on my deck, just about as far from computers and whatnot as it could be (40’ cat five from the Wemos D1 mini that drives it). I’ve still never seen it give me anything. The other ones I bought hoping they’d be different sit on my workbench.

If you can get it to work, please let me know. I’d love to know what I’m doing wrong. :smiley:

1 Like

I know I’m going to regret this and I’ll waste way too much time than reasonable on that thing, but I just ordered a cheapo clone on Ali (the Sparkfun was too expensive for something that is probably not going to work). This sensor is too fascinating to pass :grinning: We have a lot of thunderstorms here in the summer so I’ll have plenty of opportunities to test ! So hopefully some results in a few months…

I got one of these devices not knowing the issues I would encountered (The cheap ones I suppose)

It’s the GY-AS3935. I’m assuming some register masks may not be correct for this specific device? Not sure but yea… storm right now and it’s only coming up with “Unknown” for the readings. I would have thought that as it has the same chip, it would have functioned the same :x

Can this work with an ESP32 too? :thinking:

I’ve got 5 of them lying around so if I could avoid to buy again…

OK, I can confirm that these things just don’t work. I have one connected to the lowest noise MCU I could find, an Arduino powered by a battery. The thing is on a post in the middle of a field, more than 800m from any interfering electronics. We just had a heavy thunderstorm go right over our heads. Constant lightning strikes all around, one even struck one of my neighbors trees.

My AS3935 (clone) detected - absolutely nothing except some noise :roll_eyes:

Maybe it’s the clones that are just broken, I don’t know.

For reference, that is the thing that went over us. If the AS can’t even detect something like this, I don’t know what will make it trigger…

(From https://map.blitzortung.org)

1 Like

Thanks for confirming. It’s sad that they’re around $30 and still available for curious people to buy into when they just don’t do what they’re designed to do.

Thanks man you just saved my money and my time !!!

Au passage un p’tit “coucou” de Normandie :wink:

I have gotten these to work with some other platforms, but so far with esphome.io and Home Assistant they are pretty much a no go. I have tuned everything (antenna etc) but so far nothing. I have written drivers for these for other platforms so I’ll take a look at the code and see what is happening, but they are a finicky chip at the best of times. I do have some of the original test/diagnostic tools from AMS so I’ll try to find those as well.

2 Likes

wish I had seen this post before wasting my money and time

Welcome to the club. We have matching jackets.

I recommended using the HACS Blitzortung integration instead.

I will give that a try. I got my station all designed and put together and thought maybe I just missed something or was doing something wrong until I came across this post. I plan on keeping the sensor in place on the circuit board and maybe somewhere in the future someone will figure it out.


7 Likes

hoping to get the station put up on the tower today. It is going up on a 55ft armature radio tower that sits next to my house

Hi!

I also have the topic with disturbers. Since the datasheet talks about tuning the antenna, I looked at the Sparkfun AS3935 library example 3 to figure out at which frequency my board is tuned. Originally I had – as you can see from the screenshot


around 550kHz (1/29,1µs * 16 (divider)) which is much too high given that the datasheet talks about 500kHz ±3.5%.

So I tried the maximum compensation value (120pF)


which results in 522kHz which is still outside the maximum of 517.5kHz. With a bit of soldering I could get it to 512kHz but unfortunately the problem persists.
I then changed the i2c bus frequency to 200kHz (no harmonics for 500kHz) which made it a bit better, meaning that I do not permanently get these “disturber detected” messages.

Long story short, the circuit was badly designed/tuned, but fixing it did not bring the expected result.

1 Like

Hi, is there anyone for whom this module works?

I gave up for the moment.
I bought this one here:

But I did not assemble it yet (“Bausatz” means you have to solder it on your own).
I read that it shall work, but I won’t get the distance (if it works at all).

Not sure it’s working correctly, but I finally got the SPI bus config sorted out for an ESP32 Dev board and I’m getting values from it now and displaying them on the local OLED display. Trying to figure out how to build a current/previous bucket that holds 5min of samples now.

Can you please send the wiring diagram. I tried all the options and nothing worked properly.

I’ll see what I can do to show the wiring I used.


Ok, here is what I got working, the hard part was figuring out the right pins for the SPI bus. Use the wrong pins and it either gives no output, or worse, crashes the wifi and you have to reload via usb cable. You can ignore the i2c part of the code, it’s for the oled display.

I also found, in testing, that having the breadboard near the computer I use threw a lot of spike errors, that almost vanished when I put the breadboard in another room with less computer gear. That 500khz receiver is really sensitive to noise sources.

Here is (most of) the yaml running on the setup.

esphome:
  name: esp32-oled
  comment: HelTec WiFi OLED Dev Board
  name_add_mac_suffix: false
  platform: esp32
  board: esp32dev
  platformio_options:
    board_upload.flash_size: 16MB
    board_upload.maximum_ram_size: 524288
    board_upload.maximum_size: 16777216
    board_build.partitions: "../../../esp32-16MB-partitions.csv"

logger:

api:
  reboot_timeout: 0s
  
web_server:
  port: 80
  
ota:
  password: ***

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: true
  reboot_timeout: 5min

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp32-Oled Fallback Hotspot"
    password: !secret wifi_password
    # channel:
    
  domain: ***

captive_portal:

time:
  - platform: homeassistant
    id: homeassistant_time

mqtt:
  broker: ***
  username: ***r
  password: ***
  discovery_prefix: esp32-oled
  discovery_retain: true

output:
  - platform: gpio
    pin: GPIO25
    id: gpio_25

i2c:
  sda: GPIO04
  scl: GPIO15
  scan: true
  id: i2c_bus

spi:
  clk_pin: GPIO18
  miso_pin: GPIO19
  mosi_pin: GPIO23
  id: spi_bus
  
as3935_spi:
  cs_pin: GPIO5
  irq_pin: GPIO17
  indoor: True
  noise_level: 2
  spike_rejection: 5       # Default 2
  lightning_threshold: 1
  mask_disturber: false
  div_ratio: 0
  capacitance: 0
  watchdog_threshold: 2

binary_sensor:
  - platform: as3935
    name: "Lightning Strike"
    id: strike
    
sensor:
  - platform: as3935
    lightning_energy:
      name: "Strike Energy"
      id: energy
    distance:
      name: "Storm Distance"
      id: distance
      
light:
  - platform: binary
    output: gpio_25
    name: esp32-oled light

***

font:
  - file: "Calibri.ttf"
    id: calibri_font
    size: 12

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: GPIO16
    address: 0x3C
    lambda: |-
      it.strftime(0, 0, id(calibri_font), "%Y-%m-%d %H:%M", id(homeassistant_time).now());
      it.line(0, 12, 127, 12);
      it.printf(0, 15, id(calibri_font), "Strike: %s", id(strike).state ? "Zot!" : "");
      it.printf(0, 27, id(calibri_font), "Distance: %3.1fkm", id(distance).state);
      it.printf(0, 39, id(calibri_font), "Energy: %8.0f Vix", id(energy).state);
      it.line(0, 53, 127, 53);
      it.printf(0, 54, id(calibri_font), "UniKyrn: %s", id(oled_display).state.c_str());
1 Like