Rewrote this DIY post.
It is only for the Playing With Fusion AS3935 lightning board i2C connection to a Revision 2 of the Raspberry Pi (original Homeseer Zee).
I will compress the RPi image for downloading and attach it for those interested in doing this endeavor.
I have written to the playing with fusion folks regarding a couple of questions.
- The specs state 2-5 VDC. Most folks are using 3.3VDC with their Arduino testing. Below testing is using 5.0VDC. I may change it to using 3.3VDC.
- Another question relates to the capacitor value that I have and if I need to modify the python script with the value of the tuning capacitor value.
Got an answer back from my above questions:
Hi Pete,
Awesome, thanks for pointing me to this! I would definitely switch to 3.3V pins and change to 0x0D (x0D*8 =104).
--
Thanks, and have a great 4th weekend,
Justin
Going to re pin my stuff and make the changes for the capacitor and redo the below drawing today.
If you are not a person that solders stuff send me the Lightning board and I will solder jumper cables and or pins on the board.
With pins on the board you can just utilize jumper cables from your board to the RPi.
I am using the original RPi re purposed from the original Zee and some Linux knowledge.
HW RPi info timeline
==> Zee RPi #1 HS3 OS on Wheezy (with Z-Wave GPIO / PiFace RTC) - freed original RPi for use here.
==> Zee2 RPi #2 HS3 OS on Wheezy (with Z-Wave GPIO / PiFace RTC) - freed RPi2 turned this RPi2 to ZNet like device and 1-Wire hub connected via POE in attic
==> Zee2 OS on Pine64 2Gb #3 HS3 OS on Ubuntu 16.04 64 bit - currently running Zee2 HS3 Lite.
Note that I did this endeavor using SSH and never connected a monitor to the Raspberry Pi.
Step #1 - Preparing your RPi wiring
Step #2 - Preparing your AS3935 breakout board solder the wires - use a small tipped soldering iron, put a tiny drop of solder on the iron then touch the wire to solder.Step #3 - Preparing your RPi
A - Download Wheezy from here ==> Wheezy Download
B - Download SD Card Formatter from here ==> Windows SD Card Formatter
C - Format you SD card. Here utilized Windows 7 and a 4Gb microSD card in an SD card holder
D - Download Win32 Disk Imager from here ==> Win32DiskImager
E - Write downloaded Wheezy Image to SD card - here utilize SD card slot on laptop or USB SD card stick.
Step #4 - Preparing your RPi via SSH
A - Insert your SD card in to your RPi and plug in an Ethernet cable to network port on RPi and plug in power up.
B - Have a look see at your firewall router to find the DHCP address of your RPi. It will be labeled as Raspberry.
C - Download Putty from here ==> Putty
D - Install it on your Windows PC
E - SSH to your RPi using user pi and password raspberry
F - type sudo su once in and hit enter
G - type raspi-config and hit enter - do what the picture shows. (Expand system, change password, internationalization options and advanced menu)
Go to advanced menu on raspi-config and do what the picture shows. (host name, memory split (go to 16) and i2c)
H - Exit and reboot.
I - SSH back to your RPi - adding one user
Type sudo su
add your name to users and sudo - note here using my name as an example
adduser pete *password and answer all of the questions - I use return on them
usermod -aG sudo pete
J - SSH back to your RPi - here we are going to create a static address - easy these days.
K - cd /etc
L - nano dhcpcd.conf
add your static IP to the end of the file. Use your network information. The example is my configuration.
interface eth0
static ip_address=192.168.244.165/25
static routers=192.168.244.129
static domain_name_servers=192.168.244.129
M - reboot and ssh back to your RPi with your static IP and new username and type sudo su.
N - type apt-get update
O - type apt-get upgrade (note this will run for a while)
P - when finished reboot.
Q - you are now finished with base configuration on your RPi
P - if you have not connected your lightning sensor then do it now. Note type halt to shut down your RPi, unplug network and power cable, hook up your Lightning sensor.
Q - testing your i2C connection to you lightning sensor
R - cd /
S - type apt-get install i2c-tools
T - type i2cdetect -y 1 * you will see the following. If you see only 03 then you are connected to the AS3935
Step #5 - Using the AS3935 Python library to test your lightning sensor AS3935 breakout board.
A - ssh to your RPi.
B - type cd /opt and mkdir lightning and cd lightning
C - type git - if it is not present then type apt-get install git
D - with your browser look at the following: hxxps://github.com/pcfens/RaspberryPi-AS3935 read the text file
E - type git clone hxxps://github.com/pcfens/RaspberryPi-AS3935
F - cd to /opt/lightning/RaspberryPi-AS3935
G - type pip install -r requirements.txt
H - if there in a python module missing then type: python -m pip install SomePackage
I - type again pip install -r requirements.txt
J- type cd /opt/lightning/RaspberryPi-AS3935
K - type python setup.py
L - testing demo.py - make one change to the file here:
# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
sensor = RPi_AS3935(address=0x03, bus=1)
sensor.set_indoors(True)
sensor.set_noise_floor(0)
sensor.calibrate(tun_cap=0x0D) * changed to my capacitor value of 104
M - ssh to your pi, cd /opt/lightning/RaspberryPi-AS3935
N - type python demo.py
O - I've attached another more elaborate demo for lightning sensor at the end of this post.
The python script is called AS3935-monitor.py.
Step #6 - A3935 mini web server - located here ==> hxxps://github.com/pcfens/RPi-AS3935-Web
Made the web page a link from main Homeseer 3 server and one HSTouch page.
A - SSH to your Pi
B - type cd /opt/lightning
C - type git clone hxxps://github.com/pcfens/RPi-AS3935-Web
D - type cd RPi-AS3935-Web
E - type pip install -r requirements.txt
F - if there in a python module missing then type: python -m pip install SomePackage
G - type again pip install -r requirements.txt
H - cp settings.cfg.sample to settings.cfg
I - type nano settings.cfg
J - changed the following lines to match.
[pi]
; Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
; bus equal to 1.
bus = 1
[as3935]
; Set the i2c address of lightning sensor
address = 0x03
; The value needed to tune the sensor
tuning_cap = 0x0F ==> 0x0D (x0D*8 =104) ==> tuning_cap = 0x0D
18:18c 07/02/2017 testing while storm rolls through - hear thunder and seeing lightning
AS3935 Lightning Detection Monitor Script - v0.1
Monitor Status: ONLINE
Disturber detected - masking
1 2017-07-02 23:16:00.074464 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:00.067 2017-07-02
1 2017-07-02 23:16:01.165121 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:01.158 2017-07-02
1 2017-07-02 23:16:03.188902 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:03.178 2017-07-02
7th of July, 2017
Overhead lightning detected - distance = 1 km at 14:19:53.838 2017-07-07
1 2017-07-07 19:21:48.004053 1 1 0
Overhead lightning detected - distance = 1 km at 14:21:47.993 2017-07-07
1 2017-07-07 19:22:42.710066 5 1 0
Lightning detected - distance = 5 kms at 14:22:42.699 2017-07-07
1 2017-07-07 19:23:48.668980 5 1 0
Lightning detected - distance = 5 kms at 14:23:48.658 2017-07-07
1 2017-07-07 19:25:49.172010 5 1 0
Lightning detected - distance = 5 kms at 14:25:49.161 2017-07-07
1 2017-07-07 19:38:49.285675 6 1 0
Lightning detected - distance = 6 kms at 14:38:49.275 2017-07-07
1 2017-07-07 19:47:19.987470 24 1 0
Lightning detected - distance = 24 kms at 14:47:19.977 2017-07-07
1 2017-07-07 19:54:57.464848 24 1 0
Lightning detected - distance = 24 kms at 14:54:57.454 2017-07-07
It is only for the Playing With Fusion AS3935 lightning board i2C connection to a Revision 2 of the Raspberry Pi (original Homeseer Zee).
I will compress the RPi image for downloading and attach it for those interested in doing this endeavor.
I have written to the playing with fusion folks regarding a couple of questions.
- The specs state 2-5 VDC. Most folks are using 3.3VDC with their Arduino testing. Below testing is using 5.0VDC. I may change it to using 3.3VDC.
- Another question relates to the capacitor value that I have and if I need to modify the python script with the value of the tuning capacitor value.
Got an answer back from my above questions:
Hi Pete,
Awesome, thanks for pointing me to this! I would definitely switch to 3.3V pins and change to 0x0D (x0D*8 =104).
--
Thanks, and have a great 4th weekend,
Justin
Going to re pin my stuff and make the changes for the capacitor and redo the below drawing today.
If you are not a person that solders stuff send me the Lightning board and I will solder jumper cables and or pins on the board.
With pins on the board you can just utilize jumper cables from your board to the RPi.
I am using the original RPi re purposed from the original Zee and some Linux knowledge.
HW RPi info timeline
==> Zee RPi #1 HS3 OS on Wheezy (with Z-Wave GPIO / PiFace RTC) - freed original RPi for use here.
==> Zee2 RPi #2 HS3 OS on Wheezy (with Z-Wave GPIO / PiFace RTC) - freed RPi2 turned this RPi2 to ZNet like device and 1-Wire hub connected via POE in attic
==> Zee2 OS on Pine64 2Gb #3 HS3 OS on Ubuntu 16.04 64 bit - currently running Zee2 HS3 Lite.
Note that I did this endeavor using SSH and never connected a monitor to the Raspberry Pi.
Step #1 - Preparing your RPi wiring
Step #2 - Preparing your AS3935 breakout board solder the wires - use a small tipped soldering iron, put a tiny drop of solder on the iron then touch the wire to solder.Step #3 - Preparing your RPi
A - Download Wheezy from here ==> Wheezy Download
B - Download SD Card Formatter from here ==> Windows SD Card Formatter
C - Format you SD card. Here utilized Windows 7 and a 4Gb microSD card in an SD card holder
D - Download Win32 Disk Imager from here ==> Win32DiskImager
E - Write downloaded Wheezy Image to SD card - here utilize SD card slot on laptop or USB SD card stick.
Step #4 - Preparing your RPi via SSH
A - Insert your SD card in to your RPi and plug in an Ethernet cable to network port on RPi and plug in power up.
B - Have a look see at your firewall router to find the DHCP address of your RPi. It will be labeled as Raspberry.
C - Download Putty from here ==> Putty
D - Install it on your Windows PC
E - SSH to your RPi using user pi and password raspberry
F - type sudo su once in and hit enter
G - type raspi-config and hit enter - do what the picture shows. (Expand system, change password, internationalization options and advanced menu)
Go to advanced menu on raspi-config and do what the picture shows. (host name, memory split (go to 16) and i2c)
H - Exit and reboot.
I - SSH back to your RPi - adding one user
Type sudo su
add your name to users and sudo - note here using my name as an example
adduser pete *password and answer all of the questions - I use return on them
usermod -aG sudo pete
J - SSH back to your RPi - here we are going to create a static address - easy these days.
K - cd /etc
L - nano dhcpcd.conf
add your static IP to the end of the file. Use your network information. The example is my configuration.
interface eth0
static ip_address=192.168.244.165/25
static routers=192.168.244.129
static domain_name_servers=192.168.244.129
M - reboot and ssh back to your RPi with your static IP and new username and type sudo su.
N - type apt-get update
O - type apt-get upgrade (note this will run for a while)
P - when finished reboot.
Q - you are now finished with base configuration on your RPi
P - if you have not connected your lightning sensor then do it now. Note type halt to shut down your RPi, unplug network and power cable, hook up your Lightning sensor.
Q - testing your i2C connection to you lightning sensor
R - cd /
S - type apt-get install i2c-tools
T - type i2cdetect -y 1 * you will see the following. If you see only 03 then you are connected to the AS3935
Code:
~# sudo i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: 03 -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
A - ssh to your RPi.
B - type cd /opt and mkdir lightning and cd lightning
C - type git - if it is not present then type apt-get install git
D - with your browser look at the following: hxxps://github.com/pcfens/RaspberryPi-AS3935 read the text file
E - type git clone hxxps://github.com/pcfens/RaspberryPi-AS3935
F - cd to /opt/lightning/RaspberryPi-AS3935
G - type pip install -r requirements.txt
H - if there in a python module missing then type: python -m pip install SomePackage
I - type again pip install -r requirements.txt
J- type cd /opt/lightning/RaspberryPi-AS3935
K - type python setup.py
L - testing demo.py - make one change to the file here:
# Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
# bus equal to 1. The address should be changed to match the address of the
# sensor. (Common implementations are in README.md)
sensor = RPi_AS3935(address=0x03, bus=1)
sensor.set_indoors(True)
sensor.set_noise_floor(0)
sensor.calibrate(tun_cap=0x0D) * changed to my capacitor value of 104
M - ssh to your pi, cd /opt/lightning/RaspberryPi-AS3935
N - type python demo.py
O - I've attached another more elaborate demo for lightning sensor at the end of this post.
The python script is called AS3935-monitor.py.
Step #6 - A3935 mini web server - located here ==> hxxps://github.com/pcfens/RPi-AS3935-Web
Made the web page a link from main Homeseer 3 server and one HSTouch page.
A - SSH to your Pi
B - type cd /opt/lightning
C - type git clone hxxps://github.com/pcfens/RPi-AS3935-Web
D - type cd RPi-AS3935-Web
E - type pip install -r requirements.txt
F - if there in a python module missing then type: python -m pip install SomePackage
G - type again pip install -r requirements.txt
H - cp settings.cfg.sample to settings.cfg
I - type nano settings.cfg
J - changed the following lines to match.
[pi]
; Rev. 1 Raspberry Pis should leave bus set at 0, while rev. 2 Pis should set
; bus equal to 1.
bus = 1
[as3935]
; Set the i2c address of lightning sensor
address = 0x03
; The value needed to tune the sensor
tuning_cap = 0x0F ==> 0x0D (x0D*8 =104) ==> tuning_cap = 0x0D
Code:
# -*- coding: utf-8 -*- #! /usr/bin/env python """ AS3935-monitor.py: A monitoring script for the AS3935 lightning sensor on the MOD-1016 v6 breakout board. Requires both the RaspberryPi-AS3935 and RPi.GPIO Python modules. Note that the reset function requires VCT fork of RaspberryPi-AS3935. simple invocation: $ sudo python AS3935-monitor.py error logging invocation: $ sudo python -u AS3935-monitor.py > >(tee -a output.log) 2> >(tee error.log >&2) Licensed under the GNU General Public License (GPL) version 2 or greater. Copyright 2014 Vanguard Computer Technology Labs, Inc. """ from RPi_AS3935 import RPi_AS3935 import RPi.GPIO as GPIO import time from datetime import datetime GPIO.setmode(GPIO.BCM) ## Rev 1 Raspberry Pi: bus=0 ## Rev 2 and later Raspberry Pi: bus=1 ## All: address=<i2c add> sensor = RPi_AS3935(address=0x03, bus=1) ## Uncomment to reset all registers to factory default values. ## sensor.reset() sensor.calibrate(tun_cap=0x0d) time.sleep(0.002) sensor.set_indoors(True) sensor.set_noise_floor(0) ## uncomment/set to filter out false positives sensor.set_min_strikes(1) def log_raw_data(data): # need to pass time as parameter and convert to UTC here utcnow = datetime.utcnow() version = 01 timestamp = utcnow.strftime("%Y-%m-%d %H:%M:%S.%f") outstring = str(version)+" "+str(timestamp)+" "+str(data)+" "+str(min_strikes)+" "+str(noise_floor)+"\n" print(outstring) f.write(outstring) f.flush def handle_interrupt(channel): time.sleep(0.003) global sensor reason = sensor.get_interrupt() if reason == 0x01: print("Noise level too high - adjusting") sensor.raise_noise_floor() elif reason == 0x04: print("Disturber detected - masking") sensor.set_mask_disturber(True) elif reason == 0x08: now = datetime.now() distance = sensor.get_distance() if 0 < distance < 63: log_raw_data(distance) if distance == 1: print("Overhead lightning detected - distance = " + str(distance) + " km at %s ") % now.strftime("%H:%M:%S.%f")[:-3],now.strftime("%Y-%m-%d") elif 40 < distance < 63: print("Distant lightning detected - distance = " + str(distance) + " kms at %s") % now.strftime("%H:%M:%S.%f")[:-3],now.strftime("%Y-%m-%d") elif 2 <= distance <= 40: print("Lightning detected - distance = " + str(distance) + " kms at %s") % now.strftime("%H:%M:%S.%f")[:-3],now.strftime("%Y-%m-%d") else: print("Invalid data; distance out of range.") irq_pin = 17 cs_pin = 24 GPIO.setup(irq_pin, GPIO.IN) GPIO.add_event_detect(irq_pin, GPIO.RISING, callback=handle_interrupt) def read_settings(): global min_strikes, noise_floor min_strikes = sensor.get_min_strikes() noise_floor = sensor.get_noise_floor() def print_settings(): print("Minimum allowed strikes is " + str(min_strikes)) print("Current noise floor is " + str(noise_floor)) running = True try: print("AS3935 Lightning Detection Monitor Script - v0.1") print(" Monitor Status: ONLINE") print("") ## log raw data to file f=open('AS3935-data.txt','a') read_settings() while running: time.sleep(1.0) except KeyboardInterrupt: print(" Monitor Status: OFFLINE") print_settings() print("") finally: GPIO.cleanup() # clean up GPIO on CTRL+C exit f.close()
AS3935 Lightning Detection Monitor Script - v0.1
Monitor Status: ONLINE
Disturber detected - masking
1 2017-07-02 23:16:00.074464 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:00.067 2017-07-02
1 2017-07-02 23:16:01.165121 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:01.158 2017-07-02
1 2017-07-02 23:16:03.188902 1 1 0
Overhead lightning detected - distance = 1 km at 18:16:03.178 2017-07-02
7th of July, 2017
Overhead lightning detected - distance = 1 km at 14:19:53.838 2017-07-07
1 2017-07-07 19:21:48.004053 1 1 0
Overhead lightning detected - distance = 1 km at 14:21:47.993 2017-07-07
1 2017-07-07 19:22:42.710066 5 1 0
Lightning detected - distance = 5 kms at 14:22:42.699 2017-07-07
1 2017-07-07 19:23:48.668980 5 1 0
Lightning detected - distance = 5 kms at 14:23:48.658 2017-07-07
1 2017-07-07 19:25:49.172010 5 1 0
Lightning detected - distance = 5 kms at 14:25:49.161 2017-07-07
1 2017-07-07 19:38:49.285675 6 1 0
Lightning detected - distance = 6 kms at 14:38:49.275 2017-07-07
1 2017-07-07 19:47:19.987470 24 1 0
Lightning detected - distance = 24 kms at 14:47:19.977 2017-07-07
1 2017-07-07 19:54:57.464848 24 1 0
Lightning detected - distance = 24 kms at 14:54:57.454 2017-07-07
Comment