Problems setting up a Mikroe Pi 3 Click Shield and AS3935 thunder Click

Hi,

I have just recieved a Mikroe Pi 3 Click Shield and AS3935 thunder Click, and have been trying the get it to work on my Raspberry Pi 3 with latest Raspberry pi Buster image.

I have followed the instructions this thread Raspberry Pi Lightning Detector - v1 and v2

and have not been able to get it to work.

When using sudo python3 as3935_pigpio_test.py

and get the following results.

Test starting
Register 0x00 is 0x00
Register 0x01 is 0x00
Register 0x02 is 0x00
Register 0x03 is 0x00
Register 0x04 is 0x00
Register 0x05 is 0x00
Register 0x06 is 0x00
Register 0x07 is 0x00
Register 0x08 is 0x00
Test complete

I have changed the address=0 and still get the above results.
Note SPi set to on in config.txt

What am I doing wrong, Can any one help.

many thanks Michael

I found this post by the ADMIN “Raspberry Pi Lightning Detector v4.0”. It might help you.

I’m using mine on a Pi4 but I know other have set them up on Pi3’s. Some things have changed since I last worked on the project and others might have done too. The Operating system has been upgraded and I’ve not tried the config on the latest version. There’s also the slight chance that the Pi3 Click or Thunder Click have changed, although I suspect that’s less likely.

As a starting point…does the Thunder Click have the green LED glowing when the Pi is powered on? Hopefully it does!

Which Click Shield socket is the Thunder Click plugged into and is AN1 (or AN2) set correctly? If the hardware is set correctly then it may be a software change that’s broken things.

I’m a bit rusty on this because since I built/coded it there’s been no local lightning! I went the whole of last summer and the nearest a storm came was about 50km, which is out of range! Given that summer is getting closer I should look at it again to check it’s still working!

I use a Youtube video titled “Bass Test - Frequency Sweep and Burst” on my phone to test my lightning detector when there are no storms. It’s not flawless but it generates strikes & some of them have distance computed so it’s just a rudimentary method that works for me … not saying it would work for everyone though.

I’m intrigued about how that works! I’ll have to try it when I get back to the project.

I think any low freq tone tester will generate the required disturbance … i just found that Youtube has lots of tone test videos so I decided to try a few of them and they all generate strikes … the ones that sweep through Zero to 100 Hz and back to zero seem to work best. I also was able to generate strikes by turning a hurricane fan off and on and selecting high speed and then low speed and so on. I guess it depends on if the lightning detector is easily accessible or not.

Hi, Thanks for the help.

I have re burned a new SD card with the latest Raspberry Pi OS with desktop Debian version: 11 (bullseye). And enabled SPI etc.

The board is plugged into socket 1 and the green led is lit.

I then used your installer (as3935_installer.sh 0) v4.1 all installed OK. I then ran as3935_pigpio_test.py and Test starting
Good version of pigpio found - Version 79
Register 0x00 is 0x00
Register 0x01 is 0x00
Register 0x02 is 0x00
Register 0x03 is 0x00
Register 0x04 is 0x00
Register 0x05 is 0x00
Register 0x06 is 0x00
Register 0x07 is 0x00
Register 0x08 is 0x00
Test complete

I then tried calibrate_pig.py
with the following results

