pcfens / RaspberryPi-AS3935

A basic library for working with the AS3935 that's connected to the Raspberry Pi.
Other
52 stars 24 forks source link

TypeError: 'module' object is not callable with Python 3.7.3 #30

Open grilli303 opened 3 years ago

grilli303 commented 3 years ago

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

schorschfunke commented 3 years ago

The fix is simple. Change the line "from RPiAS3935...." in init _.py to "from .RPi_AS3935....".

ivannunyadambiz commented 3 years ago

that didn't seem to fix it...

eelcohn commented 2 years ago

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)