Open grilli303 opened 3 years ago
The fix is simple. Change the line "from RPiAS3935...." in init _.py to "from .RPi_AS3935....".
that didn't seem to fix it...
This worked for me on Python 3.7.3:
#!/usr/bin/env python
from RPi_AS3935 import RPi_AS3935
import RPi.GPIO as GPIO
import time
from datetime import datetime
GPIO.setmode(GPIO.BCM)
# 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.RPi_AS3935(address=0x03, bus=1)
sensor.set_indoors(True)
sensor.set_noise_floor(0)
sensor.calibrate(tun_cap=0x0F)
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().strftime('%H:%M:%S - %Y/%m/%d')
distance = sensor.get_distance()
print("We sensed lightning!")
print("It was " + str(distance) + "km away. (%s)" % now)
print("")
pin = 17
GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.RISING, callback=handle_interrupt)
print("Waiting for lightning - or at least something that looks like it")
while True:
time.sleep(1.0)
Hi there I tried to run demo.py with Python 3.7.3 and get the following error:
Traceback (most recent call last): File "demo.py", line 13, in
sensor = RPi_AS3935(address=0x03, bus=1)
TypeError: 'module' object is not callable
When I run demo.py with Python 2.7.16 it works Does someone can know, how I can modify the code to make it work with Python 3.7.3 ?
Kind regards, Daniel