sudo python3 calibrate_pig.py
Starting calibration run - Please wait approximately 16 seconds
calibration_run - At 0 pF 4032.0 IRQs/sec with variance from ideal of 125.8 ( 3.22 %)
calibration_run - At 8 pF 3949.0 IRQs/sec with variance from ideal of 42.8 ( 1.09 %)
calibration_run - At 16 pF 3392.0 IRQs/sec with variance from ideal of -514.2 ( -13.16 %)
calibration_run - At 24 pF 3551.0 IRQs/sec with variance from ideal of -355.2 ( -9.09 %)
calibration_run - At 32 pF 3304.0 IRQs/sec with variance from ideal of -602.2 ( -15.42 %)
calibration_run - At 40 pF 3927.0 IRQs/sec with variance from ideal of 20.8 ( 0.53 %)
calibration_run - At 48 pF 3960.0 IRQs/sec with variance from ideal of 53.8 ( 1.38 %)
calibration_run - At 56 pF 3951.0 IRQs/sec with variance from ideal of 44.8 ( 1.15 %)
calibration_run - At 64 pF 3960.0 IRQs/sec with variance from ideal of 53.8 ( 1.38 %)
calibration_run - At 72 pF 4036.0 IRQs/sec with variance from ideal of 129.8 ( 3.32 %)
calibration_run - At 80 pF 3961.0 IRQs/sec with variance from ideal of 54.8 ( 1.40 %)
calibration_run - At 88 pF 3961.0 IRQs/sec with variance from ideal of 54.8 ( 1.40 %)
calibration_run - At 96 pF 3998.0 IRQs/sec with variance from ideal of 91.8 ( 2.35 %)
calibration_run - At 104 pF 3960.0 IRQs/sec with variance from ideal of 53.8 ( 1.38 %)
calibration_run - At 112 pF 3949.0 IRQs/sec with variance from ideal of 42.8 ( 1.09 %)
calibration_run - At 120 pF 3962.0 IRQs/sec with variance from ideal of 55.8 ( 1.43 %)
Success!
Tuning Capacitor setting - 0x05 - 40 pF
Percent variance = 0.53 %

Does this indicate its working ?

If i run sudo systemctl status as3935_monitor.service, it shows these errors

● as3935_monitor.service - AS3935 Monitor service
Loaded: loaded (/lib/systemd/system/as3935_monitor.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-05-18 23:00:35 BST; 2min 5s ago
Main PID: 616 (python3)
Tasks: 5 (limit: 1598)
CPU: 1min 56.576s
CGroup: /system.slice/as3935_monitor.service
├─616 /usr/bin/python3 /home/pi/Sensors/as3935_monitor.py
├─625 /usr/bin/python3 /home/pi/Sensors/as3935_monitor.py
└─705 /usr/bin/python3 /home/pi/Sensors/as3935_monitor.py

May 18 23:00:39 RASPI-AS3935 python3[705]: rc = self._packet_read()
May 18 23:00:39 RASPI-AS3935 python3[705]: File “/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py”, line 2439, in _packet_read
May 18 23:00:39 RASPI-AS3935 python3[705]: rc = self._packet_handle()
May 18 23:00:39 RASPI-AS3935 python3[705]: File “/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py”, line 3039, in _packet_handle
May 18 23:00:39 RASPI-AS3935 python3[705]: return self._handle_connack()
May 18 23:00:39 RASPI-AS3935 python3[705]: File “/usr/local/lib/python3.9/dist-packages/paho/mqtt/client.py”, line 3138, in _handle_connack
May 18 23:00:39 RASPI-AS3935 python3[705]: on_connect(
May 18 23:00:39 RASPI-AS3935 python3[705]: File “/home/pi/Sensors/as3935_monitor.py”, line 357, in on_connect
May 18 23:00:39 RASPI-AS3935 python3[705]: logger.debug("MQTT broker connection failed with result: "+connack_string(rc))
May 18 23:00:39 RASPI-AS3935 python3[705]: NameError: name ‘connack_string’ is not defined

I guess some things have changed, also the webpage cannot be accessed using
http://192.168.0.xxx/as3935

I have know idea if its working or not. Here in S.E UK we are expecting some storms tonight.

As another thought could Adafruit’s CircuitPython be used run the setup?

Hopefully we can get it to work
Michael

Michael …

Run “i2cdetect -y 1” and when it dumps it’s output to the screen you should see “03” to the right of 00: if your detector is recognized. If you have the “03” on that address I would say you are good. But you do have those py errors … so I’m not sure if that’s a problem or not.

Hi

If its an SPI device would it show up on i2cdetect, my results are below.

sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
pi@RASPI-AS3935:~ $

Should the Mikroe Pi 3 Click Shield show as a i2cdevice?

Many thanks Michael
Michael

I don’t think i2cdetect works for SPI devices although it may have been updated since I last used it.

Also I’m pretty sure that the Click Shield has no onboard intelligence so it shouldn’t show up as either I2C or SPI.

Hi
Is there any way this device(s) can be setup and used without MQTT.

So only the AS3935 can be tested on the SPI

Michael

Short answer: Yes, but…

Longer answer: All the code is provided so you’d need to modify it.

If I remember the code correctly it uses a queue manager to schedule things to happen at the right times. So I think it’s structured as:

Setup data and AS3935 comms
Setup task schedules and start the queue
The tasks then execute as required. There are tasks for things like reading data back from the AS3935, sending data to MQTT, etc

If you made a new version of the code and stripped out the queue setup/scheduling, and anything not related to handling the AS3935, then you should be left with code that just handles the chip.

How easy that would be depends on your Python skills. I went from not really knowing the language to writing the code you’ve seen, so if you already know Python it might not be too difficult deciphering the code written by a noob like me!

Yeah … I screwed that up Michael. Sorry about that.

Hi,
Thanks for the replies,

I’m not skilled an coding, how ever there is no harm in having a play, I have played a little with Adafruits Circuit Pyhon and have a feeling it may be the route to take, I will have a play without using MQTT.

If any one can help I would be greatful, I see that BiffoBear has written an library GitHub - BiffoBear/CircuitPython_AS3935: A CircuitPython driver library for the Franklin AS3935 lightning detector. The driver supports connections via SPI and I2C. for i2c, perhaps it could be adapted to use SPI

I will have a play, but do think will have much luck as my programming skill are limited.
I would be greatful for any help

Michael

Hi,

Just thought I would ask does anyone have one of these working on a raspberry pi, or had one working.
I had a play but do know if the two boards are talking to my raspberry pi3, I tried searching and information about thes boards is very sparse.
Does any elso have a working AS3935 Board that works, I did once use a Gravity Lightning Distance Sensor by Dfrobot sadly these did not work for long before becoming faulty

Regards Michael

I also looked around on the web for a few days and couldn’t find anything at all. All kinds of tutorials on the i2c version but nothing on the spi.

Hi,

I think using SPI is getting me no where, so I have decided to revert back to i2c,and have ordered Gravity Lightning Distance Sensor by Dfrobot, hoping it will last longer, at least I know these are easy to set up and to get working with a raspberry pi3.

I will report back at you know how I get on.

Michael

Hi All,

Over the last few day I have been playing with a DFRobot Gravity: Lightning Distance Sensor and using the biffobear_as3935 CircuitPython_AS3935 drivers.
And have adapted the software found in as3935_full_install_v3_2.zip, to produce a nowcast.txt file into import WD.

All seems working and data is is being recieved.
How ever I’m getting a lot of faulse strikes, can anyone advise me as to how to fix this.

In have included the python3 files I use.

Many Thanks Michael


Lightning.zip (241 KB)

Sorry for being quiet on this topic recently. I was away on holiday and have been preparing for overseas visitors coming next week so haven’t had much time. I’ve just started to rebuild my Dev Pi to get back into working on this and my other IoT projects. I had to rebuild the Pi because I tried an OS upgrade which failed badly so a clean start is the best way forward. I’ll be back with more news once I’ve got things working at this end.

Firstly, thank you Michael for providing the code that got the alternative solution working. That’s exactly what I was hoping would happen with these projects, i.e. get others motivated to try things and provide their own solutions/modifications for others to use.

Moving on…I read somewhere way back when I started this project, i.e. about 2 years ago or beyond my living memory, that the I2C interface on the AS3935 is flawed in some way. I don’t recall how it’s flawed but the recommendation was to use it in SPI mode if at all possible. I don’t know if that will affect the DrRobot solution, but it will be interesting to see how that goes.

I’ve just re-installed the v4.1 code by following the instructions in this board, just to make sure I was seeing exactly what all of you would see, and also installed onto a fresh Pi OS build rather than my usual build which contains my development environment which might have affected things.

My 4GB Pi4 is now built using 32-bit Pi OS Lite (Debian Bullseye) and fully patched before I installed the AS3935 software. My previous tests were with Debian Buster so this was a new environment for me. I installed the pre-requisites and enabled the SPI interface using raspi-config, then ran the installer with the ThunderClick in slot 1. The installer ran without errors and correctly identified the ThunderClick on completion. The as3935_monitor service ran without errors and the web page can be accessed. There’s no lightning here at the moment but next step is to try the app that was mentioned to see if that generates and clicks for me.

So…it all worked as expected so I’m not quite sure why it’s not working for others. The only thoughts I have at the moment are:

  1. I’ve not tried this on a 64-bit OS so I don’t know if it would work or not.
  2. If you’ve not enabled the SPI interface using raspi-config then things wouldn’t work, but I think you mentioned an SPI setting in config.txt?